31 #include <QScrollBar> |
31 #include <QScrollBar> |
32 #include <QItemSelectionModel> |
32 #include <QItemSelectionModel> |
33 #include <QStringList> |
33 #include <QStringList> |
34 #include <QDateTime> |
34 #include <QDateTime> |
35 #include <QTime> |
35 #include <QTime> |
|
36 #include <QPainter> |
36 |
37 |
37 #include <QMessageBox> |
38 #include <QMessageBox> |
38 |
39 |
39 |
40 |
40 #include "DataManager.h" |
41 #include "DataManager.h" |
41 #include "hwconsts.h" |
42 #include "hwconsts.h" |
42 #include "gameuiconfig.h" |
43 #include "gameuiconfig.h" |
43 |
44 |
44 #include "chatwidget.h" |
45 #include "chatwidget.h" |
45 |
46 |
|
47 |
46 ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick) |
48 ListWidgetNickItem::ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored) : QListWidgetItem(nick) |
47 { |
49 { |
48 this->aFriend = isFriend; |
50 setData(Friend, isFriend); |
49 this->isIgnored = isIgnored; |
51 setData(Ignore, isIgnored); |
50 } |
52 } |
51 |
53 |
52 void ListWidgetNickItem::setFriend(bool isFriend) |
54 void ListWidgetNickItem::setData(StateFlag role, const QVariant &value) |
53 { |
55 { |
54 this->aFriend = isFriend; |
56 QListWidgetItem::setData(role, value); |
55 } |
57 |
56 |
58 updateIcon(); |
57 void ListWidgetNickItem::setIgnored(bool isIgnored) |
|
58 { |
|
59 this->isIgnored = isIgnored; |
|
60 } |
|
61 |
|
62 bool ListWidgetNickItem::isFriend() |
|
63 { |
|
64 return aFriend; |
|
65 } |
|
66 |
|
67 bool ListWidgetNickItem::ignored() |
|
68 { |
|
69 return isIgnored; |
|
70 } |
59 } |
71 |
60 |
72 bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const |
61 bool ListWidgetNickItem::operator< (const QListWidgetItem & other) const |
73 { |
62 { |
74 // case in-sensitive comparison of the associated strings |
63 // case in-sensitive comparison of the associated strings |
75 // chars that are no letters are sorted at the end of the list |
64 // chars that are no letters are sorted at the end of the list |
76 |
65 |
77 ListWidgetNickItem otherNick = const_cast<ListWidgetNickItem &>(dynamic_cast<const ListWidgetNickItem &>(other)); |
66 ListWidgetNickItem otherNick = const_cast<ListWidgetNickItem &>(dynamic_cast<const ListWidgetNickItem &>(other)); |
78 |
67 |
79 // ignored always down |
68 // ignored always down |
80 if (isIgnored != otherNick.ignored()) |
69 if (data(Ignore).toBool() != otherNick.data(Ignore).toBool()) |
81 return !isIgnored; |
70 return !data(Ignore).toBool(); |
82 |
71 |
83 // friends always up |
72 // friends always up |
84 if (aFriend != otherNick.isFriend()) |
73 if (data(Friend).toBool() != otherNick.data(Friend).toBool()) |
85 return aFriend; |
74 return data(Friend).toBool(); |
86 |
75 |
87 QString txt1 = text().toLower(); |
76 QString txt1 = text().toLower(); |
88 QString txt2 = other.text().toLower(); |
77 QString txt2 = other.text().toLower(); |
89 |
78 |
90 bool firstIsShorter = (txt1.size() < txt2.size()); |
79 bool firstIsShorter = (txt1.size() < txt2.size()); |
98 return txt1[i].isLetter(); |
87 return txt1[i].isLetter(); |
99 return (txt1[i] < txt2[i]); |
88 return (txt1[i] < txt2[i]); |
100 } |
89 } |
101 |
90 |
102 return firstIsShorter; |
91 return firstIsShorter; |
|
92 } |
|
93 |
|
94 void ListWidgetNickItem::updateIcon() |
|
95 { |
|
96 quint32 iconNum = 0; |
|
97 |
|
98 QList<bool> flags; |
|
99 flags |
|
100 << data(Ready).toBool() |
|
101 << data(ServerAdmin).toBool() |
|
102 << data(RoomAdmin).toBool() |
|
103 << data(Registered).toBool() |
|
104 << data(Friend).toBool() |
|
105 << data(Ignore).toBool() |
|
106 ; |
|
107 |
|
108 for(int i = flags.size() - 1; i >= 0; --i) |
|
109 if(flags[i]) |
|
110 iconNum |= 1 << i; |
|
111 |
|
112 if(m_icons().contains(iconNum)) |
|
113 { |
|
114 setIcon(m_icons().value(iconNum)); |
|
115 } |
|
116 else |
|
117 { |
|
118 QPixmap result(24, 16); |
|
119 result.fill(Qt::transparent); |
|
120 |
|
121 QPainter painter(&result); |
|
122 |
|
123 if(data(Ready).toBool()) |
|
124 painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/lamp.png")); |
|
125 |
|
126 QString mainIconName(":/res/chat/"); |
|
127 |
|
128 if(data(RoomAdmin).toBool()) |
|
129 mainIconName += "roomadmin"; |
|
130 else if(data(ServerAdmin).toBool()) |
|
131 mainIconName += "serveradmin"; |
|
132 else |
|
133 mainIconName += "hedgehog"; |
|
134 |
|
135 if(!data(Registered).toBool()) |
|
136 mainIconName += "_gray"; |
|
137 |
|
138 painter.drawPixmap(0, 0, 16, 16, QPixmap(mainIconName + ".png")); |
|
139 |
|
140 if(data(Ignore).toBool()) |
|
141 painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/ignore.png")); |
|
142 else |
|
143 if(data(Friend).toBool()) |
|
144 painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/friend.png")); |
|
145 |
|
146 painter.end(); |
|
147 |
|
148 QIcon icon(result); |
|
149 |
|
150 setIcon(icon); |
|
151 m_icons().insert(iconNum, icon); |
|
152 } |
|
153 |
|
154 if(data(Ignore).toBool()) |
|
155 setForeground(Qt::gray); |
|
156 else |
|
157 if(data(Friend).toBool()) |
|
158 setForeground(Qt::green); |
|
159 else |
|
160 setForeground(QBrush(QColor(0xff, 0xcc, 0x00))); |
|
161 } |
|
162 |
|
163 QHash<quint32, QIcon> & ListWidgetNickItem::m_icons() |
|
164 { |
|
165 static QHash<quint32, QIcon> iconsCache; |
|
166 |
|
167 return iconsCache; |
103 } |
168 } |
104 |
169 |
105 QString * HWChatWidget::s_styleSheet = NULL; |
170 QString * HWChatWidget::s_styleSheet = NULL; |
106 QStringList * HWChatWidget::s_displayNone = NULL; |
171 QStringList * HWChatWidget::s_displayNone = NULL; |
107 bool HWChatWidget::s_isTimeStamped = true; |
172 bool HWChatWidget::s_isTimeStamped = true; |
288 connect(chatText, SIGNAL(anchorClicked(const QUrl&)), |
353 connect(chatText, SIGNAL(anchorClicked(const QUrl&)), |
289 this, SLOT(linkClicked(const QUrl&))); |
354 this, SLOT(linkClicked(const QUrl&))); |
290 mainLayout.addWidget(chatText, 0, 0, 2, 1); |
355 mainLayout.addWidget(chatText, 0, 0, 2, 1); |
291 |
356 |
292 chatNicks = new QListWidget(this); |
357 chatNicks = new QListWidget(this); |
|
358 chatNicks->setIconSize(QSize(24, 16)); |
293 chatNicks->setMinimumHeight(10); |
359 chatNicks->setMinimumHeight(10); |
294 chatNicks->setMinimumWidth(10); |
360 chatNicks->setMinimumWidth(10); |
295 chatNicks->setSortingEnabled(true); |
361 chatNicks->setSortingEnabled(true); |
296 chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
362 chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
297 chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu); |
363 chatNicks->setContextMenuPolicy(Qt::ActionsContextMenu); |
458 void HWChatWidget::updateNickItem(QListWidgetItem *nickItem) |
523 void HWChatWidget::updateNickItem(QListWidgetItem *nickItem) |
459 { |
524 { |
460 QString nick = nickItem->text(); |
525 QString nick = nickItem->text(); |
461 ListWidgetNickItem * item = dynamic_cast<ListWidgetNickItem*>(nickItem); |
526 ListWidgetNickItem * item = dynamic_cast<ListWidgetNickItem*>(nickItem); |
462 |
527 |
463 item->setFriend(friendsList.contains(nick, Qt::CaseInsensitive)); |
528 item->setData(ListWidgetNickItem::Friend, QVariant(friendsList.contains(nick, Qt::CaseInsensitive))); |
464 item->setIgnored(ignoreList.contains(nick, Qt::CaseInsensitive)); |
529 item->setData(ListWidgetNickItem::Ignore, QVariant(ignoreList.contains(nick, Qt::CaseInsensitive))); |
465 |
|
466 if(item->ignored()) |
|
467 { |
|
468 item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_ignore_on.png" : ":/res/chat_ignore_off.png") : ":/res/chat_ignore.png")); |
|
469 item->setForeground(Qt::gray); |
|
470 } |
|
471 else if(item->isFriend()) |
|
472 { |
|
473 item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_friend_on.png" : ":/res/chat_friend_off.png") : ":/res/chat_friend.png")); |
|
474 item->setForeground(Qt::green); |
|
475 } |
|
476 else |
|
477 { |
|
478 item->setIcon(QIcon(showReady ? (item->data(Qt::UserRole).toBool() ? ":/res/chat_default_on.png" : ":/res/chat_default_off.png") : ":/res/chat_default.png")); |
|
479 item->setForeground(QBrush(QColor(0xff, 0xcc, 0x00))); |
|
480 } |
|
481 } |
530 } |
482 |
531 |
483 void HWChatWidget::updateNickItems() |
532 void HWChatWidget::updateNickItems() |
484 { |
533 { |
485 for(int i = 0; i < chatNicks->count(); i++) |
534 for(int i = 0; i < chatNicks->count(); i++) |
889 acKick->setVisible(!isSelf); |
938 acKick->setVisible(!isSelf); |
890 acBan->setVisible(!isSelf); |
939 acBan->setVisible(!isSelf); |
891 } |
940 } |
892 } |
941 } |
893 |
942 |
894 void HWChatWidget::setShowReady(bool s) |
943 void HWChatWidget::setStatus(const QString & nick, ListWidgetNickItem::StateFlag flag, bool status) |
895 { |
944 { |
896 showReady = s; |
945 QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly); |
|
946 |
|
947 if (items.size() == 1) |
|
948 { |
|
949 items[0]->setData(flag, status); |
|
950 updateNickItem(items[0]); |
|
951 } |
897 } |
952 } |
898 |
953 |
899 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady) |
954 void HWChatWidget::setReadyStatus(const QString & nick, bool isReady) |
900 { |
955 { |
901 QList<QListWidgetItem *> items = chatNicks->findItems(nick, Qt::MatchExactly); |
956 setStatus(nick, ListWidgetNickItem::Ready, isReady); |
902 if (items.size() != 1) |
957 } |
903 { |
958 |
904 qWarning("Bug: cannot find user in chat"); |
959 void HWChatWidget::setAdminStatus(const QString & nick, bool isAdmin) |
905 return; |
960 { |
906 } |
961 setStatus(nick, ListWidgetNickItem::ServerAdmin, isAdmin); |
907 |
962 } |
908 items[0]->setData(Qt::UserRole, isReady); // bulb status |
963 |
909 updateNickItem(items[0]); |
964 void HWChatWidget::setRoomMasterStatus(const QString & nick, bool isAdmin) |
910 |
965 { |
911 // ensure we're still showing the status bulbs |
966 setStatus(nick, ListWidgetNickItem::RoomAdmin, isAdmin); |
912 showReady = true; |
967 } |
|
968 |
|
969 void HWChatWidget::setRegisteredStatus(const QStringList & nicks, bool isRegistered) |
|
970 { |
|
971 foreach(const QString & nick, nicks) |
|
972 setStatus(nick, ListWidgetNickItem::Registered, isRegistered); |
913 } |
973 } |
914 |
974 |
915 void HWChatWidget::adminAccess(bool b) |
975 void HWChatWidget::adminAccess(bool b) |
916 { |
976 { |
917 chatNicks->removeAction(acKick); |
977 chatNicks->removeAction(acKick); |