From d57a6111aa9c53526d64e60fd3da8b2c5c805ec9 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 31 Jan 2015 17:11:17 +0100 Subject: [PATCH] Buddy stars Buddies will now be seen as stars in the chat --- cockatrice/cockatrice.qrc | 3 + .../resources/userlevels/admin_buddy.svg | 125 +++++++++++++++ .../resources/userlevels/moderator_buddy.svg | 147 ++++++++++++++++++ .../resources/userlevels/registered_buddy.svg | 115 ++++++++++++++ cockatrice/src/chatview.cpp | 4 +- cockatrice/src/gamesmodel.cpp | 2 +- cockatrice/src/pixmapgenerator.cpp | 13 +- cockatrice/src/pixmapgenerator.h | 2 +- cockatrice/src/playerlistwidget.cpp | 2 +- cockatrice/src/playertarget.cpp | 2 +- cockatrice/src/userinfobox.cpp | 4 +- cockatrice/src/userlist.cpp | 2 +- 12 files changed, 409 insertions(+), 12 deletions(-) create mode 100644 cockatrice/resources/userlevels/admin_buddy.svg create mode 100644 cockatrice/resources/userlevels/moderator_buddy.svg create mode 100644 cockatrice/resources/userlevels/registered_buddy.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 08e2a43a..018cf1ed 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -320,8 +320,11 @@ resources/userlevels/normal.svg resources/userlevels/registered.svg + resources/userlevels/registered_buddy.svg resources/userlevels/moderator.svg + resources/userlevels/moderator_buddy.svg resources/userlevels/admin.svg + resources/userlevels/admin_buddy.svg resources/news/exclamation_mark.svg resources/news/question_mark.svg diff --git a/cockatrice/resources/userlevels/admin_buddy.svg b/cockatrice/resources/userlevels/admin_buddy.svg new file mode 100644 index 00000000..0d4defb5 --- /dev/null +++ b/cockatrice/resources/userlevels/admin_buddy.svg @@ -0,0 +1,125 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/moderator_buddy.svg b/cockatrice/resources/userlevels/moderator_buddy.svg new file mode 100644 index 00000000..677c6e13 --- /dev/null +++ b/cockatrice/resources/userlevels/moderator_buddy.svg @@ -0,0 +1,147 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/registered_buddy.svg b/cockatrice/resources/userlevels/registered_buddy.svg new file mode 100644 index 00000000..14fcd596 --- /dev/null +++ b/cockatrice/resources/userlevels/registered_buddy.svg @@ -0,0 +1,115 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index f93980e8..41e80b21 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "chatview.h" #include "user_level.h" #include "user_context_menu.h" @@ -130,7 +131,8 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use if (!sameSender) { if (!sender.isEmpty()) { const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize(); - cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel)); + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender)).toImage()); cursor.insertText(" "); } cursor.setCharFormat(senderFormat); diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 1ef81e16..716ff085 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -115,7 +115,7 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const case Qt::DisplayRole: return QString::fromStdString(g.creator_info().name()); case Qt::DecorationRole: { - QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)g.creator_info().user_level()); + QPixmap avatarPixmap = UserLevelPixmapGenerator::generatePixmap(13, (UserLevelFlags)g.creator_info().user_level(), false); return QIcon(avatarPixmap); } default: diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp index 8bae4853..4241a8f4 100644 --- a/cockatrice/src/pixmapgenerator.cpp +++ b/cockatrice/src/pixmapgenerator.cpp @@ -134,12 +134,13 @@ QPixmap CountryPixmapGenerator::generatePixmap(int height, const QString &countr QMap CountryPixmapGenerator::pmCache; -QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel) +QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy) { - int key = height * 10000 + (int) userLevel; + + int key = height * 10000 + (int) userLevel + (int) isBuddy; if (pmCache.contains(key)) return pmCache.value(key); - + QString levelString; if (userLevel.testFlag(ServerInfo_User::IsAdmin)) levelString = "admin"; @@ -149,13 +150,17 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user levelString = "registered"; else levelString = "normal"; + + if (isBuddy) + levelString.append("_buddy"); + QSvgRenderer svg(QString(":/resources/userlevels/" + levelString + ".svg")); int width = (int) round(height * (double) svg.defaultSize().width() / (double) svg.defaultSize().height()); QPixmap pixmap(width, height); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); svg.render(&painter, QRectF(0, 0, width, height)); - + pmCache.insert(key, pixmap); return pixmap; } diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h index 67a8b2b2..9caeece9 100644 --- a/cockatrice/src/pixmapgenerator.h +++ b/cockatrice/src/pixmapgenerator.h @@ -50,7 +50,7 @@ class UserLevelPixmapGenerator { private: static QMap pmCache; public: - static QPixmap generatePixmap(int height, UserLevelFlags userLevel); + static QPixmap generatePixmap(int height, UserLevelFlags userLevel, bool isBuddy); static void clear() { pmCache.clear(); } }; diff --git a/cockatrice/src/playerlistwidget.cpp b/cockatrice/src/playerlistwidget.cpp index 4edf26ed..e18bab98 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -118,7 +118,7 @@ void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon)); if (prop.has_user_info()) { player->setData(3, Qt::UserRole, prop.user_info().user_level()); - player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level())))); + player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()), false))); player->setText(4, QString::fromStdString(prop.user_info().name())); const QString country = QString::fromStdString(prop.user_info().country()); if (!country.isEmpty()) diff --git a/cockatrice/src/playertarget.cpp b/cockatrice/src/playertarget.cpp index 98b266df..d1081797 100644 --- a/cockatrice/src/playertarget.cpp +++ b/cockatrice/src/playertarget.cpp @@ -98,7 +98,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o QPixmap tempPixmap; if (fullPixmap.isNull()) - tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level())); + tempPixmap = UserLevelPixmapGenerator::generatePixmap(translatedSize.height(), UserLevelFlags(info->user_level()), false); else tempPixmap = fullPixmap.scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); diff --git a/cockatrice/src/userinfobox.cpp b/cockatrice/src/userinfobox.cpp index 6c33bbf7..0fd0e569 100644 --- a/cockatrice/src/userinfobox.cpp +++ b/cockatrice/src/userinfobox.cpp @@ -60,7 +60,7 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user) QPixmap avatarPixmap; const std::string bmp = user.avatar_bmp(); if (!avatarPixmap.loadFromData((const uchar *) bmp.data(), bmp.size())) - avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel); + avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, userLevel, false); avatarLabel.setPixmap(avatarPixmap); nameLabel.setText(QString::fromStdString(user.name())); @@ -69,7 +69,7 @@ void UserInfoBox::updateInfo(const ServerInfo_User &user) QString country = QString::fromStdString(user.country()); countryLabel2.setPixmap(CountryPixmapGenerator::generatePixmap(15, country)); countryLabel3.setText(QString("(%1)").arg(country.toUpper())); - userLevelLabel2.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel)); + userLevelLabel2.setPixmap(UserLevelPixmapGenerator::generatePixmap(15, userLevel, false)); QString userLevelText; if (userLevel.testFlag(ServerInfo_User::IsAdmin)) userLevelText = tr("Administrator"); diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index c6174a6e..5e9e2490 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -181,7 +181,7 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo) userInfo = _userInfo; setData(0, Qt::UserRole, userInfo.user_level()); - setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level())))); + setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level()), false))); setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country())))); setData(2, Qt::UserRole, QString::fromStdString(userInfo.name())); setData(2, Qt::DisplayRole, QString::fromStdString(userInfo.name()));