Added avatar context menu to usercard (#2517)

This commit is contained in:
Paweł
2021-03-14 15:09:16 +01:00
committed by GitHub
parent 7002954aa9
commit 382462f465
3 changed files with 51 additions and 4 deletions
+49 -4
View File
@@ -149,10 +149,54 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, QWidget *parent)
head.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);
avatar->setScaleIndependantSize(100, 100);
avatar->setDim(Button::Dim::None);
QObject::connect(avatar.getElement(), &Button::leftClicked, [this] {
QDesktopServices::openUrl(
QUrl("https://twitch.tv/" + this->userName_.toLower()));
});
QObject::connect(
avatar.getElement(), &Button::clicked,
[this](Qt::MouseButton button) {
switch (button)
{
case Qt::LeftButton: {
QDesktopServices::openUrl(QUrl(
"https://twitch.tv/" + this->userName_.toLower()));
}
break;
case Qt::RightButton: {
// don't raise open context menu if there's no avatar (probably in cases when invalid user's usercard was opened)
if (this->avatarUrl_.isEmpty())
{
return;
}
static QMenu *previousMenu = nullptr;
if (previousMenu != nullptr)
{
previousMenu->deleteLater();
previousMenu = nullptr;
}
auto menu = new QMenu;
previousMenu = menu;
// add context menu actions
menu->addAction(
"Open avatar in browser",
[avatarUrl = this->avatarUrl_] {
QDesktopServices::openUrl(QUrl(avatarUrl));
});
menu->addAction("Copy avatar link",
[avatarUrl = this->avatarUrl_] {
crossPlatformCopy(avatarUrl);
});
menu->popup(QCursor::pos());
menu->raise();
}
break;
default:;
}
});
auto vbox = head.emplace<QVBoxLayout>();
{
@@ -604,6 +648,7 @@ void UserInfoPopup::updateUserData()
}
this->userId_ = user.id;
this->avatarUrl_ = user.profileImageUrl;
this->ui_.nameLabel->setText(user.displayName);
this->setWindowTitle(TEXT_TITLE.arg(user.displayName));