Fix window position/size saving
I've only tested this for the main window so far Fixes #149
This commit is contained in:
+25
-89
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "util/helpers.hpp"
|
||||
#include "widgets/basewidget.hpp"
|
||||
#include "widgets/notebook.hpp"
|
||||
#include "widgets/titlebar.hpp"
|
||||
@@ -10,8 +11,7 @@
|
||||
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/signals2.hpp>
|
||||
#include <pajlada/settings/serialize.hpp>
|
||||
#include <pajlada/settings/settingdata.hpp>
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
@@ -21,12 +21,32 @@ class CompletionManager;
|
||||
|
||||
namespace widgets {
|
||||
|
||||
struct WindowGeometry {
|
||||
WindowGeometry(const std::string &key)
|
||||
: x(fS("/windows/{}/geometry/x", key))
|
||||
, y(fS("/windows/{}/geometry/y", key))
|
||||
, width(fS("/windows/{}/geometry/width", key))
|
||||
, height(fS("/windows/{}/geometry/height", key))
|
||||
{
|
||||
}
|
||||
|
||||
pajlada::Settings::Setting<int> x;
|
||||
pajlada::Settings::Setting<int> y;
|
||||
pajlada::Settings::Setting<int> width;
|
||||
pajlada::Settings::Setting<int> height;
|
||||
};
|
||||
|
||||
class Window : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QString windowName;
|
||||
|
||||
WindowGeometry windowGeometry;
|
||||
|
||||
public:
|
||||
explicit Window(ChannelManager &_channelManager, ColorScheme &_colorScheme, bool isMainWindow);
|
||||
explicit Window(const QString &_windowName, ChannelManager &_channelManager,
|
||||
ColorScheme &_colorScheme, bool isMainWindow);
|
||||
|
||||
void repaintVisibleChatWidgets(Channel *channel = nullptr);
|
||||
|
||||
@@ -48,6 +68,8 @@ private:
|
||||
|
||||
virtual void refreshTheme() override;
|
||||
|
||||
void loadGeometry();
|
||||
|
||||
ChannelManager &channelManager;
|
||||
ColorScheme &colorScheme;
|
||||
|
||||
@@ -55,92 +77,6 @@ private:
|
||||
bool loaded = false;
|
||||
TitleBar titleBar;
|
||||
|
||||
/*
|
||||
class QRectWrapper : public pajlada::Settings::ISettingData, public QRect
|
||||
{
|
||||
public:
|
||||
QRectWrapper()
|
||||
: QRect(-1, -1, -1, -1)
|
||||
{
|
||||
}
|
||||
|
||||
pajlada::Signals::Signal<const QRectWrapper &> valueChanged;
|
||||
|
||||
const QRectWrapper &getValueRef() const
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual rapidjson::Value marshalInto(rapidjson::Document &d) override
|
||||
{
|
||||
using namespace pajlada::Settings;
|
||||
|
||||
rapidjson::Value obj(rapidjson::kObjectType);
|
||||
|
||||
auto _x = serializeToJSON<int>::serialize(this->x(), d.GetAllocator());
|
||||
auto _y = serializeToJSON<int>::serialize(this->y(), d.GetAllocator());
|
||||
auto _width = serializeToJSON<int>::serialize(this->width(), d.GetAllocator());
|
||||
auto _height = serializeToJSON<int>::serialize(this->height(), d.GetAllocator());
|
||||
|
||||
obj.AddMember("x", _x, d.GetAllocator());
|
||||
obj.AddMember("y", _y, d.GetAllocator());
|
||||
obj.AddMember("width", _width, d.GetAllocator());
|
||||
obj.AddMember("height", _height, d.GetAllocator());
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
virtual bool unmarshalFrom(rapidjson::Document &document) override
|
||||
{
|
||||
using namespace pajlada::Settings;
|
||||
|
||||
auto vXp = this->getValueWithSuffix("/x", document);
|
||||
auto vYp = this->getValueWithSuffix("/y", document);
|
||||
auto vWidthp = this->getValueWithSuffix("/width", document);
|
||||
auto vHeightp = this->getValueWithSuffix("/height", document);
|
||||
if (vXp != nullptr) {
|
||||
this->setX(deserializeJSON<int>::deserialize(*vXp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vYp != nullptr) {
|
||||
this->setY(deserializeJSON<int>::deserialize(*vYp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vWidthp != nullptr) {
|
||||
this->setWidth(deserializeJSON<int>::deserialize(*vWidthp));
|
||||
this->filled = true;
|
||||
}
|
||||
if (vHeightp != nullptr) {
|
||||
this->setHeight(deserializeJSON<int>::deserialize(*vHeightp));
|
||||
this->filled = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void registerDocument(rapidjson::Document &d) override
|
||||
{
|
||||
this->valueChanged.connect([this, &d](const auto &) {
|
||||
this->marshalInto(d); //
|
||||
});
|
||||
}
|
||||
|
||||
QRectWrapper &operator=(const QRect &rhs)
|
||||
{
|
||||
static_cast<QRect &>(*this) = rhs;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void setValue(const QRect &rhs)
|
||||
{
|
||||
static_cast<QRect &>(*this) = rhs;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
// pajlada::Settings::Setting<QRectWrapper> windowGeometry;
|
||||
|
||||
friend class Notebook;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user