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:
Patrick Geneva
2022-11-12 07:21:43 -05:00
committed by GitHub
parent 070151fbc8
commit 06b28ea0ab
15 changed files with 134 additions and 1 deletions
+38
View File
@@ -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);