diff --git a/CHANGELOG.md b/CHANGELOG.md index 82f4a511c..0a8b5eaa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - Minor: Links can now have prefixes and suffixes such as parentheses. (#5486, #5515) - Minor: Added support for scrolling in splits with touchscreen panning gestures. (#5524) - Minor: Removed experimental IRC support. (#5547) +- Minor: Remember last popup size for next popup. (#5635) - Minor: Moderators can now see which mods start and cancel raids. (#5563) - Minor: The emote popup now reloads when Twitch emotes are reloaded. (#5580) - Minor: Added `--login ` CLI argument to specify which account to start logged in as. (#5626) diff --git a/src/common/ChatterinoSetting.hpp b/src/common/ChatterinoSetting.hpp index 6dab1a0c6..35d538b13 100644 --- a/src/common/ChatterinoSetting.hpp +++ b/src/common/ChatterinoSetting.hpp @@ -3,6 +3,7 @@ #include "util/QMagicEnum.hpp" #include +#include #include namespace chatterino { @@ -55,6 +56,7 @@ using DoubleSetting = ChatterinoSetting; using IntSetting = ChatterinoSetting; using StringSetting = ChatterinoSetting; using QStringSetting = ChatterinoSetting; +using QSizeSetting = ChatterinoSetting; template class EnumSetting diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3566815e8..94366dabe 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,6 +212,10 @@ public: BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; + QSizeSetting lastPopupSize = { + "/appearance/lastPopup/size", + {300, 500}, + }; /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp new file mode 100644 index 000000000..c5cff3778 --- /dev/null +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include "util/RapidjsonHelpers.hpp" + +#include +#include + +namespace pajlada { + +template <> +struct Serialize { + static rapidjson::Value get(const QSize &value, + rapidjson::Document::AllocatorType &a) + { + rapidjson::Value ret(rapidjson::kObjectType); + + chatterino::rj::set(ret, "width", value.width(), a); + chatterino::rj::set(ret, "height", value.height(), a); + + return ret; + } +}; + +template <> +struct Deserialize { + static QSize get(const rapidjson::Value &value, bool *error = nullptr) + { + if (!value.IsObject()) + { + PAJLADA_REPORT_ERROR(error); + return {}; + } + + int width{}; + int height{}; + + if (!chatterino::rj::getSafe(value, "width", width)) + { + PAJLADA_REPORT_ERROR(error); + return {}; + } + if (!chatterino::rj::getSafe(value, "height", height)) + { + PAJLADA_REPORT_ERROR(error); + return {}; + } + + return {width, height}; + } +}; + +} // namespace pajlada diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index c095c9c28..4dcb14503 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -18,6 +18,7 @@ #include "singletons/Updates.hpp" #include "singletons/WindowManager.hpp" #include "util/InitUpdateButton.hpp" +#include "util/RapidJsonSerializeQSize.hpp" #include "widgets/AccountSwitchPopup.hpp" #include "widgets/dialogs/SettingsDialog.hpp" #include "widgets/dialogs/switcher/QuickSwitcherPopup.hpp" @@ -75,7 +76,13 @@ Window::Window(WindowType type, QWidget *parent) } else { - this->resize(int(300 * this->scale()), int(500 * this->scale())); + auto lastPopup = getSettings()->lastPopupSize.getValue(); + if (lastPopup.isEmpty()) + { + // The size in the setting was invalid, use the default value + lastPopup = getSettings()->lastPopupSize.getDefaultValue(); + } + this->resize(lastPopup.width(), lastPopup.height()); } this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, @@ -142,7 +149,12 @@ void Window::closeEvent(QCloseEvent *) getApp()->getWindows()->save(); getApp()->getWindows()->closeAll(); } - + else + { + QRect rect = this->getBounds(); + QSize newSize(rect.width(), rect.height()); + getSettings()->lastPopupSize.setValue(newSize); + } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by // `selectedWindow_`.