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

View file

@ -56,6 +56,7 @@
- Minor: Remove EmojiOne 2 and 3 due to license restrictions. (#1555)
- Minor: Added `/streamlink` command. Usage: `/streamlink <channel>`. You can also use the command without arguments in any twitch channel to open it in streamlink. (#2443, #2495)
- Minor: Humanized all numbers visible to end-users. (#2488)
- Minor: Added a context menu to avatar in usercard. It opens on right-clicking the avatar in usercard. (#2517)
- Bugfix: Fix crash occurring when pressing Escape in the Color Picker Dialog (#1843)
- Bugfix: Fix bug where the "check user follow state" event could trigger a network request requesting the user to follow or unfollow a user. By itself its quite harmless as it just repeats to Twitch the same follow state we had, so no follows should have been lost by this but it meant there was a rogue network request that was fired that could cause a crash (#1906)
- Bugfix: /usercard command will now respect the "Automatically close user popup" setting (#1918)

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

View file

@ -38,6 +38,7 @@ private:
QString userName_;
QString userId_;
QString avatarUrl_;
ChannelPtr channel_;
pajlada::Signals::NoArgSignal userStateChanged_;