Show more statuses in icons.
authorunc0rr
Mon, 01 Oct 2012 00:31:38 +0400
changeset 7720 8e6b79a020f8
parent 7719 eeae1cb6b6bf
child 7721 2b1ad418ba39
Show more statuses in icons. Need further work: - Better icons (specially registered vs unregistered) - Share information between chat widgets (now room widget can't show registered status because recieves events for users when user list is empty)
QTfrontend/hedgewars.qrc
QTfrontend/hwform.cpp
QTfrontend/res/chat/friend.png
QTfrontend/res/chat/hedgehog.png
QTfrontend/res/chat/hedgehog_gray.png
QTfrontend/res/chat/ignore.png
QTfrontend/res/chat/lamp.png
QTfrontend/res/chat/roomadmin.png
QTfrontend/res/chat/roomadmin_gray.png
QTfrontend/res/chat/serveradmin.png
QTfrontend/res/chat/serveradmin_gray.png
QTfrontend/res/chat_default.png
QTfrontend/res/chat_default_off.png
QTfrontend/res/chat_default_on.png
QTfrontend/res/chat_friend.png
QTfrontend/res/chat_friend_off.png
QTfrontend/res/chat_friend_on.png
QTfrontend/res/chat_ignore.png
QTfrontend/res/chat_ignore_off.png
QTfrontend/res/chat_ignore_on.png
QTfrontend/ui/page/pagenetgame.cpp
QTfrontend/ui/widget/chatwidget.cpp
QTfrontend/ui/widget/chatwidget.h
--- a/QTfrontend/hedgewars.qrc	Sat Sep 29 19:26:18 2012 +0400
+++ b/QTfrontend/hedgewars.qrc	Mon Oct 01 00:31:38 2012 +0400
@@ -5,7 +5,7 @@
         <file>res/css/chat.css</file>
         <file>res/css/christmas.css</file>
         <file>res/css/easter.css</file>
-        <file>res/css/birthday.css</file>		  
+        <file>res/css/birthday.css</file>
         <file>res/hh25x25.png</file>
         <file>res/hh25x25grey.png</file>
         <file>res/ammopic.png</file>
@@ -102,20 +102,11 @@
         <file>res/iconRope.png</file>
         <file>res/dice.png</file>
         <file>res/Star.png</file>
-	<file>res/Flake.png</file>
-	<file>res/Egg.png</file>
-	<file>res/Confetti.png</file>
+        <file>res/Flake.png</file>
+        <file>res/Egg.png</file>
+        <file>res/Confetti.png</file>
         <file>res/file_save.png</file>
         <file>res/file_demo.png</file>
-        <file>res/chat_default.png</file>
-        <file>res/chat_ignore.png</file>
-        <file>res/chat_friend.png</file>
-        <file>res/chat_default_on.png</file>
-        <file>res/chat_ignore_on.png</file>
-        <file>res/chat_friend_on.png</file>
-        <file>res/chat_default_off.png</file>
-        <file>res/chat_ignore_off.png</file>
-        <file>res/chat_friend_off.png</file>
         <file>res/addfriend.png</file>
         <file>res/remfriend.png</file>
         <file>res/ignore.png</file>
@@ -143,5 +134,14 @@
         <file>res/mapMissing.png</file>
         <file>res/mapCustom.png</file>
         <file>res/mapMission.png</file>
+        <file>res/chat/friend.png</file>
+        <file>res/chat/ignore.png</file>
+        <file>res/chat/lamp.png</file>
+        <file>res/chat/hedgehog.png</file>
+        <file>res/chat/hedgehog_gray.png</file>
+        <file>res/chat/roomadmin.png</file>
+        <file>res/chat/roomadmin_gray.png</file>
+        <file>res/chat/serveradmin.png</file>
+        <file>res/chat/serveradmin_gray.png</file>
     </qresource>
 </RCC>
--- a/QTfrontend/hwform.cpp	Sat Sep 29 19:26:18 2012 +0400
+++ b/QTfrontend/hwform.cpp	Mon Oct 01 00:31:38 2012 +0400
@@ -1121,6 +1121,17 @@
             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(setReadyStatus(const QString &, bool)),
             ui.pageNetGame->pChatWidget, SLOT(setReadyStatus(const QString &, bool)), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(setAdminStatus(const QString &, bool)),
+            ui.pageNetGame->pChatWidget, SLOT(setAdminStatus(const QString &, bool)), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(setAdminStatus(const QString &, bool)),
+            ui.pageRoomsList->chatWidget, SLOT(setAdminStatus(const QString &, bool)), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(setRoomMasterStatus(const QString &, bool)),
+            ui.pageNetGame->pChatWidget, SLOT(setRoomMasterStatus(const QString &, bool)), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(setRegisteredStatus(const QStringList &, bool)),
+            ui.pageNetGame->pChatWidget, SLOT(setRegisteredStatus(const QStringList &, bool)), Qt::QueuedConnection);
+    connect(hwnet, SIGNAL(setRegisteredStatus(const QStringList &, bool)),
+            ui.pageRoomsList->chatWidget, SLOT(setRegisteredStatus(const QStringList &, bool)), Qt::QueuedConnection);
+
     connect(hwnet, SIGNAL(chatStringFromMe(const QString&)),
             ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection);
     connect(hwnet, SIGNAL(roomMaster(bool)),
Binary file QTfrontend/res/chat/friend.png has changed
Binary file QTfrontend/res/chat/hedgehog.png has changed
Binary file QTfrontend/res/chat/hedgehog_gray.png has changed
Binary file QTfrontend/res/chat/ignore.png has changed
Binary file QTfrontend/res/chat/lamp.png has changed
Binary file QTfrontend/res/chat/roomadmin.png has changed
Binary file QTfrontend/res/chat/roomadmin_gray.png has changed
Binary file QTfrontend/res/chat/serveradmin.png has changed
Binary file QTfrontend/res/chat/serveradmin_gray.png has changed
Binary file QTfrontend/res/chat_default.png has changed
Binary file QTfrontend/res/chat_default_off.png has changed
Binary file QTfrontend/res/chat_default_on.png has changed
Binary file QTfrontend/res/chat_friend.png has changed
Binary file QTfrontend/res/chat_friend_off.png has changed
Binary file QTfrontend/res/chat_friend_on.png has changed
Binary file QTfrontend/res/chat_ignore.png has changed
Binary file QTfrontend/res/chat_ignore_off.png has changed
Binary file QTfrontend/res/chat_ignore_on.png has changed
--- a/QTfrontend/ui/page/pagenetgame.cpp	Sat Sep 29 19:26:18 2012 +0400
+++ b/QTfrontend/ui/page/pagenetgame.cpp	Mon Oct 01 00:31:38 2012 +0400
@@ -38,7 +38,6 @@
 
     // chatwidget
     pChatWidget = new HWChatWidget(this, m_gameSettings, true);
-    pChatWidget->setShowReady(true); // show status bulbs by default
     pChatWidget->setShowFollow(false); // don't show follow in nicks' context menus
     pChatWidget->setIgnoreListKick(true); // kick ignored players automatically
     pageLayout->addWidget(pChatWidget, 2, 0, 1, 2);
--- a/QTfrontend/ui/widget/chatwidget.cpp	Sat Sep 29 19:26:18 2012 +0400
+++ b/QTfrontend/ui/widget/chatwidget.cpp	Mon Oct 01 00:31:38 2012 +0400
@@ -33,6 +33,7 @@
 #include <QStringList>
 #include <QDateTime>
 #include <QTime>
+#include <QPainter>
 
 #include <QMessageBox>
 
@@ -43,30 +44,18 @@
 
 #include "chatwidget.h"
 
+
 ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick)
 {
-    this->aFriend = isFriend;
-    this->isIgnored = isIgnored;
-}
-
-void ListWidgetNickItem::setFriend(bool isFriend)
-{
-    this->aFriend = isFriend;
+    setData(Friend, isFriend);
+    setData(Ignore, isIgnored);
 }
 
