|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com> |
|
4 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 |
|
20 #ifndef _CHAT_WIDGET_INCLUDED |
|
21 #define _CHAT_WIDGET_INCLUDED |
|
22 |
|
23 #include <QWidget> |
|
24 #include <QListWidget> |
|
25 #include <QString> |
|
26 #include <QGridLayout> |
|
27 #include <QRegExp> |
|
28 |
|
29 #include "SDLs.h" |
|
30 |
|
31 class ListWidgetNickItem; |
|
32 class QTextBrowser; |
|
33 class QLineEdit; |
|
34 class QListWidget; |
|
35 class QSettings; |
|
36 class SDLInteraction; |
|
37 |
|
38 // this class is for custom nick sorting |
|
39 class ListWidgetNickItem : public QListWidgetItem |
|
40 { |
|
41 public: |
|
42 ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored); |
|
43 bool operator<(const QListWidgetItem & other) const; |
|
44 void setFriend(bool isFriend); |
|
45 void setIgnored(bool isIgnored); |
|
46 bool isFriend(); |
|
47 bool ignored(); |
|
48 |
|
49 private: |
|
50 bool aFriend; |
|
51 bool isIgnored; |
|
52 }; |
|
53 |
|
54 class HWChatWidget : public QWidget |
|
55 { |
|
56 Q_OBJECT |
|
57 |
|
58 public: |
|
59 HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify); |
|
60 void loadLists(const QString & nick); |
|
61 void saveLists(const QString & nick); |
|
62 void setShowReady(bool s); |
|
63 void setShowFollow(bool enabled); |
|
64 void addLine(const QString & cssClass, QString line); |
|
65 static const char* STYLE; |
|
66 QStringList ignoreList, friendsList; |
|
67 |
|
68 private: |
|
69 void loadList(QStringList & list, const QString & file); |
|
70 void saveList(QStringList & list, const QString & file); |
|
71 void updateNickItem(QListWidgetItem *item); |
|
72 void updateNickItems(); |
|
73 static const QRegExp URLREGEXP; |
|
74 |
|
75 public slots: |
|
76 void onChatString(const QString& str); |
|
77 void onChatString(const QString& nick, const QString& str); |
|
78 void onServerMessage(const QString& str); |
|
79 void nickAdded(const QString& nick, bool notifyNick); |
|
80 void nickRemoved(const QString& nick); |
|
81 void clear(); |
|
82 void setReadyStatus(const QString & nick, bool isReady); |
|
83 void adminAccess(bool); |
|
84 |
|
85 signals: |
|
86 void chatLine(const QString& str); |
|
87 void kick(const QString & str); |
|
88 void ban(const QString & str); |
|
89 void info(const QString & str); |
|
90 void follow(const QString &); |
|
91 void nickCountUpdate(int cnt); |
|
92 |
|
93 private: |
|
94 QGridLayout mainLayout; |
|
95 QTextBrowser* chatText; |
|
96 QStringList chatStrings; |
|
97 QListWidget* chatNicks; |
|
98 QLineEdit* chatEditLine; |
|
99 QAction * acInfo; |
|
100 QAction * acKick; |
|
101 QAction * acBan; |
|
102 QAction * acFollow; |
|
103 QAction * acIgnore; |
|
104 QAction * acFriend; |
|
105 QSettings * gameSettings; |
|
106 SDLInteraction * sdli; |
|
107 Mix_Chunk *sound[4]; |
|
108 bool notify; |
|
109 bool showReady; |
|
110 |
|
111 private slots: |
|
112 void returnPressed(); |
|
113 void onBan(); |
|
114 void onKick(); |
|
115 void onInfo(); |
|
116 void onFollow(); |
|
117 void onIgnore(); |
|
118 void onFriend(); |
|
119 void chatNickDoubleClicked(QListWidgetItem * item); |
|
120 void chatNickSelected(int index); |
|
121 void linkClicked(const QUrl & link); |
|
122 }; |
|
123 |
|
124 #endif // _CHAT_WIDGET_INCLUDED |