QTfrontend/ui/widget/chatwidget.h
author sheepluva
Mon, 24 Oct 2011 20:01:25 +0200
changeset 6200 6a4ace88d85a
parent 6197 4ce7c29799b9
child 6201 d88e7f6cf499
permissions -rw-r--r--
tweak and document abstract page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
480
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     1
/*
1066
1f1b3686a2b0 Update copyright headers a bit
unc0rr
parents: 486
diff changeset
     2
 * Hedgewars, a free turn based strategy game
486
7ea71cd3acd5 - Change proto version to 4
unc0rr
parents: 480
diff changeset
     3
 * Copyright (c) 2007 Igor Ulyanov <iulyanov@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4958
diff changeset
     4
 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
480
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     5
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     8
 * the Free Software Foundation; version 2 of the License
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     9
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    13
 * GNU General Public License for more details.
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    14
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    15
 * You should have received a copy of the GNU General Public License
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    16
 * along with this program; if not, write to the Free Software
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    18
 */
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    19
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    20
#ifndef _CHAT_WIDGET_INCLUDED
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    21
#define _CHAT_WIDGET_INCLUDED
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    22
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    23
#include <QWidget>
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: 1860
diff changeset
    24
#include <QListWidget>
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    25
#include <QString>
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    26
#include <QGridLayout>
6197
sheepluva
parents: 6194
diff changeset
    27
#include <QMutex>
4899
8163c9aaad0c automatically convert hedgewars.org urls to actual links (in order to make support in the lobby/rooms easier
sheepluva
parents: 4897
diff changeset
    28
#include <QRegExp>
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    29
6165
6fe3e922246e moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents: 6147
diff changeset
    30
#include "SDLInteraction.h"
2775
3445ce5e9c79 Only beep in room, load sound in constructor
nemo
parents: 2773
diff changeset
    31
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents: 6060
diff changeset
    32
#include "SmartLineEdit.h"
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents: 6060
diff changeset
    33
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    34
class ListWidgetNickItem;
1520
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    35
class QTextBrowser;
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    36
class QLineEdit;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    37
class QListWidget;
2773
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
    38
class QSettings;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    39
6200
6a4ace88d85a tweak and document abstract page
sheepluva
parents: 6197
diff changeset
    40
/// Class for custom nickname sorting
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    41
class ListWidgetNickItem : public QListWidgetItem
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    42
{
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    43
public:
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    44
  ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored);
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    45
  bool operator<(const QListWidgetItem & other) const;
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    46
  void setFriend(bool isFriend);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    47
  void setIgnored(bool isIgnored);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    48
  bool isFriend();
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    49
  bool ignored();
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    50
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    51
private:
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    52
  bool aFriend;
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    53
  bool isIgnored;
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    54
};
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    55
6185
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    56
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    57
/**
6200
6a4ace88d85a tweak and document abstract page
sheepluva
parents: 6197
diff changeset
    58
 * @brief Chat widget.
6185
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    59
 *
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    60
 * By default uses :res/css/chat.css as style sheet for chat.
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    61
 * See \repo{res/css/chat.css} for a more detailed description.
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    62
 *
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    63
 * @see http://doc.qt.nokia.com/4.5/richtext-html-subset.html#css-properties
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    64
 */
a6aa2d44f390 document css files better
sheepluva
parents: 6182
diff changeset
    65
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    66
class HWChatWidget : public QWidget
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    67
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    68
  Q_OBJECT
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    69
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    70
 public:
6165
6fe3e922246e moving and renaming SDLs.*, making it a singleton; cleaning up class responsibilties wrt SDLInteraction; some comments
sheepluva
parents: 6147
diff changeset
    71
  HWChatWidget(QWidget* parent, QSettings * gameSettings, bool notify);
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    72
  void loadLists(const QString & nick);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    73
  void saveLists(const QString & nick);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    74
  void setShowReady(bool s);
4892
b0610081ee95 nicklist actions:
sheepluva
parents: 4884
diff changeset
    75
  void setShowFollow(bool enabled);
4958
84afe376a3b3 Autokick ignored players from game room on join. Needs testing.
nemo
parents: 4899
diff changeset
    76
  QStringList ignoreList, friendsList;
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: 6165
diff changeset
    77
  static QString & styleSheet();
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: 6165
diff changeset
    78
  void 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: 6165
diff changeset
    79
  void 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: 6165
diff changeset
    80
  void displayWarning(const QString & message);
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    81
6197
sheepluva
parents: 6194
diff changeset
    82
protected:
sheepluva
parents: 6194
diff changeset
    83
    virtual void dragEnterEvent(QDragEnterEvent * event);
sheepluva
parents: 6194
diff changeset
    84
    virtual void dropEvent(QDropEvent * event);
sheepluva
parents: 6194
diff changeset
    85
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    86
private:
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: 6165
diff changeset
    87
  static QString * s_styleSheet;
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: 6165
diff changeset
    88
  static QStringList * s_displayNone;
6197
sheepluva
parents: 6194
diff changeset
    89
  static bool s_isTimeStamped;
sheepluva
parents: 6194
diff changeset
    90
  static QMutex s_styleSheetMutex;
sheepluva
parents: 6194
diff changeset
    91
  static const QRegExp URLREGEXP;
sheepluva
parents: 6194
diff changeset
    92
sheepluva
parents: 6194
diff changeset
    93
  static void setStyleSheet(const QString & 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: 6165
diff changeset
    94
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    95
  void loadList(QStringList & list, const QString & file);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    96
  void saveList(QStringList & list, const QString & file);
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    97
  void updateNickItem(QListWidgetItem *item);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    98
  void updateNickItems();
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: 6180
diff changeset
    99
  void addLine(const QString & cssClass, QString line, bool isHighlight = false);
6197
sheepluva
parents: 6194
diff changeset
   100
  bool parseCommand(const QString & line);
sheepluva
parents: 6194
diff changeset
   101
  void discardStyleSheet();
sheepluva
parents: 6194
diff changeset
   102
  void saveStyleSheet();
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   103
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   104
 public slots:
1360
d3e285281c26 Fix doubling chat message
unc0rr
parents: 1356
diff changeset
   105
  void onChatString(const QString& str);
4897
11598e7aa7e6 make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents: 4892
diff changeset
   106
  void onChatString(const QString& nick, const QString& str);
1587
b8a3d449bed7 Don't escape chat strings which go to engine
unc0rr
parents: 1577
diff changeset
   107
  void onServerMessage(const QString& str);
2777
95a1a69d491c tweak. no chirp on room creation.
nemo
parents: 2776
diff changeset
   108
  void nickAdded(const QString& nick, bool notifyNick);
465
07eca0a2546c chatWidget with nicks ready
displacer
parents: 462
diff changeset
   109
  void nickRemoved(const QString& nick);
07eca0a2546c chatWidget with nicks ready
displacer
parents: 462
diff changeset
   110
  void clear();
1405
ee4b28a1861d Show players ready status in chat nick list
unc0rr
parents: 1391
diff changeset
   111
  void setReadyStatus(const QString & nick, bool isReady);
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   112
  void adminAccess(bool);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   113
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   114
 signals:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   115
  void chatLine(const QString& str);
1391
735f6d43780b Implement kick
unc0rr
parents: 1360
diff changeset
   116
  void kick(const QString & str);
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   117
  void ban(const QString & str);
1577
e3e37c730dc0 - Decrease font size in chat
unc0rr
parents: 1520
diff changeset
   118
  void info(const QString & str);
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: 1860
diff changeset
   119
  void follow(const QString &);
5259
926958e3e87b display player count below and with label, just because it's funny to mess with unC0Rr's code and make him cry :P
sheepluva
parents: 5094
diff changeset
   120
  void nickCountUpdate(int cnt);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   121
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   122
 private:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   123
  QGridLayout mainLayout;
1520
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
   124
  QTextBrowser* chatText;
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
   125
  QStringList chatStrings;
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
   126
  QListWidget* chatNicks;
6147
b4d7d8d62feb feature-pimpin'-up the chat input line in frontend:
sheepluva
parents: 6060
diff changeset
   127
  SmartLineEdit* chatEditLine;
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   128
  QAction * acInfo;
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   129
  QAction * acKick;
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   130
  QAction * acBan;
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: 1860
diff changeset
   131
  QAction * acFollow;
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   132
  QAction * acIgnore;
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   133
  QAction * acFriend;
2773
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
   134
  QSettings * gameSettings;
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: 6180
diff changeset
   135
  QString m_helloSound;
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: 6180
diff changeset
   136
  QString 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: 6180
diff changeset
   137
  QString m_userNick;
6194
32b7e0ece99a improve and cash hilight regexp
sheepluva
parents: 6185
diff changeset
   138
  QRegExp m_hlRegExp; ///< regular expression used for highlighting messages
2775
3445ce5e9c79 Only beep in room, load sound in constructor
nemo
parents: 2773
diff changeset
   139
  bool notify;
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   140
  bool showReady;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   141
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   142
 private slots:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   143
  void returnPressed();
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   144
  void onBan();
1391
735f6d43780b Implement kick
unc0rr
parents: 1360
diff changeset
   145
  void onKick();
1577
e3e37c730dc0 - Decrease font size in chat
unc0rr
parents: 1520
diff changeset
   146
  void onInfo();
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: 1860
diff changeset
   147
  void onFollow();
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   148
  void onIgnore();
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   149
  void onFriend();
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: 1860
diff changeset
   150
  void chatNickDoubleClicked(QListWidgetItem * item);
2847
cde320fd3122 Frontend:
smxx
parents: 2846
diff changeset
   151
  void chatNickSelected(int index);
4897
11598e7aa7e6 make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents: 4892
diff changeset
   152
  void linkClicked(const QUrl & link);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   153
};
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   154
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   155
#endif // _CHAT_WIDGET_INCLUDED