Skip to content

Commit

Permalink
feat: add button to toggle profile pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Apr 5, 2024
1 parent ad58d9a commit c82799a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
35 changes: 34 additions & 1 deletion src/widgets/dialogs/UserInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QCheckBox>
#include <QDesktopServices>
#include <QFile>
#include <QMovie>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QPointer>
Expand Down Expand Up @@ -269,9 +270,10 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
// first line
auto head = layout.emplace<QHBoxLayout>().withoutMargin();
{
auto avatarBox = head.emplace<QVBoxLayout>().withoutMargin();
// avatar
auto avatar =
head.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);
avatarBox.emplace<Button>(nullptr).assign(&this->ui_.avatarButton);

avatar->setScaleIndependantSize(100, 100);
avatar->setDim(Button::Dim::None);
Expand Down Expand Up @@ -344,6 +346,31 @@ UserInfoPopup::UserInfoPopup(bool closeAutomatically, Split *split)
default:;
}
});
auto switchAv = avatarBox.emplace<EffectLabel2>(nullptr, 2)
.assign(&this->ui_.switchAvatars);
switchAv->hide();
QObject::connect(
switchAv.getElement(), &EffectLabel2::leftClicked, [this] {
if (!this->seventvAvatar_)
{
this->ui_.switchAvatars->hide();
return;
}
this->isTwitchAvatarShown_ = !this->isTwitchAvatarShown_;
if (this->isTwitchAvatarShown_)
{
this->seventvAvatar_->stop();
this->ui_.avatarButton->setPixmap(this->avatarPixmap_);
this->ui_.switchAvatars->getLabel().setText("Show 7TV");
}
else
{
this->ui_.avatarButton->setPixmap(
this->seventvAvatar_->currentPixmap());
this->seventvAvatar_->start();
this->ui_.switchAvatars->getLabel().setText("Show Twitch");
}
});

auto vbox = head.emplace<QVBoxLayout>();
{
Expand Down Expand Up @@ -994,6 +1021,7 @@ void UserInfoPopup::loadAvatar(const HelixUser &user)

avatar.loadFromData(cacheFile.readAll());
this->ui_.avatarButton->setPixmap(avatar);
this->avatarPixmap_ = std::move(avatar);
}
else
{
Expand All @@ -1011,6 +1039,7 @@ void UserInfoPopup::loadAvatar(const HelixUser &user)
avatar.loadFromData(data);
this->ui_.avatarButton->setPixmap(avatar);
this->saveCacheAvatar(data, filename);
this->avatarPixmap_ = std::move(avatar);
}
else
{
Expand Down Expand Up @@ -1104,6 +1133,10 @@ void UserInfoPopup::setSevenTVAvatar(const QString &filename)
});

movie->start();
this->seventvAvatar_ = movie;
this->ui_.switchAvatars->show();
this->ui_.switchAvatars->getLabel().setText("Show Twitch");
this->isTwitchAvatarShown_ = false;
}

void UserInfoPopup::saveCacheAvatar(const QByteArray &avatar,
Expand Down
8 changes: 7 additions & 1 deletion src/widgets/dialogs/UserInfoPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

#include <pajlada/signals/scoped-connection.hpp>
#include <pajlada/signals/signal.hpp>
#include <QMovie>
#include <QPixmap>

#include <chrono>

class QCheckBox;
class QMovie;

namespace chatterino {

Expand Down Expand Up @@ -100,8 +101,13 @@ class UserInfoPopup final : public DraggablePopup
ChannelView *latestMessages = nullptr;

EffectLabel2 *usercardLabel = nullptr;
EffectLabel2 *switchAvatars = nullptr;
} ui_;

QMovie *seventvAvatar_ = nullptr;
bool isTwitchAvatarShown_ = true;
QPixmap avatarPixmap_;

class TimeoutWidget : public BaseWidget
{
public:
Expand Down

0 comments on commit c82799a

Please sign in to comment.