From ebfcb49e8c6e279e038066ef93afdaab4012c035 Mon Sep 17 00:00:00 2001 From: mmb L Date: Mon, 13 Apr 2020 19:15:51 +0800 Subject: [PATCH] Make emote popup remember last position (#1580) * Use existing moveTo to ensure window stay within desktop geometry --- src/singletons/WindowManager.cpp | 19 +++++++++++++++++++ src/singletons/WindowManager.hpp | 5 +++++ src/widgets/dialogs/EmotePopup.cpp | 8 ++++++++ src/widgets/dialogs/EmotePopup.hpp | 2 ++ 4 files changed, 34 insertions(+) diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index fb1a28a3b..5c9f23cad 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -274,6 +274,16 @@ Window *WindowManager::windowAt(int index) return this->windows_.at(index); } +QPoint WindowManager::emotePopupPos() +{ + return this->emotePopupPos_; +} + +void WindowManager::setEmotePopupPos(QPoint pos) +{ + this->emotePopupPos_ = pos; +} + void WindowManager::initialize(Settings &settings, Paths &paths) { assertInGuiThread(); @@ -401,6 +411,10 @@ void WindowManager::initialize(Settings &settings, Paths &paths) } window.show(); + QJsonObject emote_popup_obj = window_obj.value("emotePopup").toObject(); + this->emotePopupPos_ = QPoint(emote_popup_obj.value("x").toInt(), + emote_popup_obj.value("y").toInt()); + if (window_obj.value("state") == "minimized") { window.setWindowState(Qt::WindowMinimized); @@ -478,6 +492,11 @@ void WindowManager::save() window_obj.insert("width", rect.width()); window_obj.insert("height", rect.height()); + QJsonObject emote_popup_obj; + emote_popup_obj.insert("x", this->emotePopupPos_.x()); + emote_popup_obj.insert("y", this->emotePopupPos_.y()); + window_obj.insert("emotePopup", emote_popup_obj); + // window tabs QJsonArray tabs_arr; diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index 9dfd8d9bb..7ffe52e11 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -51,6 +51,9 @@ public: int windowCount(); Window *windowAt(int index); + QPoint emotePopupPos(); + void setEmotePopupPos(QPoint pos); + virtual void initialize(Settings &settings, Paths &paths) override; virtual void save() override; void closeAll(); @@ -89,6 +92,8 @@ private: bool initialized_ = false; + QPoint emotePopupPos_; + std::atomic generation_{0}; std::vector windows_; diff --git a/src/widgets/dialogs/EmotePopup.cpp b/src/widgets/dialogs/EmotePopup.cpp index 9e0911cb7..72b04ee4c 100644 --- a/src/widgets/dialogs/EmotePopup.cpp +++ b/src/widgets/dialogs/EmotePopup.cpp @@ -8,6 +8,7 @@ #include "messages/MessageBuilder.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "singletons/Emotes.hpp" +#include "singletons/WindowManager.hpp" #include "util/Shortcut.hpp" #include "widgets/Notebook.hpp" #include "widgets/helper/ChannelView.hpp" @@ -113,6 +114,8 @@ namespace { EmotePopup::EmotePopup(QWidget *parent) : BasePopup(BaseWindow::EnableCustomFrame, parent) { + this->moveTo(this, getApp()->windows->emotePopupPos()); + auto layout = new QVBoxLayout(this); this->getLayoutContainer()->setLayout(layout); @@ -220,4 +223,9 @@ void EmotePopup::loadEmojis() this->viewEmojis_->setChannel(emojiChannel); } +void EmotePopup::closeEvent(QCloseEvent *event) +{ + getApp()->windows->setEmotePopupPos(this->pos()); + QWidget::closeEvent(event); +} } // namespace chatterino diff --git a/src/widgets/dialogs/EmotePopup.hpp b/src/widgets/dialogs/EmotePopup.hpp index 7e24faf95..18647f26d 100644 --- a/src/widgets/dialogs/EmotePopup.hpp +++ b/src/widgets/dialogs/EmotePopup.hpp @@ -19,6 +19,8 @@ public: void loadChannel(ChannelPtr channel); void loadEmojis(); + virtual void closeEvent(QCloseEvent *event) override; + pajlada::Signals::Signal linkClicked; private: