Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember Popped-up Chat Size #5635

Merged
merged 16 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <username>` CLI argument to specify which account to start logged in as. (#5626)
Expand Down
2 changes: 2 additions & 0 deletions src/common/ChatterinoSetting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "util/QMagicEnum.hpp"

#include <pajlada/settings.hpp>
#include <QSize>
#include <QString>

namespace chatterino {
Expand Down Expand Up @@ -55,6 +56,7 @@ using DoubleSetting = ChatterinoSetting<double>;
using IntSetting = ChatterinoSetting<int>;
using StringSetting = ChatterinoSetting<std::string>;
using QStringSetting = ChatterinoSetting<QString>;
using QSizeSetting = ChatterinoSetting<QSize>;

template <typename Enum>
class EnumSetting
Expand Down
4 changes: 4 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ class Settings
BoolSetting useCustomFfzVipBadges = {
"/appearance/badges/useCustomFfzVipBadges", true};
BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true};
QSizeSetting lastPopupSize = {
"/appearance/lastPopup/size",
{300, 500},
};

/// Behaviour
BoolSetting allowDuplicateMessages = {"/behaviour/allowDuplicateMessages",
Expand Down
52 changes: 52 additions & 0 deletions src/util/RapidJsonSerializeQSize.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include "util/RapidjsonHelpers.hpp"

#include <pajlada/serialize.hpp>
#include <QSize>

namespace pajlada {

template <>
struct Serialize<QSize> {
static rapidjson::Value get(const QSize &value,
rapidjson::Document::AllocatorType &a)
{
rapidjson::Value ret(rapidjson::kObjectType);

chatterino::rj::set(ret, "width", value.width(), a);
pajlada marked this conversation as resolved.
Show resolved Hide resolved
chatterino::rj::set(ret, "height", value.height(), a);
pajlada marked this conversation as resolved.
Show resolved Hide resolved

return ret;
}
};

template <>
struct Deserialize<QSize> {
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
16 changes: 14 additions & 2 deletions src/widgets/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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_`.
Expand Down
Loading