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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 23 deletions

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 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)

View file

@ -85,6 +85,7 @@ inline const std::map<HotkeyCategory, ActionDefinitionMap> actionNames{
ActionDefinition{
"Usercard: execute moderation action",
"<ban, unban or number of the timeout button to use>", 1}},
{"pin", ActionDefinition{"Usercard, reply thread: pin window"}},
}},
{HotkeyCategory::Split,
{

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()
{
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

View file

@ -34,6 +34,10 @@ protected:
// lifetimeHack_ is used to check that the window hasn't been destroyed yet
std::shared_ptr<bool> 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

View file

@ -62,6 +62,11 @@ ReplyThreadPopup::ReplyThreadPopup(bool closeAutomatically, QWidget *parent,
}
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
{"execModeratorAction", nullptr},

View file

@ -231,6 +231,11 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent,
this->underlyingChannel_->sendMessage(msg);
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
{"reject", nullptr},

View file

@ -59,9 +59,9 @@ private:
std::unique_ptr<pajlada::Signals::ScopedConnection> 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;