-void ListWidgetNickItem::setIgnored(bool isIgnored)
-{
-    this->isIgnored = isIgnored;
-}
-
-bool ListWidgetNickItem::isFriend()
+void ListWidgetNickItem::setData(StateFlag role, const QVariant &value)
 {
-    return aFriend;
-}
+    QListWidgetItem::setData(role, value);
 
-bool ListWidgetNickItem::ignored()
-{
-    return isIgnored;
+    updateIcon();
 }
 
 bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const
@@ -77,12 +66,12 @@
     ListWidgetNickItem otherNick = const_cast<ListWidgetNickItem &>(dynamic_cast<const ListWidgetNickItem &>(other));
 
     // ignored always down
-    if (isIgnored != otherNick.ignored())
-        return !isIgnored;
+    if (data(Ignore).toBool() != otherNick.data(Ignore).toBool())
+        return !data(Ignore).toBool();
 
     // friends always up
-    if (aFriend != otherNick.isFriend())
-        return aFriend;
+    if (data(Friend).toBool() != otherNick.data(Friend).toBool())
+        return data(Friend).toBool();
 
     QString txt1 = text().toLower();
     QString txt2 = other.text().toLower();
@@ -102,6 +91,82 @@
     return firstIsShorter;
 }
 
+void ListWidgetNickItem::updateIcon()
+{
+    quint32 iconNum = 0;
+
+    QList<bool> flags;
+    flags
+        << data(Ready).toBool()
+        << data(ServerAdmin).toBool()
+        << data(RoomAdmin).toBool()
+        << data(Registered).toBool()
+        << data(Friend).toBool()
+        << data(Ignore).toBool()
+        ;
+
+    for(int i = flags.size() - 1; i >= 0; --i)
+        if(flags[i])
+            iconNum |= 1 << i;
+
+    if(m_icons().contains(iconNum))
+    {
+        setIcon(m_icons().value(iconNum));
+    }
+    else
+    {
+        QPixmap result(24, 16);
+        result.fill(Qt::transparent);
+
+        QPainter painter(&result);
+
+        if(data(Ready).toBool())
+            painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/lamp.png"));
+
+        QString mainIconName(":/res/chat/");
+
+        if(data(RoomAdmin).toBool())
+            mainIconName += "roomadmin";
+        else if(data(ServerAdmin).toBool())
+            mainIconName += "serveradmin";
+        else
+            mainIconName += "hedgehog";
+
+        if(!data(Registered).toBool())
+            mainIconName += "_gray";
+
+        painter.drawPixmap(0, 0, 16, 16, QPixmap(mainIconName + ".png"));
+
+        if(data(Ignore).toBool())
+            painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/ignore.png"));
+        else
+        if(data(Friend).toBool())
+            painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/friend.png"));
+
+        painter.end();
+
+        QIcon icon(result);
+
+        setIcon(icon);
+        m_icons().insert(iconNum, icon);
+    }
+
+    if(data(Ignore).toBool())
+        setForeground(Qt::gray);
+    else
+    if(data(Friend).toBool())
+        setForeground(Qt::green);
+    else
+        setForeground(QBrush(QColor(0xff, 0xcc, 0x00)));
+}
+
+QHash<quint32, QIcon> & ListWidgetNickItem::m_icons()
+{
+    static QHash<quint32, QIcon> iconsCache;
+
+    return iconsCache;
+}
+
 QString * HWChatWidget::s_styleSheet = NULL;
 QStringList * HWChatWidget::s_displayNone = NULL;
 bool HWChatWidget::s_isTimeStamped = true;
