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 3 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 selected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib/settings/tests/files/advanced-window.json
2 changes: 2 additions & 0 deletions src/common/ChatterinoSetting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

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
2 changes: 2 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class Settings
BoolSetting useCustomFfzVipBadges = {
"/appearance/badges/useCustomFfzVipBadges", true};
BoolSetting showBadgesSevenTV = {"/appearance/badges/seventv", true};
ChatterinoSetting<QSize> lastPopupSetting = {"/appearance/lastPopup",
{300, 500}};

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

#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 QSize{};
}

int _width;
pajlada marked this conversation as resolved.
Show resolved Hide resolved
pajlada marked this conversation as resolved.
Show resolved Hide resolved
int _height;
pajlada marked this conversation as resolved.
Show resolved Hide resolved
pajlada marked this conversation as resolved.
Show resolved Hide resolved

chatterino::rj::getSafe(value, "width", _width);
pajlada marked this conversation as resolved.
Show resolved Hide resolved
chatterino::rj::getSafe(value, "height", _height);
pajlada marked this conversation as resolved.
Show resolved Hide resolved

return QSize(_width, _height);
pajlada marked this conversation as resolved.
Show resolved Hide resolved
}
};

} // namespace pajlada
11 changes: 9 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,8 @@ Window::Window(WindowType type, QWidget *parent)
}
else
{
this->resize(int(300 * this->scale()), int(500 * this->scale()));
auto lastPopup = getSettings()->lastPopupSetting.getValue();
this->resize(lastPopup.width(), lastPopup.height());
}

this->signalHolder_.managedConnect(getApp()->getHotkeys()->onItemsUpdated,
Expand Down Expand Up @@ -148,7 +150,12 @@ void Window::closeEvent(QCloseEvent *)
getApp()->getWindows()->save();
getApp()->getWindows()->closeAll();
}

else
{
QRect rect = this->getBounds();
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
// `selectedWindow_`.
Expand Down
Loading