From d5c8f45ab9bb1178c25b16e28154ed16c584f502 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Fri, 23 Jan 2015 02:09:01 +0100 Subject: [PATCH 1/5] Added buddy stars to chat --- cockatrice/cockatrice.qrc | 2 ++ cockatrice/resources/buddy_icon.svg | 56 +++++++++++++++++++++++++++++ cockatrice/src/chatview.cpp | 3 ++ cockatrice/src/pixmapgenerator.cpp | 16 +++++++++ cockatrice/src/pixmapgenerator.h | 8 +++++ 5 files changed, 85 insertions(+) create mode 100644 cockatrice/resources/buddy_icon.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index f8ce1bb8f..73fa3f87e 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -54,6 +54,8 @@ resources/genders/male.svg resources/genders/female.svg resources/genders/unknown.svg + + resources/buddy_icon.svg resources/countries/ar.svg resources/countries/at.svg diff --git a/cockatrice/resources/buddy_icon.svg b/cockatrice/resources/buddy_icon.svg new file mode 100644 index 000000000..e487714aa --- /dev/null +++ b/cockatrice/resources/buddy_icon.svg @@ -0,0 +1,56 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 5d85f58ce..cc93859d5 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -133,6 +133,9 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use 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(); + if (buddyList.contains(sender)) + cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage()); cursor.insertText(" "); } cursor.setCharFormat(senderFormat); diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp index 8bae48539..1a50f23a5 100644 --- a/cockatrice/src/pixmapgenerator.cpp +++ b/cockatrice/src/pixmapgenerator.cpp @@ -160,4 +160,20 @@ QPixmap UserLevelPixmapGenerator::generatePixmap(int height, UserLevelFlags user return pixmap; } +QMap PixmapGenerator::pmCache; +QPixmap PixmapGenerator::generatePixmap(int height, QString resourceName) { + if (pmCache.contains(resourceName)) + return pmCache.value(resourceName); + + QSvgRenderer svg(resourceName); + 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(resourceName, pixmap); + return pixmap; +} + QMap UserLevelPixmapGenerator::pmCache; diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h index 67a8b2b2e..a7ead3a26 100644 --- a/cockatrice/src/pixmapgenerator.h +++ b/cockatrice/src/pixmapgenerator.h @@ -54,4 +54,12 @@ public: static void clear() { pmCache.clear(); } }; +class PixmapGenerator { +private: + static QMap pmCache; +public: + static QPixmap generatePixmap(int height, QString resourceName); + static void clear() { pmCache.clear(); } +}; + #endif From 0aef6ecc94c9b31369348201c62f65c013c0be7b Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Fri, 23 Jan 2015 10:25:56 +0100 Subject: [PATCH 2/5] Added option in chat settings --- cockatrice/src/chatview.cpp | 8 +++++--- cockatrice/src/dlg_settings.cpp | 5 +++++ cockatrice/src/dlg_settings.h | 1 + cockatrice/src/settingscache.cpp | 7 +++++++ cockatrice/src/settingscache.h | 7 +++++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index cc93859d5..8daed9b80 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -133,9 +133,11 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use 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(); - if (buddyList.contains(sender)) - cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage()); + if (settingsCache->getShowBuddyIcon()) { + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + if (buddyList.contains(sender)) + cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage()); + } cursor.insertText(" "); } cursor.setCharFormat(senderFormat); diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 7d29b48bf..33f71285c 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -578,9 +578,13 @@ MessagesSettingsPage::MessagesSettingsPage() ignoreUnregUsersMainChat.setChecked(settingsCache->getIgnoreUnregisteredUsers()); connect(&ignoreUnregUsersMainChat, SIGNAL(stateChanged(int)), settingsCache, SLOT(setIgnoreUnregisteredUsers(int))); + showBuddyIcon.setChecked(settingsCache->getShowBuddyIcon()); + connect(&showBuddyIcon, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowBuddyIcon(int))); + QGridLayout *chatGrid = new QGridLayout; chatGrid->addWidget(&chatMentionCheckBox, 0, 0); chatGrid->addWidget(&ignoreUnregUsersMainChat, 1, 0); + chatGrid->addWidget(&showBuddyIcon, 2, 0); chatGroupBox = new QGroupBox; chatGroupBox->setLayout(chatGrid); @@ -651,6 +655,7 @@ void MessagesSettingsPage::retranslateUi() aRemove->setText(tr("&Remove")); chatGroupBox->setTitle(tr("Chat settings")); chatMentionCheckBox.setText(tr("Enable chat mentions ('@yourusername' in chat log will be highlighted)")); + showBuddyIcon.setText(tr("Show buddy Icon")); messageShortcuts->setTitle(tr("In-game message macros")); ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat")); } diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index a3875c5c1..58caac297 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -162,6 +162,7 @@ private: QAction *aRemove; QCheckBox chatMentionCheckBox; QCheckBox ignoreUnregUsersMainChat; + QCheckBox showBuddyIcon; QGroupBox *chatGroupBox; QGroupBox *messageShortcuts; diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 8bfbeb2dd..57fea9925 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -59,6 +59,8 @@ SettingsCache::SettingsCache() ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool(); + showBuddyIcon = settings->value("chat/showbuddyicon", true).toBool(); + attemptAutoConnect = settings->value("server/auto_connect", 0).toBool(); } @@ -244,6 +246,11 @@ void SettingsCache::setChatMention(int _chatMention) { settings->setValue("chat/mention", chatMention); } +void SettingsCache::setShowBuddyIcon(int _showBuddyIcon) { + showBuddyIcon = _showBuddyIcon; + settings->setValue("chat/showbuddyicon", showBuddyIcon); +} + void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) { zoneViewSortByName = _zoneViewSortByName; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index b4d6e9bf1..6ecacdbcb 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -57,6 +57,7 @@ private: int minPlayersForMultiColumnLayout; bool tapAnimation; bool chatMention; + bool showBuddyIcon; bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView, zoneViewShuffle; bool soundEnabled; QString soundPath; @@ -96,6 +97,11 @@ public: int getMinPlayersForMultiColumnLayout() const { return minPlayersForMultiColumnLayout; } bool getTapAnimation() const { return tapAnimation; } bool getChatMention() const { return chatMention; } + /** + Returns if the buddy icon should be displayed in chat. + @return buddyIcon if the buddy icon should be displayed in chat. + */ + bool getShowBuddyIcon() const { return showBuddyIcon; } bool getZoneViewSortByName() const { return zoneViewSortByName; } bool getZoneViewSortByType() const { return zoneViewSortByType; } /** @@ -146,6 +152,7 @@ public slots: void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setTapAnimation(int _tapAnimation); void setChatMention(int _chatMention); + void setShowBuddyIcon(int _showBuddyIcon); void setZoneViewSortByName(int _zoneViewSortByName); void setZoneViewSortByType(int _zoneViewSortByType); void setZoneViewPileView(int _zoneViewPileView); From ccccc78f9159645154be3ed1f854672154680303 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Fri, 23 Jan 2015 14:34:20 +0100 Subject: [PATCH 3/5] Updated colors and alignment + star is now gold with black outline + aligned for users who are not buddies --- cockatrice/cockatrice.qrc | 1 + cockatrice/resources/buddy_icon.svg | 67 ++++++++++++++++-- cockatrice/resources/empty_icon.svg | 105 ++++++++++++++++++++++++++++ cockatrice/src/chatview.cpp | 2 + 4 files changed, 171 insertions(+), 4 deletions(-) create mode 100644 cockatrice/resources/empty_icon.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 73fa3f87e..5fb8ed399 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -56,6 +56,7 @@ resources/genders/unknown.svg resources/buddy_icon.svg + resources/empty_icon.svg resources/countries/ar.svg resources/countries/at.svg diff --git a/cockatrice/resources/buddy_icon.svg b/cockatrice/resources/buddy_icon.svg index e487714aa..fa32b8c37 100644 --- a/cockatrice/resources/buddy_icon.svg +++ b/cockatrice/resources/buddy_icon.svg @@ -5,6 +5,7 @@ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" + xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" viewBox="0 0 64 64" @@ -27,7 +28,60 @@ + id="defs10"> + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/empty_icon.svg b/cockatrice/resources/empty_icon.svg new file mode 100644 index 000000000..ff4027a8f --- /dev/null +++ b/cockatrice/resources/empty_icon.svg @@ -0,0 +1,105 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 8daed9b80..e99df633f 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -137,6 +137,8 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); if (buddyList.contains(sender)) cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage()); + else + cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/empty_icon.svg").toImage()); } cursor.insertText(" "); } From 31302df43e4885c8cf0367b4dd5f8cdd352c6573 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 24 Jan 2015 01:18:32 +0100 Subject: [PATCH 4/5] WIP --- cockatrice/cockatrice.qrc | 7 +- cockatrice/resources/buddy_icon.svg | 14 +- .../resources/userlevels/admin_buddy.svg | 125 +++++++++++++++ .../resources/userlevels/moderator_buddy.svg | 147 ++++++++++++++++++ .../resources/userlevels/registered_buddy.svg | 115 ++++++++++++++ cockatrice/src/chatview.cpp | 10 +- cockatrice/src/pixmapgenerator.cpp | 7 +- cockatrice/src/pixmapgenerator.h | 2 +- cockatrice/src/playerlistwidget.cpp | 4 +- 9 files changed, 410 insertions(+), 21 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 5fb8ed399..1aebae80e 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -54,9 +54,6 @@ resources/genders/male.svg resources/genders/female.svg resources/genders/unknown.svg - - resources/buddy_icon.svg - resources/empty_icon.svg resources/countries/ar.svg resources/countries/at.svg @@ -127,6 +124,10 @@ resources/userlevels/registered.svg resources/userlevels/moderator.svg resources/userlevels/admin.svg + + resources/userlevels/registered_buddy.svg + resources/userlevels/admin_buddy.svg + resources/userlevels/moderator_buddy.svg resources/news/exclamation_mark.svg resources/news/question_mark.svg diff --git a/cockatrice/resources/buddy_icon.svg b/cockatrice/resources/buddy_icon.svg index fa32b8c37..14fcd596c 100644 --- a/cockatrice/resources/buddy_icon.svg +++ b/cockatrice/resources/buddy_icon.svg @@ -34,11 +34,11 @@ + style="stop-color:#0fbb00;stop-opacity:1;" /> + style="stop-color:#064400;stop-opacity:1;" /> @@ -91,15 +91,15 @@ guidetolerance="10" inkscape:pageopacity="0" inkscape:pageshadow="2" - inkscape:window-width="1920" - inkscape:window-height="1028" + inkscape:window-width="1600" + inkscape:window-height="1178" id="namedview8" showgrid="false" inkscape:zoom="7.375" - inkscape:cx="6.1659936" + inkscape:cx="-14.986549" inkscape:cy="23.31428" - inkscape:window-x="-8" - inkscape:window-y="-8" + inkscape:window-x="1912" + inkscape:window-y="227" inkscape:window-maximized="1" inkscape:current-layer="svg2" /> + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cockatrice/resources/userlevels/moderator_buddy.svg b/cockatrice/resources/userlevels/moderator_buddy.svg new file mode 100644 index 000000000..677c6e13a --- /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 000000000..14fcd596c --- /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 e99df633f..e8bb69069 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -132,14 +132,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)); - if (settingsCache->getShowBuddyIcon()) { - QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); - if (buddyList.contains(sender)) - cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/buddy_icon.svg").toImage()); - else - cursor.insertImage(PixmapGenerator::generatePixmap(pixelSize, ":/resources/empty_icon.svg").toImage()); - } + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + cursor.insertImage(UserLevelPixmapGenerator::generatePixmap(pixelSize, userLevel, buddyList.contains(sender)).toImage(), QString::number(pixelSize) + "_" + QString::number((int) userLevel)); cursor.insertText(" "); } cursor.setCharFormat(senderFormat); diff --git a/cockatrice/src/pixmapgenerator.cpp b/cockatrice/src/pixmapgenerator.cpp index 1a50f23a5..45c9c5a6b 100644 --- a/cockatrice/src/pixmapgenerator.cpp +++ b/cockatrice/src/pixmapgenerator.cpp @@ -134,8 +134,9 @@ 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; if (pmCache.contains(key)) return pmCache.value(key); @@ -149,6 +150,10 @@ 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); diff --git a/cockatrice/src/pixmapgenerator.h b/cockatrice/src/pixmapgenerator.h index a7ead3a26..023675b11 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 4edf26edb..46673ce8f 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -118,7 +118,9 @@ 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())))); + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); + QString userName = QString(prop.user_info().name().c_str()); + player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(prop.user_info().user_level()), buddyList.contains(userName)))); player->setText(4, QString::fromStdString(prop.user_info().name())); const QString country = QString::fromStdString(prop.user_info().country()); if (!country.isEmpty()) From 948adb49171a8bbab5bd62fca6b2912b1857ed10 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 24 Jan 2015 01:26:40 +0100 Subject: [PATCH 5/5] WIP file --- cockatrice/src/userlist.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cockatrice/src/userlist.cpp b/cockatrice/src/userlist.cpp index c6174a6e5..49f1b45fd 100644 --- a/cockatrice/src/userlist.cpp +++ b/cockatrice/src/userlist.cpp @@ -180,6 +180,7 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo) { userInfo = _userInfo; + QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); setData(0, Qt::UserRole, userInfo.user_level()); setIcon(0, QIcon(UserLevelPixmapGenerator::generatePixmap(12, UserLevelFlags(userInfo.user_level())))); setIcon(1, QIcon(CountryPixmapGenerator::generatePixmap(12, QString::fromStdString(userInfo.country()))));