@@ -290,6 +355,7 @@
     mainLayout.addWidget(chatText, 0, 0, 2, 1);
 
     chatNicks = new QListWidget(this);
+    chatNicks->setIconSize(QSize(24, 16));
     chatNicks->setMinimumHeight(10);
     chatNicks->setMinimumWidth(10);
     chatNicks->setSortingEnabled(true);
@@ -333,7 +399,6 @@
     chatNicks->insertAction(0, acInfo);
     chatNicks->insertAction(0, acIgnore);
 
-    showReady = false;
     setShowFollow(true);
 
     setAcceptDrops(true);
@@ -460,24 +525,8 @@
     QString nick = nickItem->text();
     ListWidgetNickItem * item = dynamic_cast<ListWidgetNickItem*>(nickItem);
 
-    item->setFriend(friendsList.contains(nick, Qt::CaseInsensitive));
-    item->setIgnored(ignoreList.contains(nick, Qt::CaseInsensitive));
-
-    if(item->ignored())
-    {
-        item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on.png" : ":/res/chat_ignore_off.png") : ":/res/chat_ignore.png"));
-        item->setForeground(Qt::gray);
-    }
-    else if(item->isFriend())
-    {
-        item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on.png" : ":/res/chat_friend_off.png") : ":/res/chat_friend.png"));
-        item->setForeground(Qt::green);
-    }
-    else
-    {
-        item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on.png" : ":/res/chat_default_off.png") : ":/res/chat_default.png"));
-        item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00)));
-    }
+    item->setData(ListWidgetNickItem::Friend, QVariant(friendsList.contains(nick, Qt::CaseInsensitive)));
+    item->setData(ListWidgetNickItem::Ignore, QVariant(ignoreList.contains(nick, Qt::CaseInsensitive)));
 }
 
 void HWChatWidget::updateNickItems()
@@ -891,25 +940,36 @@
     }
 }
 
-void HWChatWidget::setShowReady(bool s)
+void HWChatWidget::setStatus(const QString & nick, ListWidgetNickItem::StateFlag flag, bool status)
 {
-    showReady = s;
+    QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
+
+    if (items.size() == 1)
+    {
+        items[0]->setData(flag, status);
+        updateNickItem(items[0]);
+    }
 }
 
 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady)
 {
-    QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly);
-    if (items.size() != 1)
-    {
-        qWarning("Bug: cannot find user in chat");
-        return;
-    }
+    setStatus(nick, ListWidgetNickItem::Ready, isReady);
+}
+
+void HWChatWidget::setAdminStatus(const QString & nick, bool isAdmin)
+{
+    setStatus(nick, ListWidgetNickItem::ServerAdmin, isAdmin);
+}
 
-    items[0]->setData(Qt::UserRole, isReady); // bulb status
-    updateNickItem(items[0]);
+void HWChatWidget::setRoomMasterStatus(const QString & nick, bool isAdmin)
+{
+    setStatus(nick, ListWidgetNickItem::RoomAdmin, isAdmin);
+}
 
-    // ensure we're still showing the status bulbs
-    showReady = true;
+void HWChatWidget::setRegisteredStatus(const QStringList & nicks, bool isRegistered)
+{
+    foreach(const QString & nick, nicks)
+        setStatus(nick, ListWidgetNickItem::Registered, isRegistered);
 }
 
 void HWChatWidget::adminAccess(bool b)
--- a/QTfrontend/ui/widget/chatwidget.h	Sat Sep 29 19:26:18 2012 +0400
+++ b/QTfrontend/ui/widget/chatwidget.h	Mon Oct 01 00:31:38 2012 +0400
@@ -27,6 +27,7 @@
 #include <QList>
 #include <QPair>
 #include <QRegExp>
+#include <QHash>
 
 #include "SDLInteraction.h"
 
@@ -42,16 +43,22 @@
 class ListWidgetNickItem : public QListWidgetItem
 {
     public:
-        ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored);
-        bool operator<(const QListWidgetItem & other) const;
-        void setFriend(bool isFriend);
-        void setIgnored(bool isIgnored);
-        bool isFriend();
-        bool ignored();
+        enum StateFlag {
+            Ready       = Qt::UserRole,
+            ServerAdmin = Qt::UserRole + 1,
+            RoomAdmin   = Qt::UserRole + 2,
+            Registered  = Qt::UserRole + 3,
+            Friend      = Qt::UserRole + 4,
+            Ignore      = Qt::UserRole + 5
+        };
+
+        ListWidgetNickItem(const QString & nick, bool isFriend, bool isIgnored);
+        void setData(StateFlag role, const QVariant &value);
+        bool operator<(const QListWidgetItem & other) const;        
 
     private:
-        bool aFriend;
-        bool isIgnored;
+        QHash<quint32, QIcon> & m_icons();
+        void updateIcon();
 };
 
 
@@ -73,7 +80,6 @@
         void loadLists(const QString & nick);
         void saveLists(const QString & nick);
         void setIgnoreListKick(bool enabled); ///< automatically kick people on ignore list (if possible)
-        void setShowReady(bool s);
         void setShowFollow(bool enabled);
         QStringList ignoreList, friendsList;
         static const QString & styleSheet();
@@ -113,6 +119,9 @@
         void nickRemoved(const QString& nick);
         void clear();
         void setReadyStatus(const QString & nick, bool isReady);
+        void setAdminStatus(const QString & nick, bool isAdmin);
+        void setRoomMasterStatus(const QString & nick, bool isAdmin);
+        void setRegisteredStatus(const QStringList & nicks, bool isRegistered);
         void adminAccess(bool);
 
     signals:
@@ -143,9 +152,10 @@
         QString m_clickedNick;
         QList<QRegExp> m_highlights; ///< regular expressions used for highlighting
         bool notify;
-        bool showReady;
         bool m_autoKickEnabled;
 
+        void setStatus(const QString & nick, ListWidgetNickItem::StateFlag flag, bool status);
+
     private slots:
         void returnPressed();
         void onBan();