QTfrontend/ui/widget/chatwidget.h
changeset 6616 f77bb02b669f
parent 6418 f1a3c3aab5b4
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    39 class QSettings;
    39 class QSettings;
    40 
    40 
    41 /// Class for custom nickname sorting
    41 /// Class for custom nickname sorting
    42 class ListWidgetNickItem : public QListWidgetItem
    42 class ListWidgetNickItem : public QListWidgetItem
    43 {
    43 {
    44 public:
    44     public:
    45   ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored);
    45         ListWidgetNickItem(const QString& nick, bool isFriend, bool isIgnored);
    46   bool operator<(const QListWidgetItem & other) const;
    46         bool operator<(const QListWidgetItem & other) const;
    47   void setFriend(bool isFriend);
    47         void setFriend(bool isFriend);
    48   void setIgnored(bool isIgnored);
    48         void setIgnored(bool isIgnored);
    49   bool isFriend();
    49         bool isFriend();
    50   bool ignored();
    50         bool ignored();
    51 
    51 
    52 private:
    52     private:
    53   bool aFriend;
    53         bool aFriend;
    54   bool isIgnored;
    54         bool isIgnored;
    55 };
    55 };
    56 
    56 
    57 
    57 
    58 /**
    58 /**
    59  * @brief Chat widget.
    59  * @brief Chat widget.
    64  * @see http://doc.qt.nokia.com/4.5/richtext-html-subset.html#css-properties
    64  * @see http://doc.qt.nokia.com/4.5/richtext-html-subset.html#css-properties
    65  */
    65  */
    66 
    66 
    67 class HWChatWidget : public QWidget
    67 class HWChatWidget : public QWidget
    68 {
    68 {
    69   Q_OBJECT
    69         Q_OBJECT
    70 
    70 
    71  public:
    71     public:
    72   HWChatWidget(QWidget* parent, QSettings * gameSettings, bool notify);
    72         HWChatWidget(QWidget* parent, QSettings * gameSettings, bool notify);
    73   void loadLists(const QString & nick);
    73         void loadLists(const QString & nick);
    74   void saveLists(const QString & nick);
    74         void saveLists(const QString & nick);
    75   void setShowReady(bool s);
    75         void setShowReady(bool s);
    76   void setShowFollow(bool enabled);
    76         void setShowFollow(bool enabled);
    77   QStringList ignoreList, friendsList;
    77         QStringList ignoreList, friendsList;
    78   static const QString & styleSheet();
    78         static const QString & styleSheet();
    79   void displayError(const QString & message);
    79         void displayError(const QString & message);
    80   void displayNotice(const QString & message);
    80         void displayNotice(const QString & message);
    81   void displayWarning(const QString & message);
    81         void displayWarning(const QString & message);
    82   void setUser(const QString & nickname);
    82         void setUser(const QString & nickname);
    83 
    83 
    84 protected:
    84     protected:
    85     virtual void dragEnterEvent(QDragEnterEvent * event);
    85         virtual void dragEnterEvent(QDragEnterEvent * event);
    86     virtual void dropEvent(QDropEvent * event);
    86         virtual void dropEvent(QDropEvent * event);
    87 
    87 
    88 private:
    88     private:
    89   static QString * s_styleSheet;
    89         static QString * s_styleSheet;
    90   static QStringList * s_displayNone;
    90         static QStringList * s_displayNone;
    91   static bool s_isTimeStamped;
    91         static bool s_isTimeStamped;
    92   static QString s_tsFormat;
    92         static QString s_tsFormat;
    93   static const QRegExp URLREGEXP;
    93         static const QRegExp URLREGEXP;
    94 
    94 
    95   static void setStyleSheet(const QString & styleSheet = "");
    95         static void setStyleSheet(const QString & styleSheet = "");
    96 
    96 
    97   void loadList(QStringList & list, const QString & file);
    97         void loadList(QStringList & list, const QString & file);
    98   void saveList(QStringList & list, const QString & file);
    98         void saveList(QStringList & list, const QString & file);
    99   void updateNickItem(QListWidgetItem *item);
    99         void updateNickItem(QListWidgetItem *item);
   100   void updateNickItems();
   100         void updateNickItems();
   101   void addLine(const QString & cssClass, QString line, bool isHighlight = false);
   101         void addLine(const QString & cssClass, QString line, bool isHighlight = false);
   102   bool parseCommand(const QString & line);
   102         bool parseCommand(const QString & line);
   103   void discardStyleSheet();
   103         void discardStyleSheet();
   104   void saveStyleSheet();
   104         void saveStyleSheet();
   105   QString linkedNick(const QString & nickname);
   105         QString linkedNick(const QString & nickname);
   106 
   106 
   107  public slots:
   107     public slots:
   108   void onChatString(const QString& str);
   108         void onChatString(const QString& str);
   109   void onChatString(const QString& nick, const QString& str);
   109         void onChatString(const QString& nick, const QString& str);
   110   void onServerMessage(const QString& str);
   110         void onServerMessage(const QString& str);
   111   void nickAdded(const QString& nick, bool notifyNick);
   111         void nickAdded(const QString& nick, bool notifyNick);
   112   void nickRemoved(const QString& nick);
   112         void nickRemoved(const QString& nick);
   113   void clear();
   113         void clear();
   114   void setReadyStatus(const QString & nick, bool isReady);
   114         void setReadyStatus(const QString & nick, bool isReady);
   115   void adminAccess(bool);
   115         void adminAccess(bool);
   116 
   116 
   117  signals:
   117     signals:
   118   void chatLine(const QString& str);
   118         void chatLine(const QString& str);
   119   void kick(const QString & str);
   119         void kick(const QString & str);
   120   void ban(const QString & str);
   120         void ban(const QString & str);
   121   void info(const QString & str);
   121         void info(const QString & str);
   122   void follow(const QString &);
   122         void follow(const QString &);
   123   void nickCountUpdate(int cnt);
   123         void nickCountUpdate(int cnt);
   124 
   124 
   125  private:
   125     private:
   126   bool m_isAdmin;
   126         bool m_isAdmin;
   127   QGridLayout mainLayout;
   127         QGridLayout mainLayout;
   128   QTextBrowser* chatText;
   128         QTextBrowser* chatText;
   129   QStringList chatStrings;
   129         QStringList chatStrings;
   130   QListWidget* chatNicks;
   130         QListWidget* chatNicks;
   131   SmartLineEdit* chatEditLine;
   131         SmartLineEdit* chatEditLine;
   132   QAction * acInfo;
   132         QAction * acInfo;
   133   QAction * acKick;
   133         QAction * acKick;
   134   QAction * acBan;
   134         QAction * acBan;
   135   QAction * acFollow;
   135         QAction * acFollow;
   136   QAction * acIgnore;
   136         QAction * acIgnore;
   137   QAction * acFriend;
   137         QAction * acFriend;
   138   QSettings * gameSettings;
   138         QSettings * gameSettings;
   139   QString m_helloSound;
   139         QString m_helloSound;
   140   QString m_hilightSound;
   140         QString m_hilightSound;
   141   QString m_userNick;
   141         QString m_userNick;
   142   QString m_clickedNick;
   142         QString m_clickedNick;
   143   QList<QRegExp> m_highlights; ///< regular expressions used for highlighting
   143         QList<QRegExp> m_highlights; ///< regular expressions used for highlighting
   144   bool notify;
   144         bool notify;
   145   bool showReady;
   145         bool showReady;
   146 
   146 
   147  private slots:
   147     private slots:
   148   void returnPressed();
   148         void returnPressed();
   149   void onBan();
   149         void onBan();
   150   void onKick();
   150         void onKick();
   151   void onInfo();
   151         void onInfo();
   152   void onFollow();
   152         void onFollow();
   153   void onIgnore();
   153         void onIgnore();
   154   void onFriend();
   154         void onFriend();
   155   void chatNickDoubleClicked(QListWidgetItem * item);
   155         void chatNickDoubleClicked(QListWidgetItem * item);
   156   void chatNickSelected(int index);
   156         void chatNickSelected(int index);
   157   void linkClicked(const QUrl & link);
   157         void linkClicked(const QUrl & link);
   158 };
   158 };
   159 
   159 
   160 #endif // _CHAT_WIDGET_INCLUDED
   160 #endif // _CHAT_WIDGET_INCLUDED