Add "pin" action to usercards and reply threads (#4692)

This commit is contained in:
Mm2PL
2023-07-01 16:38:55 +00:00
committed by GitHub
parent 61566e2f4f
commit f915eab1a2
7 changed files with 43 additions and 23 deletions
+1
View File
@@ -10,6 +10,7 @@
- Minor: Added setting to only show tabs with live channels (default toggle hotkey: Ctrl+Shift+L). (#4358) - 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 option to subscribe to and unsubscribe from reply threads. (#4680)
- Minor: Added a message for when Chatterino joins a channel (#4616) - 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: 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: 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) - Bugfix: Fixed a crash when opening and closing a reply thread and switching the user. (#4675)
+1
View File
@@ -85,6 +85,7 @@ inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
ActionDefinition{ ActionDefinition{
"Usercard: execute moderation action", "Usercard: execute moderation action",
"<ban, unban or number of the timeout button to use>", 1}}, "<ban, unban or number of the timeout button to use>", 1}},
{"pin", ActionDefinition{"Usercard, reply thread: pin window"}},
}}, }},
{HotkeyCategory::Split, {HotkeyCategory::Split,
{ {
+21 -20
View File
@@ -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() Button *DraggablePopup::createPinButton()
{ {
auto *button = new Button(this); this->pinButton_ = new Button(this);
button->setPixmap(getTheme()->buttons.pin); this->pinButton_->setPixmap(getTheme()->buttons.pin);
button->setScaleIndependantSize(18, 18); this->pinButton_->setScaleIndependantSize(18, 18);
button->setToolTip("Pin Window"); this->pinButton_->setToolTip("Pin Window");
bool pinned = false; QObject::connect(this->pinButton_, &Button::leftClicked, this,
QObject::connect( &DraggablePopup::togglePinned);
button, &Button::leftClicked, [this, button, pinned]() mutable { return this->pinButton_;
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;
} }
} // namespace chatterino } // namespace chatterino
+7
View File
@@ -34,6 +34,10 @@ protected:
// lifetimeHack_ is used to check that the window hasn't been destroyed yet // lifetimeHack_ is used to check that the window hasn't been destroyed yet
std::shared_ptr<bool> lifetimeHack_; std::shared_ptr<bool> lifetimeHack_;
// Toggles pin status updates action on focus loss, isPinned_ and the pin
// button pixmap
void togglePinned();
private: 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_) // 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; bool isMoving_ = false;
@@ -47,6 +51,9 @@ private:
// dragTimer_ is called ~60 times per second once the user has initiated dragging // dragTimer_ is called ~60 times per second once the user has initiated dragging
QTimer dragTimer_; QTimer dragTimer_;
Button *pinButton_ = nullptr;
bool isPinned_ = false;
}; };
} // namespace chatterino } // namespace chatterino
+5
View File
@@ -62,6 +62,11 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, QWidget *parent,
} }
return ""; return "";
}}, }},
{"pin",
[this](std::vector<QString> /*arguments*/) -> QString {
this->togglePinned();
return "";
}},
// these actions make no sense in the context of a reply thread, so they aren't implemented // these actions make no sense in the context of a reply thread, so they aren't implemented
{"execModeratorAction", nullptr}, {"execModeratorAction", nullptr},
+5
View File
@@ -231,6 +231,11 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent,
this->underlyingChannel_->sendMessage(msg); this->underlyingChannel_->sendMessage(msg);
return ""; return "";
}}, }},
{"pin",
[this](std::vector<QString> /*arguments*/) -> QString {
this->togglePinned();
return "";
}},
// these actions make no sense in the context of a usercard, so they aren't implemented // these actions make no sense in the context of a usercard, so they aren't implemented
{"reject", nullptr}, {"reject", nullptr},
+3 -3
View File
@@ -59,9 +59,9 @@ private:
std::unique_ptr<pajlada::Signals::ScopedConnection> refreshConnection_; std::unique_ptr<pajlada::Signals::ScopedConnection> refreshConnection_;
// If we should close the dialog automatically if the user clicks out // 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 // 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 // Pinned status is tracked in DraggablePopup::isPinned_.
bool closeAutomatically_; const bool closeAutomatically_;
struct { struct {
Button *avatarButton = nullptr; Button *avatarButton = nullptr;