Add ability to pin Usercards to stay open even if it loses focus (#3884)
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com> Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com> Co-authored-by: James Upjohn <jammehcow@jammehcow.co.nz>
This commit is contained in:
@@ -134,11 +134,13 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent,
|
||||
Split *split)
|
||||
: DraggablePopup(closeAutomatically, parent)
|
||||
, split_(split)
|
||||
, closeAutomatically_(closeAutomatically)
|
||||
{
|
||||
assert(split != nullptr &&
|
||||
"split being nullptr causes lots of bugs down the road");
|
||||
this->setWindowTitle("Usercard");
|
||||
this->setStayInScreenRect(true);
|
||||
this->updateFocusLoss();
|
||||
|
||||
HotkeyController::HotkeyMap actions{
|
||||
{"delete",
|
||||
@@ -349,6 +351,22 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent,
|
||||
|
||||
this->ui_.localizedNameLabel->setVisible(false);
|
||||
this->ui_.localizedNameCopyButton->setVisible(false);
|
||||
|
||||
// button to pin the window (only if we close automatically)
|
||||
if (this->closeAutomatically_)
|
||||
{
|
||||
this->ui_.pinButton = box.emplace<Button>().getElement();
|
||||
this->ui_.pinButton->setPixmap(
|
||||
getApp()->themes->buttons.pin);
|
||||
this->ui_.pinButton->setScaleIndependantSize(18, 18);
|
||||
this->ui_.pinButton->setToolTip("Pin Window");
|
||||
QObject::connect(this->ui_.pinButton, &Button::leftClicked,
|
||||
[this]() {
|
||||
this->closeAutomatically_ =
|
||||
!this->closeAutomatically_;
|
||||
this->updateFocusLoss();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// items on the left
|
||||
@@ -873,6 +891,26 @@ void UserInfoPopup::updateUserData()
|
||||
this->ui_.ignoreHighlights->setEnabled(false);
|
||||
}
|
||||
|
||||
void UserInfoPopup::updateFocusLoss()
|
||||
{
|
||||
if (this->closeAutomatically_)
|
||||
{
|
||||
this->setActionOnFocusLoss(BaseWindow::Delete);
|
||||
if (this->ui_.pinButton != nullptr)
|
||||
{
|
||||
this->ui_.pinButton->setPixmap(getApp()->themes->buttons.pin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setActionOnFocusLoss(BaseWindow::Nothing);
|
||||
if (this->ui_.pinButton != nullptr)
|
||||
{
|
||||
this->ui_.pinButton->setPixmap(getResources().buttons.pinEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserInfoPopup::loadAvatar(const QUrl &url)
|
||||
{
|
||||
QNetworkRequest req(url);
|
||||
|
||||
@@ -36,6 +36,7 @@ private:
|
||||
void installEvents();
|
||||
void updateUserData();
|
||||
void updateLatestMessages();
|
||||
void updateFocusLoss();
|
||||
|
||||
void loadAvatar(const QUrl &url);
|
||||
bool isMod_;
|
||||
@@ -46,8 +47,10 @@ private:
|
||||
QString userName_;
|
||||
QString userId_;
|
||||
QString avatarUrl_;
|
||||
|
||||
// The channel the popup was opened from (e.g. /mentions or #forsen). Can be a special channel.
|
||||
ChannelPtr channel_;
|
||||
|
||||
// The channel the messages are rendered from (e.g. #forsen). Can be a special channel, but will try to not be where possible.
|
||||
ChannelPtr underlyingChannel_;
|
||||
|
||||
@@ -55,6 +58,11 @@ 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_;
|
||||
|
||||
struct {
|
||||
Button *avatarButton = nullptr;
|
||||
Button *localizedNameCopyButton = nullptr;
|
||||
@@ -64,6 +72,8 @@ private:
|
||||
Label *followerCountLabel = nullptr;
|
||||
Label *createdDateLabel = nullptr;
|
||||
Label *userIDLabel = nullptr;
|
||||
// Can be uninitialized if usercard is not configured to close on focus loss
|
||||
Button *pinButton = nullptr;
|
||||
Label *followageLabel = nullptr;
|
||||
Label *subageLabel = nullptr;
|
||||
|
||||
|
||||
@@ -700,7 +700,7 @@ void GeneralPage::initLayout(GeneralPageView &layout)
|
||||
s.mentionUsersWithComma);
|
||||
layout.addCheckbox("Show joined users (< 1000 chatters)", s.showJoins);
|
||||
layout.addCheckbox("Show parted users (< 1000 chatters)", s.showParts);
|
||||
layout.addCheckbox("Automatically close user popup when it loses focus",
|
||||
layout.addCheckbox("Automatically close usercard when it loses focus",
|
||||
s.autoCloseUserPopup);
|
||||
layout.addCheckbox(
|
||||
"Automatically close reply thread popup when it loses focus",
|
||||
|
||||
Reference in New Issue
Block a user