QTfrontend/chatwidget.h
author sheepluva
Sun, 30 Jan 2011 06:56:12 +0100
changeset 4884 b2006a9f0fbc
parent 4876 813ef4e8e385
child 4892 b0610081ee95
permissions -rw-r--r--
nicklists: * friends go to the top * ignored people go to the bottom * first time each of those happens it automatically scrolls there (to avoid "where did it go?!"-moments) friendslist/ignorelist: adding a nick to one will remove it from other
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>
480
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     4
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     8
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    12
 * GNU General Public License for more details.
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    13
 *
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    14
 * You should have received a copy of the GNU General Public License
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    15
 * along with this program; if not, write to the Free Software
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    17
 */
09434d6c3865 GPL headers added
displacer
parents: 465
diff changeset
    18
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    19
#ifndef _CHAT_WIDGET_INCLUDED
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    20
#define _CHAT_WIDGET_INCLUDED
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    21
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    22
#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
    23
#include <QListWidget>
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    24
#include <QString>
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    25
#include <QGridLayout>
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    26
2775
3445ce5e9c79 Only beep in room, load sound in constructor
nemo
parents: 2773
diff changeset
    27
#include "SDLs.h"
3445ce5e9c79 Only beep in room, load sound in constructor
nemo
parents: 2773
diff changeset
    28
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    29
class ListWidgetNickItem;
1520
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    30
class QTextBrowser;
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    31
class QLineEdit;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    32
class QListWidget;
2773
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
    33
class QSettings;
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
    34
class SDLInteraction;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    35
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    36
// this class is for custom nick sorting
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    37
class ListWidgetNickItem : public QListWidgetItem
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    38
{
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    39
public:
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    40
  ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored);
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    41
  bool operator<(const QListWidgetItem & other) const;
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    42
  void setFriend(bool isFriend);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    43
  void setIgnored(bool isIgnored);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    44
  bool isFriend();
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    45
  bool ignored();
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    46
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    47
private:
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    48
  bool aFriend;
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    49
  bool isIgnored;
4876
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    50
};
813ef4e8e385 sort nick lists case-insensitive
sheepluva
parents: 2847
diff changeset
    51
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    52
class HWChatWidget : public QWidget
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    53
{
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    54
  Q_OBJECT
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    55
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    56
 public:
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    57
  HWChatWidget(QWidget* parent, QSettings * gameSettings, SDLInteraction * sdli, bool notify);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    58
  void loadLists(const QString & nick);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    59
  void saveLists(const QString & nick);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    60
  void setShowReady(bool s);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    61
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    62
private:
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    63
  void loadList(QStringList & list, const QString & file);
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    64
  void saveList(QStringList & list, const QString & file);
4884
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    65
  void updateNickItem(QListWidgetItem *item);
b2006a9f0fbc nicklists:
sheepluva
parents: 4876
diff changeset
    66
  void updateNickItems();
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    67
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    68
 public slots:
1360
d3e285281c26 Fix doubling chat message
unc0rr
parents: 1356
diff changeset
    69
  void onChatString(const QString& str);
1587
b8a3d449bed7 Don't escape chat strings which go to engine
unc0rr
parents: 1577
diff changeset
    70
  void onServerMessage(const QString& str);
2777
95a1a69d491c tweak. no chirp on room creation.
nemo
parents: 2776
diff changeset
    71
  void nickAdded(const QString& nick, bool notifyNick);
465
07eca0a2546c chatWidget with nicks ready
displacer
parents: 462
diff changeset
    72
  void nickRemoved(const QString& nick);
07eca0a2546c chatWidget with nicks ready
displacer
parents: 462
diff changeset
    73
  void clear();
1405
ee4b28a1861d Show players ready status in chat nick list
unc0rr
parents: 1391
diff changeset
    74
  void setReadyStatus(const QString & nick, bool isReady);
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
    75
  void adminAccess(bool);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    76
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    77
 signals:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    78
  void chatLine(const QString& str);
1391
735f6d43780b Implement kick
unc0rr
parents: 1360
diff changeset
    79
  void kick(const QString & str);
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
    80
  void ban(const QString & str);
1577
e3e37c730dc0 - Decrease font size in chat
unc0rr
parents: 1520
diff changeset
    81
  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
    82
  void follow(const QString &);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    83
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    84
 private:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    85
  QGridLayout mainLayout;
1520
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    86
  QTextBrowser* chatText;
f72f538eba05 Refactor chat widget to use QTextBrower instead of QListWidget:
unc0rr
parents: 1405
diff changeset
    87
  QStringList chatStrings;
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    88
  QStringList ignoreList, friendsList;
462
91baab07b79a resizing and grid problems
displacer
parents: 461
diff changeset
    89
  QListWidget* chatNicks;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
    90
  QLineEdit* chatEditLine;
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
    91
  QAction * acInfo;
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
    92
  QAction * acKick;
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
    93
  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
    94
  QAction * acFollow;
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    95
  QAction * acIgnore;
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
    96
  QAction * acFriend;
2773
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
    97
  QSettings * gameSettings;
e94f240a8a41 Have game beep when someone joins lobby/room. Controlled by Sound option
nemo
parents: 2706
diff changeset
    98
  SDLInteraction * sdli;
2779
e1ae0019d43f Suggestion from Tiy. Use a random hi. Could maybe be shorter sounds, using the 4 shortest voicepacks already
nemo
parents: 2777
diff changeset
    99
  Mix_Chunk *sound[4];
2775
3445ce5e9c79 Only beep in room, load sound in constructor
nemo
parents: 2773
diff changeset
   100
  bool notify;
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   101
  bool showReady;
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   102
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   103
 private slots:
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   104
  void returnPressed();
1860
ce140b2b928a Some work on players lists context menus
unc0rr
parents: 1587
diff changeset
   105
  void onBan();
1391
735f6d43780b Implement kick
unc0rr
parents: 1360
diff changeset
   106
  void onKick();
1577
e3e37c730dc0 - Decrease font size in chat
unc0rr
parents: 1520
diff changeset
   107
  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
   108
  void onFollow();
2845
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   109
  void onIgnore();
19db164dd20d Frontend:
smxx
parents: 2779
diff changeset
   110
  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
   111
  void chatNickDoubleClicked(QListWidgetItem * item);
2847
cde320fd3122 Frontend:
smxx
parents: 2846
diff changeset
   112
  void chatNickSelected(int index);
461
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   113
};
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   114
105af110b0e6 chatWidget with layout
displacer
parents:
diff changeset
   115
#endif // _CHAT_WIDGET_INCLUDED