From f915eab1a283d32a86a21227573ef28387861744 Mon Sep 17 00:00:00 2001 From: Mm2PL Date: Sat, 1 Jul 2023 16:38:55 +0000 Subject: [PATCH] Add "pin" action to usercards and reply threads (#4692) --- CHANGELOG.md | 1 + src/controllers/hotkeys/ActionNames.hpp | 1 + src/widgets/DraggablePopup.cpp | 41 ++++++++++++------------ src/widgets/DraggablePopup.hpp | 7 ++++ src/widgets/dialogs/ReplyThreadPopup.cpp | 5 +++ src/widgets/dialogs/UserInfoPopup.cpp | 5 +++ src/widgets/dialogs/UserInfoPopup.hpp | 6 ++-- 7 files changed, 43 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e2c14cc..7767bc1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Minor: Added setting to only show tabs with live channels (default toggle hotkey: Ctrl+Shift+L). (#4358) - Minor: Added option to subscribe to and unsubscribe from reply threads. (#4680) - Minor: Added a message for when Chatterino joins a channel (#4616) +- Minor: Add pin action to usercards and reply threads. (#4692) - Bugfix: Fixed generation of crashdumps by the browser-extension process when the browser was closed. (#4667) - Bugfix: Fix spacing issue with mentions inside RTL text. (#4677) - Bugfix: Fixed a crash when opening and closing a reply thread and switching the user. (#4675) diff --git a/src/controllers/hotkeys/ActionNames.hpp b/src/controllers/hotkeys/ActionNames.hpp index d658f05d..7305cb8b 100644 --- a/src/controllers/hotkeys/ActionNames.hpp +++ b/src/controllers/hotkeys/ActionNames.hpp @@ -85,6 +85,7 @@ inline const std::map actionNames{ ActionDefinition{ "Usercard: execute moderation action", "", 1}}, + {"pin", ActionDefinition{"Usercard, reply thread: pin window"}}, }}, {HotkeyCategory::Split, { diff --git a/src/widgets/DraggablePopup.cpp b/src/widgets/DraggablePopup.cpp index 157150a9..1a38d13f 100644 --- a/src/widgets/DraggablePopup.cpp +++ b/src/widgets/DraggablePopup.cpp @@ -94,29 +94,30 @@ void DraggablePopup::mouseMoveEvent(QMouseEvent *event) } } +void DraggablePopup::togglePinned() +{ + this->isPinned_ = !isPinned_; + if (isPinned_) + { + this->setActionOnFocusLoss(BaseWindow::Nothing); + this->pinButton_->setPixmap(getResources().buttons.pinEnabled); + } + else + { + this->setActionOnFocusLoss(BaseWindow::Delete); + this->pinButton_->setPixmap(getTheme()->buttons.pin); + } +} Button *DraggablePopup::createPinButton() { - auto *button = new Button(this); - button->setPixmap(getTheme()->buttons.pin); - button->setScaleIndependantSize(18, 18); - button->setToolTip("Pin Window"); + this->pinButton_ = new Button(this); + this->pinButton_->setPixmap(getTheme()->buttons.pin); + this->pinButton_->setScaleIndependantSize(18, 18); + this->pinButton_->setToolTip("Pin Window"); - bool pinned = false; - QObject::connect( - button, &Button::leftClicked, [this, button, pinned]() mutable { - pinned = !pinned; - if (pinned) - { - this->setActionOnFocusLoss(BaseWindow::Nothing); - button->setPixmap(getResources().buttons.pinEnabled); - } - else - { - this->setActionOnFocusLoss(BaseWindow::Delete); - button->setPixmap(getTheme()->buttons.pin); - } - }); - return button; + QObject::connect(this->pinButton_, &Button::leftClicked, this, + &DraggablePopup::togglePinned); + return this->pinButton_; } } // namespace chatterino diff --git a/src/widgets/DraggablePopup.hpp b/src/widgets/DraggablePopup.hpp index 578ec8df..bf82af00 100644 --- a/src/widgets/DraggablePopup.hpp +++ b/src/widgets/DraggablePopup.hpp @@ -34,6 +34,10 @@ protected: // lifetimeHack_ is used to check that the window hasn't been destroyed yet std::shared_ptr lifetimeHack_; + // Toggles pin status updates action on focus loss, isPinned_ and the pin + // button pixmap + void togglePinned(); + private: // isMoving_ is set to true if the user is holding the left mouse button down and has moved the mouse a small amount away from the original click point (startPosDrag_) bool isMoving_ = false; @@ -47,6 +51,9 @@ private: // dragTimer_ is called ~60 times per second once the user has initiated dragging QTimer dragTimer_; + + Button *pinButton_ = nullptr; + bool isPinned_ = false; }; } // namespace chatterino diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index 16c37cdd..4abb4a6b 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -62,6 +62,11 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, QWidget *parent, } return ""; }}, + {"pin", + [this](std::vector /*arguments*/) -> QString { + this->togglePinned(); + return ""; + }}, // these actions make no sense in the context of a reply thread, so they aren't implemented {"execModeratorAction", nullptr}, diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index e5955884..ab37c80c 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -231,6 +231,11 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent, this->underlyingChannel_->sendMessage(msg); return ""; }}, + {"pin", + [this](std::vector /*arguments*/) -> QString { + this->togglePinned(); + return ""; + }}, // these actions make no sense in the context of a usercard, so they aren't implemented {"reject", nullptr}, diff --git a/src/widgets/dialogs/UserInfoPopup.hpp b/src/widgets/dialogs/UserInfoPopup.hpp index 593fb670..831f96da 100644 --- a/src/widgets/dialogs/UserInfoPopup.hpp +++ b/src/widgets/dialogs/UserInfoPopup.hpp @@ -59,9 +59,9 @@ private: std::unique_ptr refreshConnection_; // If we should close the dialog automatically if the user clicks out - // Initially set based on the "Automatically close usercard when it loses focus" setting - // If that setting is enabled, this can be toggled on and off using the pin in the top-right corner - bool closeAutomatically_; + // Set based on the "Automatically close usercard when it loses focus" setting + // Pinned status is tracked in DraggablePopup::isPinned_. + const bool closeAutomatically_; struct { Button *avatarButton = nullptr;