author | unc0rr |
Fri, 25 Jan 2013 22:33:26 +0400 | |
changeset 8436 | b89aacebb9db |
parent 8430 | 5a5c34a75e1a |
child 8451 | 8c7da08df048 |
permissions | -rw-r--r-- |
480 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com> |
6952 | 4 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
480 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
20 |
#include <QDesktopServices> |
1520
f72f538eba05
Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents:
1516
diff
changeset
|
21 |
#include <QTextBrowser> |
1391 | 22 |
#include <QAction> |
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6151
diff
changeset
|
23 |
#include <QFile> |
2845 | 24 |
#include <QTextStream> |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
25 |
#include <QMenu> |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
26 |
#include <QCursor> |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
27 |
#include <QItemSelectionModel> |
6197 | 28 |
#include <QDateTime> |
29 |
#include <QTime> |
|
7723 | 30 |
#include <QListView> |
7737 | 31 |
#include <QModelIndexList> |
32 |
#include <QSortFilterProxyModel> |
|
7740 | 33 |
#include <QMenu> |
461 | 34 |
|
6930 | 35 |
#include "DataManager.h" |
2773
e94f240a8a41
Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents:
2706
diff
changeset
|
36 |
#include "hwconsts.h" |
e94f240a8a41
Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents:
2706
diff
changeset
|
37 |
#include "gameuiconfig.h" |
7737 | 38 |
#include "playerslistmodel.h" |
6165
6fe3e922246e
moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents:
6151
diff
changeset
|
39 |
|
461 | 40 |
#include "chatwidget.h" |
41 |
||
7720 | 42 |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
43 |
QString * HWChatWidget::s_styleSheet = NULL; |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
44 |
QStringList * HWChatWidget::s_displayNone = NULL; |
6197 | 45 |
bool HWChatWidget::s_isTimeStamped = true; |
6229
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
46 |
QString HWChatWidget::s_tsFormat = ":mm:ss"; |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
47 |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
48 |
const QString & HWChatWidget::styleSheet() |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
49 |
{ |
6197 | 50 |
if (s_styleSheet != NULL) |
51 |
return *s_styleSheet; |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
52 |
|
6197 | 53 |
setStyleSheet(); |
54 |
||
55 |
return *s_styleSheet; |
|
56 |
} |
|
57 |
||
58 |
void HWChatWidget::setStyleSheet(const QString & styleSheet) |
|
59 |
{ |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
60 |
QString orgStyleSheet = styleSheet; |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
61 |
QString style = QString(orgStyleSheet); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
62 |
|
6197 | 63 |
// no stylesheet supplied, search for one or use default |
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
64 |
if (orgStyleSheet.isEmpty()) |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
65 |
{ |
6197 | 66 |
// load external stylesheet if there is any |
8049 | 67 |
QFile extFile("physfs://css/chat.css"); |
6197 | 68 |
|
69 |
QFile resFile(":/res/css/chat.css"); |
|
70 |
||
71 |
QFile & file = (extFile.exists()?extFile:resFile); |
|
72 |
||
73 |
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
74 |
{ |
6197 | 75 |
QTextStream in(&file); |
76 |
while (!in.atEnd()) |
|
77 |
{ |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
78 |
style.append(in.readLine()+"\n"); |
6197 | 79 |
} |
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
80 |
orgStyleSheet = style; |
6214 | 81 |
|
82 |
file.close(); |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
83 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
84 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
85 |
|
6197 | 86 |
// let's parse display:none; ... |
87 |
||
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
88 |
// prepare for MAGIC :D |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
89 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
90 |
// matches (multi-)whitespaces (for replacement with simple space) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
91 |
QRegExp ws("\\s+"); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
92 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
93 |
// matches comments (for removal) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
94 |
QRegExp rem("/\\*([^*]|\\*(?!/))*\\*/"); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
95 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
96 |
// strip comments and multi-whitespaces to compress the style-sheet a bit |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
97 |
style = style.remove(rem).replace(ws," "); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
98 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
99 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
100 |
// now let's see what messages the user does not want to be displayed |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
101 |
// by checking for display:none; (since QTextBrowser does not support it) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
102 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
103 |
// MOAR MAGIC :DDD |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
104 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
105 |
// matches definitions lacking display:none; (for removal) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
106 |
QRegExp displayed( |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
107 |
"([^{}]*\\{)(?!([^}]*;)* ?display ?: ?none ?(;[^}]*)?\\})[^}]*\\}"); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
108 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
109 |
// matches all {...} and , (used as seperator for splitting into names) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
110 |
QRegExp split(" *(\\{[^}]*\\}|,) *"); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
111 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
112 |
// matches class names that are referenced without hierachy |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
113 |
QRegExp nohierarchy("^.[^ .]+$"); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
114 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
115 |
QStringList victims = QString(style). |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
116 |
remove(displayed). // remove visible stuff |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
117 |
trimmed(). |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
118 |
split(split). // get a list of the names |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
119 |
filter(nohierarchy). // only direct class names |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
120 |
replaceInStrings(QRegExp("^."),""); // crop . |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
121 |
|
6197 | 122 |
|
123 |
if (victims.contains("timestamp")) |
|
124 |
{ |
|
125 |
s_isTimeStamped = false; |
|
126 |
victims.removeAll("timestamp"); |
|
127 |
} |
|
6229
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
128 |
else |
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
129 |
{ |
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
130 |
s_isTimeStamped = true; |
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
131 |
s_tsFormat = |
6231 | 132 |
((victims.contains("timestamp:hours"))?"":"hh:") + |
133 |
QString("mm") + |
|
134 |
((victims.contains("timestamp:seconds"))?"":":ss"); |
|
6229
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
135 |
} |
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
136 |
|
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
137 |
victims.removeAll("timestamp:hours"); |
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
138 |
victims.removeAll("timestamp:seconds"); |
6197 | 139 |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
140 |
victims.removeDuplicates(); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
141 |
|
6197 | 142 |
QStringList * oldDisplayNone = s_displayNone; |
143 |
QString * oldStyleSheet = s_styleSheet; |
|
144 |
||
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
145 |
s_displayNone = new QStringList(victims); |
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
146 |
s_styleSheet = new QString(orgStyleSheet); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
147 |
|
6197 | 148 |
if (oldDisplayNone != NULL) |
149 |
delete oldDisplayNone; |
|
150 |
||
151 |
if (oldStyleSheet != NULL) |
|
152 |
delete oldStyleSheet; |
|
153 |
||
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
154 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
155 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
156 |
void HWChatWidget::displayError(const QString & message) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
157 |
{ |
6181
c739b503ae31
ugh wth... cleaned FL/IL change notifications up
sheepluva
parents:
6180
diff
changeset
|
158 |
addLine("msg_Error", " !!! " + message); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
159 |
// scroll to the end |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
160 |
chatText->moveCursor(QTextCursor::End); |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
161 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
162 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
163 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
164 |
void HWChatWidget::displayNotice(const QString & message) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
165 |
{ |
6181
c739b503ae31
ugh wth... cleaned FL/IL change notifications up
sheepluva
parents:
6180
diff
changeset
|
166 |
addLine("msg_Notice", " *** " + message); |
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
167 |
// scroll to the end |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
168 |
chatText->moveCursor(QTextCursor::End); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
169 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
170 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
171 |
|
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
172 |
void HWChatWidget::displayWarning(const QString & message) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
173 |
{ |
6181
c739b503ae31
ugh wth... cleaned FL/IL change notifications up
sheepluva
parents:
6180
diff
changeset
|
174 |
addLine("msg_Warning", " *!* " + message); |
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
175 |
// scroll to the end |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
176 |
chatText->moveCursor(QTextCursor::End); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
177 |
} |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
178 |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
179 |
|
8179
a1ffcb559f99
Refactor: get rid of excessive QSettings instances on the same poor hedgewars.ini file
unc0rr
parents:
8049
diff
changeset
|
180 |
HWChatWidget::HWChatWidget(QWidget* parent, bool notify) : |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
181 |
QWidget(parent), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
182 |
mainLayout(this) |
461 | 183 |
{ |
2773
e94f240a8a41
Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents:
2706
diff
changeset
|
184 |
this->gameSettings = gameSettings; |
2775 | 185 |
this->notify = notify; |
6418
f1a3c3aab5b4
hide all context menu options for own nick, except for info
sheepluva
parents:
6240
diff
changeset
|
186 |
|
f1a3c3aab5b4
hide all context menu options for own nick, except for info
sheepluva
parents:
6240
diff
changeset
|
187 |
m_isAdmin = false; |
6929
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
188 |
m_autoKickEnabled = false; |
6418
f1a3c3aab5b4
hide all context menu options for own nick, except for info
sheepluva
parents:
6240
diff
changeset
|
189 |
|
8395
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
190 |
QStringList vpList = |
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
191 |
QStringList() << "Classic" << "Default" << "Mobster" << "Russian"; |
6928
9562ace15141
nemo said I was boring for removing the "hello" randomizer on room join.
sheepluva
parents:
6700
diff
changeset
|
192 |
|
8395
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
193 |
foreach (const QString & vp, vpList) |
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
194 |
{ |
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
195 |
m_helloSounds.append(QString("/Sounds/voices/%1/Hello.ogg").arg(vp)); |
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
196 |
} |
6238 | 197 |
|
8395
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
198 |
m_hilightSound = "/Sounds/beep.ogg"; |
2773
e94f240a8a41
Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents:
2706
diff
changeset
|
199 |
|
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
200 |
mainLayout.setMargin(0); |
461 | 201 |
|
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
202 |
QWidget * leftSideContainer = new QWidget(); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
203 |
leftSideContainer->setObjectName("leftSideContainer"); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
204 |
leftSideContainer->setStyleSheet("#leftSideContainer { border-width: 0px; background-color: #ffcc00; border-radius: 10px;} QTextBrowser, SmartLineEdit { background-color: rgb(13, 5, 68); }"); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
205 |
QVBoxLayout * leftSide = new QVBoxLayout(leftSideContainer); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
206 |
leftSide->setSpacing(3); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
207 |
leftSide->setMargin(3); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
208 |
mainLayout.addWidget(leftSideContainer, 76); |
461 | 209 |
|
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
210 |
// Chat view |
462 | 211 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
212 |
chatText = new QTextBrowser(this); |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
213 |
chatText->document()->setDefaultStyleSheet(styleSheet()); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
214 |
chatText->setMinimumHeight(20); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
215 |
chatText->setMinimumWidth(10); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
216 |
chatText->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
217 |
chatText->setOpenLinks(false); |
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
218 |
chatText->setStyleSheet("QTextBrowser { background-color: rgb(23, 11, 54); border-width: 0px; }"); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
219 |
connect(chatText, SIGNAL(anchorClicked(const QUrl&)), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
220 |
this, SLOT(linkClicked(const QUrl&))); |
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
221 |
leftSide->addWidget(chatText, 1); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
222 |
|
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
223 |
// Input box |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
224 |
|
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
225 |
// Normal: rgb(23, 11, 54) |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
226 |
// Hover: rgb(13, 5, 68) |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
227 |
|
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
228 |
chatEditLine = new SmartLineEdit(); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
229 |
chatEditLine->setMaxLength(300); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
230 |
chatEditLine->setStyleSheet("SmartLineEdit { background-color: rgb(23, 11, 54); padding: 2px 8px; border-width: 0px; border-radius: 7px; } SmartLineEdit:hover, SmartLineEdit:focus { background-color: rgb(13, 5, 68); }"); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
231 |
chatEditLine->setFixedHeight(24); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
232 |
chatEditLine->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
233 |
connect(chatEditLine, SIGNAL(returnPressed()), this, SLOT(returnPressed())); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
234 |
|
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
235 |
leftSide->addWidget(chatEditLine, 0); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
236 |
|
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
237 |
// Nickname list |
462 | 238 |
|
7723 | 239 |
chatNicks = new QListView(this); |
7720 | 240 |
chatNicks->setIconSize(QSize(24, 16)); |
7725 | 241 |
chatNicks->setSelectionMode(QAbstractItemView::SingleSelection); |
242 |
chatNicks->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
243 |
chatNicks->setMinimumHeight(10); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
244 |
chatNicks->setMinimumWidth(10); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
245 |
chatNicks->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
7740 | 246 |
chatNicks->setContextMenuPolicy(Qt::CustomContextMenu); |
247 |
||
7742 | 248 |
connect(chatNicks, SIGNAL(doubleClicked(QModelIndex)), |
249 |
this, SLOT(chatNickDoubleClicked(QModelIndex))); |
|
7740 | 250 |
|
251 |
connect(chatNicks, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(nicksContextMenuRequested(QPoint))); |
|
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
252 |
|
8430
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
253 |
mainLayout.addSpacing(0); |
5a5c34a75e1a
Aesthetic improvements to chat widget. Also fixed the ghosting issue in a few areas by using repaint().
dag10
parents:
8396
diff
changeset
|
254 |
mainLayout.addWidget(chatNicks, 24); |
1391 | 255 |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
256 |
// the userData is used to flag things that are even available when user |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
257 |
// is offline |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
258 |
acInfo = new QAction(QAction::tr("Info"), chatNicks); |
3123 | 259 |
acInfo->setIcon(QIcon(":/res/info.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
260 |
acInfo->setData(QVariant(false)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
261 |
connect(acInfo, SIGNAL(triggered(bool)), this, SLOT(onInfo())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
262 |
acKick = new QAction(QAction::tr("Kick"), chatNicks); |
3123 | 263 |
acKick->setIcon(QIcon(":/res/kick.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
264 |
acKick->setData(QVariant(false)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
265 |
connect(acKick, SIGNAL(triggered(bool)), this, SLOT(onKick())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
266 |
acBan = new QAction(QAction::tr("Ban"), chatNicks); |
3123 | 267 |
acBan->setIcon(QIcon(":/res/ban.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
268 |
acBan->setData(QVariant(true)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
269 |
connect(acBan, SIGNAL(triggered(bool)), this, SLOT(onBan())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
270 |
acFollow = new QAction(QAction::tr("Follow"), chatNicks); |
3123 | 271 |
acFollow->setIcon(QIcon(":/res/follow.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
272 |
acFollow->setData(QVariant(false)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
273 |
connect(acFollow, SIGNAL(triggered(bool)), this, SLOT(onFollow())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
274 |
acIgnore = new QAction(QAction::tr("Ignore"), chatNicks); |
3123 | 275 |
acIgnore->setIcon(QIcon(":/res/ignore.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
276 |
acIgnore->setData(QVariant(true)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
277 |
connect(acIgnore, SIGNAL(triggered(bool)), this, SLOT(onIgnore())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
278 |
acFriend = new QAction(QAction::tr("Add friend"), chatNicks); |
3123 | 279 |
acFriend->setIcon(QIcon(":/res/addfriend.png")); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
280 |
acFriend->setData(QVariant(true)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
281 |
connect(acFriend, SIGNAL(triggered(bool)), this, SLOT(onFriend())); |
2377 | 282 |
|
4892 | 283 |
chatNicks->insertAction(0, acFriend); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
284 |
chatNicks->insertAction(0, acInfo); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
285 |
chatNicks->insertAction(0, acIgnore); |
3697 | 286 |
|
4892 | 287 |
setShowFollow(true); |
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
288 |
|
6197 | 289 |
setAcceptDrops(true); |
7740 | 290 |
|
291 |
m_nicksMenu = new QMenu(this); |
|
292 |
||
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
293 |
clear(); |
4892 | 294 |
} |
295 |
||
8179
a1ffcb559f99
Refactor: get rid of excessive QSettings instances on the same poor hedgewars.ini file
unc0rr
parents:
8049
diff
changeset
|
296 |
void HWChatWidget::setSettings(QSettings * settings) |
a1ffcb559f99
Refactor: get rid of excessive QSettings instances on the same poor hedgewars.ini file
unc0rr
parents:
8049
diff
changeset
|
297 |
{ |
a1ffcb559f99
Refactor: get rid of excessive QSettings instances on the same poor hedgewars.ini file
unc0rr
parents:
8049
diff
changeset
|
298 |
gameSettings = settings; |
a1ffcb559f99
Refactor: get rid of excessive QSettings instances on the same poor hedgewars.ini file
unc0rr
parents:
8049
diff
changeset
|
299 |
} |
6178
affa860f2983
BOOOOooOM <headshot>! removing default stylesheets from c++ code and adding them as text files to the qt resources
sheepluva
parents:
6177
diff
changeset
|
300 |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
301 |
void HWChatWidget::linkClicked(const QUrl & link) |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
302 |
{ |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
303 |
if (link.scheme() == "http") |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
304 |
QDesktopServices::openUrl(link); |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
305 |
if (link.scheme() == "hwnick") |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
306 |
{ |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
307 |
// decode nick |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
308 |
QString nick = QString::fromUtf8(QByteArray::fromBase64(link.encodedQuery())); |
7742 | 309 |
QModelIndexList mil = chatNicks->model()->match(chatNicks->model()->index(0, 0), Qt::DisplayRole, nick); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
310 |
|
7742 | 311 |
bool isOffline = (mil.size() < 1); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
312 |
|
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
313 |
if (isOffline) |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
314 |
{ |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
315 |
m_clickedNick = nick; |
7742 | 316 |
chatNicks->selectionModel()->clearSelection(); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
317 |
} |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
318 |
else |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
319 |
{ |
7742 | 320 |
chatNicks->selectionModel()->select(mil[0], QItemSelectionModel::ClearAndSelect); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
321 |
} |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
322 |
|
7742 | 323 |
nicksContextMenuRequested(chatNicks->mapFromGlobal(QCursor::pos())); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
324 |
} |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
325 |
} |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
326 |
|
4892 | 327 |
void HWChatWidget::setShowFollow(bool enabled) |
328 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
329 |
if (enabled) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
330 |
{ |
4892 | 331 |
if (!(chatNicks->actions().contains(acFollow))) |
332 |
chatNicks->insertAction(acFriend, acFollow); |
|
333 |
} |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
334 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
335 |
{ |
4892 | 336 |
if (chatNicks->actions().contains(acFollow)) |
337 |
chatNicks->removeAction(acFollow); |
|
338 |
} |
|
2845 | 339 |
} |
340 |
||
6929
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
341 |
void HWChatWidget::setIgnoreListKick(bool enabled) |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
342 |
{ |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
343 |
m_autoKickEnabled = enabled; |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
344 |
} |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
345 |
|
6237
a66029015c18
whoopsy, my bad (segfault due to accepting empty lines)
sheepluva
parents:
6233
diff
changeset
|
346 |
|
461 | 347 |
void HWChatWidget::returnPressed() |
348 |
{ |
|
5990
578978418fe5
let frontend send (copypasta) multi-line messages line by line to avoid protocol violation
sheepluva
parents:
5953
diff
changeset
|
349 |
QStringList lines = chatEditLine->text().split('\n'); |
6150
1d98752c1fba
frontend chat input history, use arrow keys UP/DOWN
sheepluva
parents:
6149
diff
changeset
|
350 |
chatEditLine->rememberCurrentText(); |
6197 | 351 |
foreach (const QString &line, lines) |
352 |
{ |
|
6237
a66029015c18
whoopsy, my bad (segfault due to accepting empty lines)
sheepluva
parents:
6233
diff
changeset
|
353 |
// skip empty/whitespace lines |
a66029015c18
whoopsy, my bad (segfault due to accepting empty lines)
sheepluva
parents:
6233
diff
changeset
|
354 |
if (line.trimmed().isEmpty()) |
a66029015c18
whoopsy, my bad (segfault due to accepting empty lines)
sheepluva
parents:
6233
diff
changeset
|
355 |
continue; |
a66029015c18
whoopsy, my bad (segfault due to accepting empty lines)
sheepluva
parents:
6233
diff
changeset
|
356 |
|
6197 | 357 |
if (!parseCommand(line)) |
358 |
emit chatLine(line); |
|
359 |
} |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
360 |
chatEditLine->clear(); |
461 | 361 |
} |
2846 | 362 |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
363 |
// "link" nick, but before that encode it in base64 to make sure it can't |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
364 |
// intefere with html/url syntax the nick is put as querystring as putting |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
365 |
// it as host would convert it to it's lower case variant |
6227
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
366 |
QString HWChatWidget::linkedNick(const QString & nickname) |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
367 |
{ |
6227
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
368 |
if (nickname != m_userNick) |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
369 |
return QString("<a href=\"hwnick://?%1\" class=\"nick\">%2</a>").arg( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
370 |
QString(nickname.toUtf8().toBase64())).arg(Qt::escape(nickname)); |
6233 | 371 |
|
372 |
// unlinked nick (if own one) |
|
373 |
return QString("<span class=\"nick\">%1</span>").arg(Qt::escape(nickname)); |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
374 |
} |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
375 |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
376 |
|
1360 | 377 |
void HWChatWidget::onChatString(const QString& str) |
461 | 378 |
{ |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
379 |
onChatString("", str); |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
380 |
} |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
381 |
|
4899
8163c9aaad0c
automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
sheepluva
parents:
4898
diff
changeset
|
382 |
const QRegExp HWChatWidget::URLREGEXP = QRegExp("(http://)?(www\\.)?(hedgewars\\.org(/[^ ]*)?)"); |
8163c9aaad0c
automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
sheepluva
parents:
4898
diff
changeset
|
383 |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
384 |
void HWChatWidget::onChatString(const QString& nick, const QString& str) |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
385 |
{ |
7741 | 386 |
QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
387 |
if(!playersSortFilterModel) |
|
388 |
return; |
|
389 |
||
390 |
PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
391 |
||
392 |
if(!players) |
|
393 |
return; |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
394 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
395 |
if (!nick.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
396 |
{ |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
397 |
// don't show chat lines that are from ignored nicks |
7741 | 398 |
if (players->isFlagSet(nick, PlayersListModel::Ignore)) |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
399 |
return; |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
400 |
} |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
401 |
|
7741 | 402 |
bool isFriend = (!nick.isEmpty()) && players->isFlagSet(nick, PlayersListModel::Friend); |
403 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
404 |
QString formattedStr = Qt::escape(str.mid(1)); |
4899
8163c9aaad0c
automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
sheepluva
parents:
4898
diff
changeset
|
405 |
// make hedgewars.org urls actual links |
8163c9aaad0c
automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
sheepluva
parents:
4898
diff
changeset
|
406 |
formattedStr = formattedStr.replace(URLREGEXP, "<a href=\"http://\\3\">\\3</a>"); |
2845 | 407 |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
408 |
// link the nick |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
409 |
if(!nick.isEmpty()) |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
410 |
formattedStr.replace("|nick|", linkedNick(nick)); |
2845 | 411 |
|
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
412 |
QString cssClass("msg_UserChat"); |
3697 | 413 |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
414 |
// check first character for color code and set color properly |
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
415 |
char c = str[0].toAscii(); |
6214 | 416 |
switch (c) |
417 |
{ |
|
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
418 |
case 3: |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
419 |
cssClass = (isFriend ? "msg_FriendJoin" : "msg_UserJoin"); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
420 |
break; |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
421 |
case 2: |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
422 |
cssClass = (isFriend ? "msg_FriendAction" : "msg_UserAction"); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
423 |
break; |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
424 |
default: |
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
425 |
if (isFriend) |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
426 |
cssClass = "msg_FriendChat"; |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4892
diff
changeset
|
427 |
} |
2396 | 428 |
|
6214 | 429 |
bool isHL = false; |
430 |
||
6227
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
431 |
if ((c != 3) && (!nick.isEmpty()) && |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
432 |
(nick != m_userNick) && (!m_userNick.isEmpty())) |
6214 | 433 |
{ |
434 |
QString lcStr = str.toLower(); |
|
435 |
||
436 |
foreach (const QRegExp & hl, m_highlights) |
|
437 |
{ |
|
438 |
if (lcStr.contains(hl)) |
|
439 |
{ |
|
440 |
isHL = true; |
|
441 |
break; |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
6193 | 445 |
|
446 |
addLine(cssClass, formattedStr, isHL); |
|
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
447 |
} |
2377 | 448 |
|
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
449 |
void HWChatWidget::addLine(const QString & cssClass, QString line, bool isHighlight) |
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
450 |
{ |
6180
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
451 |
if (s_displayNone->contains(cssClass)) |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
452 |
return; // the css forbids us to display this line |
0992fc5a4ad9
some changes to the css... display:none; works now (e.g. you can use it for user join/leave messages that are not your friends)
sheepluva
parents:
6178
diff
changeset
|
453 |
|
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
454 |
if (chatStrings.size() > 250) |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
455 |
chatStrings.removeFirst(); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
456 |
|
6197 | 457 |
if (s_isTimeStamped) |
458 |
{ |
|
459 |
QString tsMarkUp = "<span class=\"timestamp\">[%1]</span> "; |
|
460 |
QTime now = QDateTime::currentDateTime().time(); |
|
6229
4c834af76c3b
* fix highlighting (i just broke it by not negating a boolean expression)
sheepluva
parents:
6227
diff
changeset
|
461 |
line = tsMarkUp.arg(now.toString(s_tsFormat)) + line; |
6197 | 462 |
} |
463 |
||
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
464 |
line = QString("<span class=\"%1\">%2</span>").arg(cssClass).arg(line); |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
465 |
|
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
466 |
if (isHighlight) |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
467 |
{ |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
468 |
line = QString("<span class=\"highlight\">%1</span>").arg(line); |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
469 |
SDLInteraction::instance().playSoundFile(m_hilightSound); |
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
470 |
} |
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
471 |
|
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5990
diff
changeset
|
472 |
chatStrings.append(line); |
2377 | 473 |
|
6197 | 474 |
chatText->setHtml("<html><body>"+chatStrings.join("<br>")+"</body></html>"); |
1587 | 475 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
476 |
chatText->moveCursor(QTextCursor::End); |
1587 | 477 |
} |
478 |
||
479 |
void HWChatWidget::onServerMessage(const QString& str) |
|
480 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
481 |
if (chatStrings.size() > 250) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
482 |
chatStrings.removeFirst(); |
2377 | 483 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
484 |
chatStrings.append("<hr>" + str + "<hr>"); |
2377 | 485 |
|
6197 | 486 |
chatText->setHtml("<html><body>"+chatStrings.join("<br>")+"</body></html>"); |
1516
bb9fa5809c49
Limit chat history to 250 entries to avoid DoS attack with its use
unc0rr
parents:
1457
diff
changeset
|
487 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
488 |
chatText->moveCursor(QTextCursor::End); |
461 | 489 |
} |
465 | 490 |
|
7741 | 491 |
|
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
492 |
void HWChatWidget::nickAdded(const QString & nick, bool notifyNick) |
465 | 493 |
{ |
7741 | 494 |
QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
495 |
if(!playersSortFilterModel) |
|
496 |
return; |
|
497 |
||
498 |
PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
499 |
||
500 |
if(!players) |
|
501 |
return; |
|
502 |
||
503 |
bool isIgnored = players->isFlagSet(nick, PlayersListModel::Ignore); |
|
6929
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
504 |
|
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
505 |
if (isIgnored && m_isAdmin && m_autoKickEnabled) |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
506 |
{ |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
507 |
emit kick(nick); |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
508 |
return; |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
509 |
} |
c305d31642ac
reimplement auto-kick for ignored players (it was temporarily removed during refactoring)
sheepluva
parents:
6928
diff
changeset
|
510 |
|
6182
d56d18802481
some more chat fixes and changes, I think. hum. what was that? um. aaah, I better go catch some sheep ... er sleep.. um..
sheepluva
parents:
6181
diff
changeset
|
511 |
if ((!isIgnored) && (nick != m_userNick)) // don't auto-complete own name |
6149 | 512 |
chatEditLine->addNickname(nick); |
513 |
||
7740 | 514 |
emit nickCountUpdate(chatNicks->model()->rowCount()); |
5094 | 515 |
|
8395
0b357c57e01c
small cleanup of helloSounds; note: physfs:// prefix will break sound paths since playSoundFile uses physfs for finding files already
sheepluva
parents:
8179
diff
changeset
|
516 |
if (notifyNick && notify && (m_helloSounds.size() > 0)) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
517 |
{ |
6928
9562ace15141
nemo said I was boring for removing the "hello" randomizer on room join.
sheepluva
parents:
6700
diff
changeset
|
518 |
SDLInteraction::instance().playSoundFile( |
9562ace15141
nemo said I was boring for removing the "hello" randomizer on room join.
sheepluva
parents:
6700
diff
changeset
|
519 |
m_helloSounds.at(rand() % m_helloSounds.size())); |
2773
e94f240a8a41
Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents:
2706
diff
changeset
|
520 |
} |
465 | 521 |
} |
522 |
||
523 |
void HWChatWidget::nickRemoved(const QString& nick) |
|
524 |
{ |
|
6147
b4d7d8d62feb
feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
6145
diff
changeset
|
525 |
chatEditLine->removeNickname(nick); |
b4d7d8d62feb
feature-pimpin'-up the chat input line in frontend:
sheepluva
parents:
6145
diff
changeset
|
526 |
|
7741 | 527 |
emit nickCountUpdate(chatNicks->model()->rowCount()); |
465 | 528 |
} |
529 |
||
530 |
void HWChatWidget::clear() |
|
531 |
{ |
|
6151
9fd5b70acb1a
give the room name edit box a history of previous room. however I hate that box from the bottom of my heart, it shall dieeeee... later...
sheepluva
parents:
6150
diff
changeset
|
532 |
chatEditLine->reset(); |
6198
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
533 |
|
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
534 |
// add default commands |
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
535 |
QStringList cmds; |
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
536 |
cmds << "/me" << "/discardStyleSheet" << "/saveStyleSheet"; |
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
537 |
chatEditLine->addCommands(cmds); |
9aa9ed77d63c
unbreak command auto-completion (was broken since r0b92341adb6a - 52 commits ago)
sheepluva
parents:
6197
diff
changeset
|
538 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
539 |
chatText->clear(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
540 |
chatStrings.clear(); |
7723 | 541 |
//chatNicks->clear(); |
6214 | 542 |
|
543 |
// clear and re compile regexp for highlighting |
|
544 |
m_highlights.clear(); |
|
545 |
||
6215 | 546 |
QString hlRegExp("^(.* )?%1[^-a-z0-9_]*( .*)?$"); |
6214 | 547 |
QRegExp whitespace("\\s"); |
548 |
||
7911
98b806c1793d
this should fix the highlighting failz with non-lowercase player names like the one CheezeMonkey ran into.
sheepluva
parents:
7743
diff
changeset
|
549 |
m_highlights.append(QRegExp(hlRegExp.arg(m_userNick.toLower()))); |
6214 | 550 |
|
7911
98b806c1793d
this should fix the highlighting failz with non-lowercase player names like the one CheezeMonkey ran into.
sheepluva
parents:
7743
diff
changeset
|
551 |
QFile file(cfgdir->absolutePath() + "/" + m_userNick.toLower() + "_highlight.txt"); |
6214 | 552 |
|
553 |
if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
|
554 |
{ |
|
555 |
QTextStream in(&file); |
|
556 |
while (!in.atEnd()) |
|
557 |
{ |
|
558 |
QString line = in.readLine(); |
|
559 |
QStringList list = line.split(whitespace); |
|
560 |
foreach (QString word, list) |
|
561 |
{ |
|
562 |
m_highlights.append(QRegExp( |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6418
diff
changeset
|
563 |
hlRegExp.arg(QRegExp::escape(word.toLower())))); |
6214 | 564 |
} |
565 |
} |
|
566 |
||
567 |
if (file.isOpen()) |
|
568 |
file.close(); |
|
569 |
} |
|
570 |
||
7911
98b806c1793d
this should fix the highlighting failz with non-lowercase player names like the one CheezeMonkey ran into.
sheepluva
parents:
7743
diff
changeset
|
571 |
QFile file2(cfgdir->absolutePath() + "/" + m_userNick.toLower() + "_hlregexp.txt"); |
6214 | 572 |
|
573 |
if (file2.exists() && (file2.open(QIODevice::ReadOnly | QIODevice::Text))) |
|
574 |
{ |
|
575 |
QTextStream in(&file2); |
|
576 |
while (!in.atEnd()) |
|
577 |
{ |
|
578 |
m_highlights.append(QRegExp(in.readLine().toLower())); |
|
579 |
} |
|
580 |
||
581 |
if (file2.isOpen()) |
|
582 |
file2.close(); |
|
583 |
} |
|
465 | 584 |
} |
1391 | 585 |
|
586 |
void HWChatWidget::onKick() |
|
587 |
{ |
|
7737 | 588 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
589 |
||
590 |
if(mil.size()) |
|
591 |
emit kick(mil[0].data().toString()); |
|
1391 | 592 |
} |
1405 | 593 |
|
1860 | 594 |
void HWChatWidget::onBan() |
595 |
{ |
|
7737 | 596 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
597 |
||
598 |
if(mil.size()) |
|
599 |
emit ban(mil[0].data().toString()); |
|
1860 | 600 |
} |
601 |
||
1577 | 602 |
void HWChatWidget::onInfo() |
603 |
{ |
|
7737 | 604 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
605 |
||
606 |
if(mil.size()) |
|
607 |
emit info(mil[0].data().toString()); |
|
1577 | 608 |
} |
609 |
||
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
610 |
void HWChatWidget::onFollow() |
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
611 |
{ |
7737 | 612 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
613 |
||
614 |
if(mil.size()) |
|
615 |
emit follow(mil[0].data().toString()); |
|
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
616 |
} |
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
617 |
|
2845 | 618 |
void HWChatWidget::onIgnore() |
619 |
{ |
|
7737 | 620 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
621 |
||
622 |
QString nick; |
|
623 |
if(mil.size()) |
|
624 |
nick = mil[0].data().toString(); |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
625 |
else |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
626 |
nick = m_clickedNick; |
2845 | 627 |
|
7737 | 628 |
QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
629 |
if(!playersSortFilterModel) |
|
630 |
return; |
|
631 |
||
632 |
PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
633 |
||
634 |
if(!players) |
|
635 |
return; |
|
636 |
||
637 |
if(players->isFlagSet(nick, PlayersListModel::Ignore)) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
638 |
{ |
7737 | 639 |
players->setFlag(nick, PlayersListModel::Ignore, false); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
640 |
chatEditLine->addNickname(nick); |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
641 |
displayNotice(tr("%1 has been removed from your ignore list").arg(linkedNick(nick))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
642 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
643 |
else // not on list - add |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
644 |
{ |
4884 | 645 |
// don't consider ignored people friends |
7737 | 646 |
if(players->isFlagSet(nick, PlayersListModel::Friend)) |
4884 | 647 |
emit onFriend(); |
648 |
||
7737 | 649 |
players->setFlag(nick, PlayersListModel::Ignore, true); |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
650 |
chatEditLine->removeNickname(nick); |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
651 |
displayNotice(tr("%1 has been added to your ignore list").arg(linkedNick(nick))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
652 |
} |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
653 |
|
7737 | 654 |
if(mil.size()) |
655 |
chatNicks->scrollTo(chatNicks->selectionModel()->selectedRows()[0]); |
|
2845 | 656 |
} |
657 |
||
658 |
void HWChatWidget::onFriend() |
|
659 |
{ |
|
7737 | 660 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
661 |
||
662 |
QString nick; |
|
663 |
if(mil.size()) |
|
664 |
nick = mil[0].data().toString(); |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
665 |
else |
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
666 |
nick = m_clickedNick; |
2845 | 667 |
|
7737 | 668 |
QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
669 |
if(!playersSortFilterModel) |
|
670 |
return; |
|
671 |
||
672 |
PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
673 |
||
674 |
if(!players) |
|
675 |
return; |
|
676 |
||
677 |
if(players->isFlagSet(nick, PlayersListModel::Friend)) |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
678 |
{ |
7737 | 679 |
players->setFlag(nick, PlayersListModel::Friend, false); |
680 |
chatEditLine->removeNickname(nick); |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
681 |
displayNotice(tr("%1 has been removed from your friends list").arg(linkedNick(nick))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
682 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
683 |
else // not on list - add |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
684 |
{ |
7737 | 685 |
if(players->isFlagSet(nick, PlayersListModel::Ignore)) |
4884 | 686 |
emit onIgnore(); |
687 |
||
7737 | 688 |
players->setFlag(nick, PlayersListModel::Friend, true); |
689 |
chatEditLine->addNickname(nick); |
|
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
690 |
displayNotice(tr("%1 has been added to your friends list").arg(linkedNick(nick))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
691 |
} |
6222
96d10dcd6d84
+ make names in notice messages and leave messages clickable too
sheepluva
parents:
6221
diff
changeset
|
692 |
|
7737 | 693 |
if(mil.size()) |
694 |
chatNicks->scrollTo(chatNicks->selectionModel()->selectedRows()[0]); |
|
2845 | 695 |
} |
7742 | 696 |
|
697 |
void HWChatWidget::chatNickDoubleClicked(const QModelIndex &index) |
|
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
698 |
{ |
7742 | 699 |
m_clickedNick = index.data().toString(); |
700 |
||
4892 | 701 |
QList<QAction *> actions = chatNicks->actions(); |
702 |
actions.first()->activate(QAction::Trigger); |
|
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2428
diff
changeset
|
703 |
} |
7742 | 704 |
|
1860 | 705 |
|
706 |
void HWChatWidget::adminAccess(bool b) |
|
707 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
708 |
chatNicks->removeAction(acKick); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
709 |
chatNicks->removeAction(acBan); |
2377 | 710 |
|
6418
f1a3c3aab5b4
hide all context menu options for own nick, except for info
sheepluva
parents:
6240
diff
changeset
|
711 |
m_isAdmin = b; |
f1a3c3aab5b4
hide all context menu options for own nick, except for info
sheepluva
parents:
6240
diff
changeset
|
712 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
713 |
if(b) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
714 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
715 |
chatNicks->insertAction(0, acKick); |
7537
833a0c34fafc
Room bans. They're more simple, than the global ones: if you ban someone, he is banned by ip in this room for the rest of the room lifetime. Not tested.
unc0rr
parents:
6952
diff
changeset
|
716 |
chatNicks->insertAction(0, acBan); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2847
diff
changeset
|
717 |
} |
1860 | 718 |
} |
6197 | 719 |
|
720 |
void HWChatWidget::dragEnterEvent(QDragEnterEvent * event) |
|
721 |
{ |
|
722 |
if (event->mimeData()->hasUrls()) |
|
723 |
{ |
|
724 |
QList<QUrl> urls = event->mimeData()->urls(); |
|
725 |
if (urls.count() == 1) |
|
6202
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
726 |
{ |
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
727 |
QUrl url = urls[0]; |
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
728 |
|
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
729 |
static QRegExp localFileRegExp("file://.*\\.css$"); |
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
730 |
localFileRegExp.setCaseSensitivity(Qt::CaseInsensitive); |
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
731 |
|
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
732 |
if (url.toString().contains(localFileRegExp)) |
6197 | 733 |
event->acceptProposedAction(); |
6202
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
734 |
} |
6197 | 735 |
} |
736 |
} |
|
737 |
||
738 |
void HWChatWidget::dropEvent(QDropEvent * event) |
|
739 |
{ |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
740 |
const QString path(event->mimeData()->urls()[0].toString()); |
6202
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
741 |
|
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
742 |
QFile file(event->mimeData()->urls()[0].toLocalFile()); |
6197 | 743 |
|
744 |
if (file.exists() && (file.open(QIODevice::ReadOnly | QIODevice::Text))) |
|
745 |
{ |
|
746 |
QString style; |
|
747 |
QTextStream in(&file); |
|
748 |
while (!in.atEnd()) |
|
749 |
{ |
|
750 |
QString line = in.readLine(); |
|
6202
8e3f006b9b1e
this should fix stylesheet importing on windows, but we'll see
sheepluva
parents:
6201
diff
changeset
|
751 |
style.append(line + "\n"); |
6197 | 752 |
} |
753 |
||
754 |
setStyleSheet(style); |
|
755 |
chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
756 |
displayNotice(tr("Stylesheet imported from %1").arg(path)); |
6239 | 757 |
displayNotice(tr("Enter %1 if you want to use the current StyleSheet in future, enter %2 to reset!").arg("/saveStyleSheet").arg("/discardStyleSheet")); |
6197 | 758 |
|
6214 | 759 |
if (file.isOpen()) |
760 |
file.close(); |
|
761 |
||
6197 | 762 |
event->acceptProposedAction(); |
763 |
} |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
764 |
else |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
765 |
displayError(tr("Couldn't read %1").arg(event->mimeData()->urls()[0].toString())); |
6197 | 766 |
} |
767 |
||
768 |
||
769 |
void HWChatWidget::discardStyleSheet() |
|
770 |
{ |
|
771 |
setStyleSheet(); |
|
772 |
chatText->document()->setDefaultStyleSheet(*s_styleSheet); |
|
773 |
displayNotice(tr("StyleSheet discarded")); |
|
774 |
} |
|
775 |
||
776 |
||
777 |
void HWChatWidget::saveStyleSheet() |
|
778 |
{ |
|
8049 | 779 |
QString dest = "physfs://css/chat.css"; |
6197 | 780 |
|
781 |
QFile file(dest); |
|
782 |
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) |
|
783 |
{ |
|
784 |
QTextStream out(&file); |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
785 |
QStringList lines = s_styleSheet->split("\n", QString::KeepEmptyParts); |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
786 |
|
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
787 |
// strip trailing empty lines |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
788 |
while (lines.last().isEmpty()) |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
789 |
lines.takeLast(); |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
790 |
|
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
791 |
foreach (const QString & line, lines) |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
792 |
{ |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
793 |
out << line << endl; |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
794 |
} |
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
795 |
out << endl; |
6197 | 796 |
file.close(); |
797 |
displayNotice(tr("StyleSheet saved to %1").arg(dest)); |
|
798 |
} |
|
799 |
else |
|
6201
d88e7f6cf499
fix of /saveStyleSheet command, error message on stylesheet import fail
sheepluva
parents:
6198
diff
changeset
|
800 |
displayError(tr("Failed to save StyleSheet to %1").arg(dest)); |
6197 | 801 |
} |
802 |
||
803 |
||
804 |
bool HWChatWidget::parseCommand(const QString & line) |
|
805 |
{ |
|
806 |
if (line[0] == '/') |
|
807 |
{ |
|
808 |
QString tline = line.trimmed(); |
|
809 |
if (tline.startsWith("/me")) |
|
810 |
return false; // not a real command |
|
811 |
||
812 |
else if (tline == "/discardStyleSheet") |
|
813 |
discardStyleSheet(); |
|
814 |
else if (tline == "/saveStyleSheet") |
|
815 |
saveStyleSheet(); |
|
816 |
else |
|
8396 | 817 |
emit consoleCommand(tline.mid(1)); |
6197 | 818 |
|
819 |
return true; |
|
820 |
} |
|
821 |
||
822 |
return false; |
|
823 |
} |
|
6227
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
824 |
|
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
825 |
|
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
826 |
void HWChatWidget::setUser(const QString & nickname) |
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
827 |
{ |
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
828 |
m_userNick = nickname; |
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
829 |
nickRemoved(nickname); |
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
830 |
clear(); |
ce60b734fff1
update name autocompletion after nick change (since own nick isn't suggested)
sheepluva
parents:
6222
diff
changeset
|
831 |
} |
7723 | 832 |
|
833 |
||
7725 | 834 |
void HWChatWidget::setUsersModel(QAbstractItemModel *model) |
7723 | 835 |
{ |
7740 | 836 |
chatNicks->selectionModel()->deleteLater(); |
837 |
||
7723 | 838 |
chatNicks->setModel(model); |
839 |
chatNicks->setModelColumn(0); |
|
840 |
} |
|
7740 | 841 |
|
842 |
void HWChatWidget::nicksContextMenuRequested(const QPoint &pos) |
|
843 |
{ |
|
844 |
QModelIndexList mil = chatNicks->selectionModel()->selectedRows(); |
|
845 |
||
846 |
QString nick; |
|
847 |
||
848 |
if(mil.size()) |
|
849 |
nick = mil[0].data().toString(); |
|
850 |
else |
|
851 |
nick = m_clickedNick; |
|
852 |
||
853 |
QSortFilterProxyModel * playersSortFilterModel = qobject_cast<QSortFilterProxyModel *>(chatNicks->model()); |
|
854 |
if(!playersSortFilterModel) |
|
855 |
return; |
|
856 |
||
857 |
PlayersListModel * players = qobject_cast<PlayersListModel *>(playersSortFilterModel->sourceModel()); |
|
858 |
||
859 |
if(!players) |
|
860 |
return; |
|
861 |
||
862 |
bool isSelf = (nick == m_userNick); |
|
863 |
||
864 |
acFollow->setVisible(!isSelf); |
|
865 |
||
866 |
// update context menu labels according to possible action |
|
867 |
if(players->isFlagSet(nick, PlayersListModel::Ignore)) |
|
868 |
{ |
|
869 |
acIgnore->setText(QAction::tr("Unignore")); |
|
870 |
acIgnore->setIcon(QIcon(":/res/unignore.png")); |
|
871 |
} |
|
872 |
else |
|
873 |
{ |
|
874 |
acIgnore->setText(QAction::tr("Ignore")); |
|
875 |
acIgnore->setIcon(QIcon(":/res/ignore.png")); |
|
876 |
acIgnore->setVisible(!isSelf); |
|
877 |
} |
|
878 |
||
879 |
if(players->isFlagSet(nick, PlayersListModel::Friend)) |
|
880 |
{ |
|
881 |
acFriend->setText(QAction::tr("Remove friend")); |
|
882 |
acFriend->setIcon(QIcon(":/res/remfriend.png")); |
|
883 |
} |
|
884 |
else |
|
885 |
{ |
|
886 |
acFriend->setText(QAction::tr("Add friend")); |
|
887 |
acFriend->setIcon(QIcon(":/res/addfriend.png")); |
|
888 |
acFriend->setVisible(!isSelf); |
|
889 |
} |
|
890 |
||
891 |
if (m_isAdmin) |
|
892 |
{ |
|
893 |
acKick->setVisible(!isSelf); |
|
894 |
acBan->setVisible(!isSelf); |
|
895 |
} |
|
896 |
||
897 |
m_nicksMenu->clear(); |
|
898 |
||
899 |
foreach(QAction * action, chatNicks->actions()) |
|
900 |
m_nicksMenu->addAction(action); |
|
901 |
||
902 |
m_nicksMenu->popup(chatNicks->mapToGlobal(pos)); |
|
903 |
} |