From 919350a8688cecb05cee084a118fdf50c8fcde8b Mon Sep 17 00:00:00 2001 From: maliByatzes Date: Tue, 8 Oct 2024 15:24:00 +0200 Subject: [PATCH 01/15] Keep track of popup window size --- src/singletons/Settings.hpp | 2 ++ src/widgets/Window.cpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 3566815e87e..74c884d0471 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,6 +212,8 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; + IntSetting lastPopupWidth = {"/appearance/popup/lastWidth", 300}; + IntSetting lastPopupHeight = {"/appearance/popup/lastHeight", 500}; /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index d91ca41dfdc..3f0bfcf7092 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -75,7 +75,9 @@ Window::Window(WindowType type, QWidget *parent) } else { - this->resize(int(300 * this->scale()), int(500 * this->scale())); + this->resize(int(getSettings()->lastPopupWidth.getValue() * this->scale()), + int(getSettings()->lastPopupHeight.getValue() * this->scale()) + ); } this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, @@ -148,7 +150,12 @@ void Window::closeEvent(QCloseEvent *) getApp()->getWindows()->save(); getApp()->getWindows()->closeAll(); } - + else + { + QRect rect = this->getBounds(); + getSettings()->lastPopupWidth.setValue(rect.width()); + getSettings()->lastPopupHeight.setValue(rect.height()); + } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by // `selectedWindow_`. From 5755dc02b0e18c0ea460c3fdc0812aa0a6007845 Mon Sep 17 00:00:00 2001 From: maliByatzes Date: Wed, 9 Oct 2024 20:27:37 +0200 Subject: [PATCH 02/15] Use QSize for dimensions --- selected | 1 + src/common/ChatterinoSetting.hpp | 2 ++ src/singletons/Settings.hpp | 4 +-- src/util/RapidJsonSerializeQSize.hpp | 42 ++++++++++++++++++++++++++++ src/widgets/Window.cpp | 10 +++---- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 selected create mode 100644 src/util/RapidJsonSerializeQSize.hpp diff --git a/selected b/selected new file mode 100644 index 00000000000..ec2b4186d36 --- /dev/null +++ b/selected @@ -0,0 +1 @@ +lib/settings/tests/files/advanced-window.json diff --git a/src/common/ChatterinoSetting.hpp b/src/common/ChatterinoSetting.hpp index 6dab1a0c654..502fb0be270 100644 --- a/src/common/ChatterinoSetting.hpp +++ b/src/common/ChatterinoSetting.hpp @@ -4,6 +4,7 @@ #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 74c884d0471..d20eebe20ce 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,8 +212,8 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; - IntSetting lastPopupWidth = {"/appearance/popup/lastWidth", 300}; - IntSetting lastPopupHeight = {"/appearance/popup/lastHeight", 500}; + ChatterinoSetting lastPopupSetting = {"/appearance/lastPopup", + {300, 500}}; /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp new file mode 100644 index 00000000000..f7c7f1a6177 --- /dev/null +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -0,0 +1,42 @@ +#pragma once + +#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) + { + if (!value.IsObject()) + { + PAJLADA_REPORT_ERROR(error); + return QSize{}; + } + + int _width; + int _height; + + chatterino::rj::getSafe(value, "width", _width); + chatterino::rj::getSafe(value, "height", _height); + + return QSize(_width, _height); + } +}; + +} // namespace pajlada diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 3f0bfcf7092..6edaaf7057c 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -75,9 +75,8 @@ Window::Window(WindowType type, QWidget *parent) } else { - this->resize(int(getSettings()->lastPopupWidth.getValue() * this->scale()), - int(getSettings()->lastPopupHeight.getValue() * this->scale()) - ); + auto lastPopup = getSettings()->lastPopupSetting.getValue(); + this->resize(lastPopup.width(), lastPopup.height()); } this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated, @@ -153,8 +152,9 @@ void Window::closeEvent(QCloseEvent *) else { QRect rect = this->getBounds(); - getSettings()->lastPopupWidth.setValue(rect.width()); - getSettings()->lastPopupHeight.setValue(rect.height()); + auto lastPopup = getSettings()->lastPopupSetting.getValue(); + lastPopup.setWidth(rect.width()); + lastPopup.setHeight(rect.height()); } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by From a703be93dd390ba6a21434ebeff8a6ebd167ff68 Mon Sep 17 00:00:00 2001 From: maliByatzes Date: Thu, 10 Oct 2024 18:27:41 +0200 Subject: [PATCH 03/15] Finish up last popup setting --- src/util/RapidJsonSerializeQSize.hpp | 2 +- src/widgets/Window.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp index f7c7f1a6177..2c92714b8fc 100644 --- a/src/util/RapidJsonSerializeQSize.hpp +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -21,7 +21,7 @@ struct Serialize { template <> struct Deserialize { - static QSize get(const rapidjson::Value &value, bool *error) + static QSize get(const rapidjson::Value &value, bool *error = nullptr) { if (!value.IsObject()) { diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index 6edaaf7057c..cdc56db0e06 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" @@ -152,9 +153,8 @@ void Window::closeEvent(QCloseEvent *) else { QRect rect = this->getBounds(); - auto lastPopup = getSettings()->lastPopupSetting.getValue(); - lastPopup.setWidth(rect.width()); - lastPopup.setHeight(rect.height()); + QSize newSize(rect.width(), rect.height()); + getSettings()->lastPopupSetting.setValue(newSize); } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by From e7fa51b6f89eeddb6420157b421b224023985bb9 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:43:22 +0200 Subject: [PATCH 04/15] nit: remove unused file `selected` --- selected | 1 - 1 file changed, 1 deletion(-) delete mode 100644 selected diff --git a/selected b/selected deleted file mode 100644 index ec2b4186d36..00000000000 --- a/selected +++ /dev/null @@ -1 +0,0 @@ -lib/settings/tests/files/advanced-window.json From bc8fb22080e0f6f543b8223e54909c8f9d3ef216 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:44:30 +0200 Subject: [PATCH 05/15] nit: change path of last popup size to `/appearance/lastPopup/size` --- src/singletons/Settings.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index d20eebe20ce..98da532acad 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,7 +212,7 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; - ChatterinoSetting lastPopupSetting = {"/appearance/lastPopup", + ChatterinoSetting lastPopupSetting = {"/appearance/lastPopup/size", {300, 500}}; /// Behaviour From 0025788b44eb824e8e70ff95d6b4997a330d9c18 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:45:04 +0200 Subject: [PATCH 06/15] nit: reformat lastPopupSetting --- src/singletons/Settings.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 98da532acad..d55c92e9540 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,8 +212,10 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; - ChatterinoSetting lastPopupSetting = {"/appearance/lastPopup/size", - {300, 500}}; + ChatterinoSetting lastPopupSetting = { + "/appearance/lastPopup/size", + {300, 500}, + }; /// Behaviour BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages", From 262b101b08dd233bb3ff0b932371a0d9479353d6 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:45:14 +0200 Subject: [PATCH 07/15] nit: use QSizeSetting alias over ChatterinoSetting --- src/singletons/Settings.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index d55c92e9540..f17d6c155f9 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,7 +212,7 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; - ChatterinoSetting lastPopupSetting = { + QSizeSetting lastPopupSetting = { "/appearance/lastPopup/size", {300, 500}, }; From 7f04d41a10fdd09dd527bfcecd455d173ed1d759 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:49:02 +0200 Subject: [PATCH 08/15] nit: remove underscore from width/height in Deserialize --- src/util/RapidJsonSerializeQSize.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp index 2c92714b8fc..2a0cfde67ce 100644 --- a/src/util/RapidJsonSerializeQSize.hpp +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -29,13 +29,13 @@ struct Deserialize { return QSize{}; } - int _width; - int _height; + int width; + int height; - chatterino::rj::getSafe(value, "width", _width); - chatterino::rj::getSafe(value, "height", _height); + chatterino::rj::getSafe(value, "width", width); + chatterino::rj::getSafe(value, "height", height); - return QSize(_width, _height); + return QSize(width, height); } }; From bf9b4bad01699d0de654271aa0d67e4e825e4450 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:57:29 +0200 Subject: [PATCH 09/15] fix: handle invalid width/height values in the setting --- src/util/RapidJsonSerializeQSize.hpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp index 2a0cfde67ce..8f35d036ef1 100644 --- a/src/util/RapidJsonSerializeQSize.hpp +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -29,11 +29,19 @@ struct Deserialize { return QSize{}; } - int width; - int height; + int width{}; + int height{}; - chatterino::rj::getSafe(value, "width", width); - chatterino::rj::getSafe(value, "height", 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 QSize(width, height); } From c7ce3484e55360e8714b048b64ea0c3a57cebbd2 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:58:13 +0200 Subject: [PATCH 10/15] Handle invalid settings --- src/widgets/Window.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index cdc56db0e06..f05d7fc918f 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -77,6 +77,11 @@ Window::Window(WindowType type, QWidget *parent) else { auto lastPopup = getSettings()->lastPopupSetting.getValue(); + if (lastPopup.isEmpty()) + { + // The size in the setting was invalid, use the default value + lastPopup = getSettings()->lastPopupSetting.getDefaultValue(); + } this->resize(lastPopup.width(), lastPopup.height()); } From 8e1016711414d7a0af8c9338859076a8a04262e8 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 11:59:44 +0200 Subject: [PATCH 11/15] nit: silence clang-tidy's "missing chatterino" complaining --- src/util/RapidJsonSerializeQSize.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp index 8f35d036ef1..8e4774047a1 100644 --- a/src/util/RapidJsonSerializeQSize.hpp +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -1,5 +1,7 @@ #pragma once +#include "util/RapidjsonHelpers.hpp" + #include #include From 00e99fe9557fa98fc7b47e2be0c3254f1fcf9961 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 12:00:05 +0200 Subject: [PATCH 12/15] nit: silence clang-tidy's complaining about repeating return type --- src/util/RapidJsonSerializeQSize.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/RapidJsonSerializeQSize.hpp b/src/util/RapidJsonSerializeQSize.hpp index 8e4774047a1..c5cff37783f 100644 --- a/src/util/RapidJsonSerializeQSize.hpp +++ b/src/util/RapidJsonSerializeQSize.hpp @@ -28,7 +28,7 @@ struct Deserialize { if (!value.IsObject()) { PAJLADA_REPORT_ERROR(error); - return QSize{}; + return {}; } int width{}; @@ -45,7 +45,7 @@ struct Deserialize { return {}; } - return QSize(width, height); + return {width, height}; } }; From 6d00c26b5291f575eeb6bd22b312c3c0ce8aa7d4 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 12:00:49 +0200 Subject: [PATCH 13/15] nit: rename setting variable to `lastPopupSize` --- src/singletons/Settings.hpp | 2 +- src/widgets/Window.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index f17d6c155f9..94366dabe3e 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -212,7 +212,7 @@ class Settings BoolSetting useCustomFfzVipBadges = { "/appearance/badges/useCustomFfzVipBadges", true}; BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true}; - QSizeSetting lastPopupSetting = { + QSizeSetting lastPopupSize = { "/appearance/lastPopup/size", {300, 500}, }; diff --git a/src/widgets/Window.cpp b/src/widgets/Window.cpp index f05d7fc918f..ca443c8649b 100644 --- a/src/widgets/Window.cpp +++ b/src/widgets/Window.cpp @@ -76,11 +76,11 @@ Window::Window(WindowType type, QWidget *parent) } else { - auto lastPopup = getSettings()->lastPopupSetting.getValue(); + auto lastPopup = getSettings()->lastPopupSize.getValue(); if (lastPopup.isEmpty()) { // The size in the setting was invalid, use the default value - lastPopup = getSettings()->lastPopupSetting.getDefaultValue(); + lastPopup = getSettings()->lastPopupSize.getDefaultValue(); } this->resize(lastPopup.width(), lastPopup.height()); } @@ -159,7 +159,7 @@ void Window::closeEvent(QCloseEvent *) { QRect rect = this->getBounds(); QSize newSize(rect.width(), rect.height()); - getSettings()->lastPopupSetting.setValue(newSize); + getSettings()->lastPopupSize.setValue(newSize); } // Ensure selectedWindow_ is never an invalid pointer. // WindowManager will return the main window if no window is pointed to by From 27984078c39e18eb09a89da3f4477743addd559f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 12:04:00 +0200 Subject: [PATCH 14/15] fix: formatting --- src/common/ChatterinoSetting.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/ChatterinoSetting.hpp b/src/common/ChatterinoSetting.hpp index 502fb0be270..35d538b138a 100644 --- a/src/common/ChatterinoSetting.hpp +++ b/src/common/ChatterinoSetting.hpp @@ -3,8 +3,8 @@ #include "util/QMagicEnum.hpp" #include -#include #include +#include namespace chatterino { From 011d4da93bbc4474b670b7fb19a019cf07bbdcc1 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 12 Oct 2024 12:07:11 +0200 Subject: [PATCH 15/15] chore: add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4976ddfaa1c..3d44d989767 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)