From e1bd6c5ef9406f962f3af44a79d1599cb2a1fe83 Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sun, 2 Feb 2025 00:36:28 -0800 Subject: [PATCH] make account tab default profile high quality --- cockatrice/src/server/user/user_info_box.cpp | 27 +++++++++++++++++--- cockatrice/src/server/user/user_info_box.h | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/server/user/user_info_box.cpp b/cockatrice/src/server/user/user_info_box.cpp index 53e1d3379..3f2381011 100644 --- a/cockatrice/src/server/user/user_info_box.cpp +++ b/cockatrice/src/server/user/user_info_box.cpp @@ -9,6 +9,7 @@ #include "../pending_command.h" #include "passwordhasher.h" #include "pb/response_get_user_info.pb.h" +#include "pb/serverinfo_user.pb.h" #include "pb/session_commands.pb.h" #include @@ -84,14 +85,27 @@ void UserInfoBox::retranslateUi() avatarButton.setText(tr("Change avatar")); } +/** + * Creates the default profile pic that is used when the user doesn't have a custom pic + */ +static QPixmap createDefaultAvatar(int height, const ServerInfo_User &user) +{ + return UserLevelPixmapGenerator::generatePixmap(height, UserLevelFlags(user.user_level()), user.pawn_colors(), + false, QString::fromStdString(user.privlevel())); +} + void UserInfoBox::updateInfo(const ServerInfo_User &user) { + currentUserInfo = &user; + const UserLevelFlags userLevel(user.user_level()); const std::string &bmp = user.avatar_bmp(); if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), static_cast(bmp.size()))) { - avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, user.pawn_colors(), false, - QString::fromStdString(user.privlevel())); + avatarPixmap = createDefaultAvatar(64, user); + hasAvatar = false; + } else { + hasAvatar = true; } nameLabel.setText(QString::fromStdString(user.name())); @@ -363,7 +377,14 @@ void UserInfoBox::processAvatarResponse(const Response &r) void UserInfoBox::resizeEvent(QResizeEvent *event) { - QPixmap resizedPixmap = avatarPixmap.scaled(avatarPic.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + QPixmap resizedPixmap; + if (hasAvatar) { + resizedPixmap = avatarPixmap.scaled(avatarPic.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); + } else { + int height = qMin(avatarPic.size().width(), avatarPic.size().height()); + resizedPixmap = createDefaultAvatar(height, *currentUserInfo); + } avatarPic.setPixmap(resizedPixmap); + QWidget::resizeEvent(event); } diff --git a/cockatrice/src/server/user/user_info_box.h b/cockatrice/src/server/user/user_info_box.h index 1fa5bb308..170c27bb2 100644 --- a/cockatrice/src/server/user/user_info_box.h +++ b/cockatrice/src/server/user/user_info_box.h @@ -20,6 +20,8 @@ private: countryLabel3, userLevelLabel1, userLevelLabel2, accountAgeLabel1, accountAgeLabel2; QPushButton editButton, passwordButton, avatarButton; QPixmap avatarPixmap; + bool hasAvatar; + const ServerInfo_User *currentUserInfo; static QString getAgeString(int ageSeconds);