mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
make account tab default profile high quality
This commit is contained in:
parent
95cea0f191
commit
e1bd6c5ef9
2 changed files with 26 additions and 3 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
#include "../pending_command.h"
|
#include "../pending_command.h"
|
||||||
#include "passwordhasher.h"
|
#include "passwordhasher.h"
|
||||||
#include "pb/response_get_user_info.pb.h"
|
#include "pb/response_get_user_info.pb.h"
|
||||||
|
#include "pb/serverinfo_user.pb.h"
|
||||||
#include "pb/session_commands.pb.h"
|
#include "pb/session_commands.pb.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
|
@ -84,14 +85,27 @@ void UserInfoBox::retranslateUi()
|
||||||
avatarButton.setText(tr("Change avatar"));
|
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)
|
void UserInfoBox::updateInfo(const ServerInfo_User &user)
|
||||||
{
|
{
|
||||||
|
currentUserInfo = &user;
|
||||||
|
|
||||||
const UserLevelFlags userLevel(user.user_level());
|
const UserLevelFlags userLevel(user.user_level());
|
||||||
|
|
||||||
const std::string &bmp = user.avatar_bmp();
|
const std::string &bmp = user.avatar_bmp();
|
||||||
if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), static_cast<uint>(bmp.size()))) {
|
if (!avatarPixmap.loadFromData((const uchar *)bmp.data(), static_cast<uint>(bmp.size()))) {
|
||||||
avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, user.pawn_colors(), false,
|
avatarPixmap = createDefaultAvatar(64, user);
|
||||||
QString::fromStdString(user.privlevel()));
|
hasAvatar = false;
|
||||||
|
} else {
|
||||||
|
hasAvatar = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nameLabel.setText(QString::fromStdString(user.name()));
|
nameLabel.setText(QString::fromStdString(user.name()));
|
||||||
|
|
@ -363,7 +377,14 @@ void UserInfoBox::processAvatarResponse(const Response &r)
|
||||||
|
|
||||||
void UserInfoBox::resizeEvent(QResizeEvent *event)
|
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);
|
avatarPic.setPixmap(resizedPixmap);
|
||||||
|
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ private:
|
||||||
countryLabel3, userLevelLabel1, userLevelLabel2, accountAgeLabel1, accountAgeLabel2;
|
countryLabel3, userLevelLabel1, userLevelLabel2, accountAgeLabel1, accountAgeLabel2;
|
||||||
QPushButton editButton, passwordButton, avatarButton;
|
QPushButton editButton, passwordButton, avatarButton;
|
||||||
QPixmap avatarPixmap;
|
QPixmap avatarPixmap;
|
||||||
|
bool hasAvatar;
|
||||||
|
const ServerInfo_User *currentUserInfo;
|
||||||
|
|
||||||
static QString getAgeString(int ageSeconds);
|
static QString getAgeString(int ageSeconds);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue