# HG changeset patch
# User unc0rr
# Date 1349037098 -14400
# Node ID 8e6b79a020f89483f55fb1e2d1baed48dc95b84d
# Parent eeae1cb6b6bf38a99bd79932d4cbd3aba25b97c8
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)
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/hedgewars.qrc
--- 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 @@
res/css/chat.css
res/css/christmas.css
res/css/easter.css
- res/css/birthday.css
+ res/css/birthday.css
res/hh25x25.png
res/hh25x25grey.png
res/ammopic.png
@@ -102,20 +102,11 @@
res/iconRope.png
res/dice.png
res/Star.png
- res/Flake.png
- res/Egg.png
- res/Confetti.png
+ res/Flake.png
+ res/Egg.png
+ res/Confetti.png
res/file_save.png
res/file_demo.png
- res/chat_default.png
- res/chat_ignore.png
- res/chat_friend.png
- res/chat_default_on.png
- res/chat_ignore_on.png
- res/chat_friend_on.png
- res/chat_default_off.png
- res/chat_ignore_off.png
- res/chat_friend_off.png
res/addfriend.png
res/remfriend.png
res/ignore.png
@@ -143,5 +134,14 @@
res/mapMissing.png
res/mapCustom.png
res/mapMission.png
+ res/chat/friend.png
+ res/chat/ignore.png
+ res/chat/lamp.png
+ res/chat/hedgehog.png
+ res/chat/hedgehog_gray.png
+ res/chat/roomadmin.png
+ res/chat/roomadmin_gray.png
+ res/chat/serveradmin.png
+ res/chat/serveradmin_gray.png
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/hwform.cpp
--- 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)),
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/friend.png
Binary file QTfrontend/res/chat/friend.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/hedgehog.png
Binary file QTfrontend/res/chat/hedgehog.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/hedgehog_gray.png
Binary file QTfrontend/res/chat/hedgehog_gray.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/ignore.png
Binary file QTfrontend/res/chat/ignore.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/lamp.png
Binary file QTfrontend/res/chat/lamp.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/roomadmin.png
Binary file QTfrontend/res/chat/roomadmin.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/roomadmin_gray.png
Binary file QTfrontend/res/chat/roomadmin_gray.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/serveradmin.png
Binary file QTfrontend/res/chat/serveradmin.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat/serveradmin_gray.png
Binary file QTfrontend/res/chat/serveradmin_gray.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_default.png
Binary file QTfrontend/res/chat_default.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_default_off.png
Binary file QTfrontend/res/chat_default_off.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_default_on.png
Binary file QTfrontend/res/chat_default_on.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_friend.png
Binary file QTfrontend/res/chat_friend.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_friend_off.png
Binary file QTfrontend/res/chat_friend_off.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_friend_on.png
Binary file QTfrontend/res/chat_friend_on.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_ignore.png
Binary file QTfrontend/res/chat_ignore.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_ignore_off.png
Binary file QTfrontend/res/chat_ignore_off.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/res/chat_ignore_on.png
Binary file QTfrontend/res/chat_ignore_on.png has changed
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/ui/page/pagenetgame.cpp
--- 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);
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/ui/widget/chatwidget.cpp
--- 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
#include
#include
+#include
#include
@@ -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(dynamic_cast(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 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 & ListWidgetNickItem::m_icons()
+{
+ static QHash 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(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 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 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)
diff -r eeae1cb6b6bf -r 8e6b79a020f8 QTfrontend/ui/widget/chatwidget.h
--- 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
#include
#include
+#include
#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 & 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 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();