Cockatrice 2025-11-30-Development-2.11.0-beta.38
A cross-platform virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
chat_view.h
Go to the documentation of this file.
1
7
8#ifndef CHATVIEW_H
9#define CHATVIEW_H
10
11#include "../../interface/widgets/tabs/tab_supervisor.h"
13
14#include <QAction>
15#include <QColor>
16#include <QTextBrowser>
17#include <QTextCursor>
18#include <QTextFragment>
21
22class AbstractGame;
23class QTextTable;
24class QMouseEvent;
25class UserContextMenu;
26class UserListProxy;
27
29{
30public:
31#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
32 UserMessagePosition() = default; // older qt versions require a default constructor to use in containers
33#endif
34 UserMessagePosition(QTextCursor &cursor);
36 QTextBlock block;
37};
38
39class ChatView : public QTextBrowser
40{
41 Q_OBJECT
42protected:
45
46private:
56 QString lastSender;
57 QString ownUserName;
58 QString mention;
59 QTextCharFormat mentionFormat;
60 QTextCharFormat highlightFormat;
61 QTextCharFormat mentionFormatOtherUser;
62 QTextCharFormat defaultFormat;
63 QStringList highlightedWords;
69 QMap<QString, QVector<UserMessagePosition>> userMessagePositions;
70
71 [[nodiscard]] QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
72 QTextCursor prepareBlock(bool same = false);
73 void appendCardTag(QTextCursor &cursor, const QString &cardName);
74 void appendUrlTag(QTextCursor &cursor, QString url);
75 static QColor getCustomMentionColor();
76 static QColor getCustomHighlightColor();
77 void showSystemPopup(const QString &userName);
78 bool isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message);
79 void checkTag(QTextCursor &cursor, QString &message);
80 void checkMention(QTextCursor &cursor, QString &message, const QString &userName, UserLevelFlags userLevel);
81 void checkWord(QTextCursor &cursor, QString &message);
82 QString extractNextWord(QString &message, QString &rest);
83
84 QColor otherUserColor = QColor(0, 65, 255); // dark blue
85 QColor serverMessageColor = QColor(0x85, 0x15, 0x15);
86 QColor linkColor;
87
88private slots:
89 void openLink(const QUrl &link);
90 void actMessageClicked();
91
92public:
93 ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
94 void retranslateUi();
95 void appendHtml(const QString &html);
96 void virtual appendHtmlServerMessage(const QString &html,
97 bool optionalIsBold = false,
98 QString optionalFontColor = QString());
99 void appendMessage(QString message,
100 RoomMessageTypeFlags messageType = {},
101 const ServerInfo_User &userInfo = {},
102 bool playerBold = false);
103 void clearChat();
104 void redactMessages(const QString &userName, int amount);
105
106protected:
107#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
108 void enterEvent(QEnterEvent *event) override;
109#else
110 void enterEvent(QEvent *event) override;
111#endif
112 void leaveEvent(QEvent *event) override;
113 void mouseMoveEvent(QMouseEvent *event) override;
114 void mousePressEvent(QMouseEvent *event) override;
115 void mouseReleaseEvent(QMouseEvent *event) override;
116signals:
117 void openMessageDialog(const QString &userName, bool focus);
118 void cardNameHovered(QString cardName);
119 void showCardInfoPopup(const QPoint &pos, const CardRef &cardRef);
120 void deleteCardInfoPopup(QString cardName);
121 void addMentionTag(QString mentionTag);
123 void showMentionPopup(const QString &userName);
124};
125
126#endif
Definition abstract_game.h:21
void appendCardTag(QTextCursor &cursor, const QString &cardName)
Definition chat_view.cpp:112
bool showTimestamps
Definition chat_view.h:65
bool evenNumber
Definition chat_view.h:64
HoveredItemType
Definition chat_view.h:48
@ HoveredNothing
Definition chat_view.h:49
@ HoveredUrl
Definition chat_view.h:50
@ HoveredCard
Definition chat_view.h:51
@ HoveredUser
Definition chat_view.h:52
ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent=nullptr)
Definition chat_view.cpp:26
void showSystemPopup(const QString &userName)
Definition chat_view.cpp:459
void checkWord(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:382
void mousePressEvent(QMouseEvent *event) override
Definition chat_view.cpp:573
AbstractGame *const game
Definition chat_view.h:44
QTextFragment getFragmentUnderMouse(const QPoint &pos) const
Definition chat_view.cpp:532
HoveredItemType hoveredItemType
Definition chat_view.h:66
QString ownUserName
Definition chat_view.h:57
QAction * messageClicked
Definition chat_view.h:68
QString mention
Definition chat_view.h:58
void openMessageDialog(const QString &userName, bool focus)
void mouseReleaseEvent(QMouseEvent *event) override
Definition chat_view.cpp:618
void appendMessage(QString message, RoomMessageTypeFlags messageType={}, const ServerInfo_User &userInfo={}, bool playerBold=false)
Definition chat_view.cpp:144
void addMentionTag(QString mentionTag)
static QColor getCustomHighlightColor()
Definition chat_view.cpp:478
void showMentionPopup(const QString &userName)
QTextCursor prepareBlock(bool same=false)
Definition chat_view.cpp:65
TabSupervisor *const tabSupervisor
Definition chat_view.h:43
QString extractNextWord(QString &message, QString &rest)
Definition chat_view.cpp:418
UserContextMenu * userContextMenu
Definition chat_view.h:55
void retranslateUi()
Definition chat_view.cpp:60
static QColor getCustomMentionColor()
Definition chat_view.cpp:467
QTextCharFormat mentionFormat
Definition chat_view.h:59
bool isModeratorSendingGlobal(QFlags< ServerInfo_User::UserLevelFlag > userLevelFlag, QString message)
Definition chat_view.cpp:443
virtual void appendHtmlServerMessage(const QString &html, bool optionalIsBold=false, QString optionalFontColor=QString())
Definition chat_view.cpp:96
void enterEvent(QEnterEvent *event) override
Definition chat_view.cpp:519
void clearChat()
Definition chat_view.cpp:489
QTextCharFormat mentionFormatOtherUser
Definition chat_view.h:61
void mouseMoveEvent(QMouseEvent *event) override
Definition chat_view.cpp:545
QStringList highlightedWords
Definition chat_view.h:63
const UserListProxy *const userListProxy
Definition chat_view.h:54
void deleteCardInfoPopup(QString cardName)
QMap< QString, QVector< UserMessagePosition > > userMessagePositions
Definition chat_view.h:69
void showCardInfoPopup(const QPoint &pos, const CardRef &cardRef)
QColor linkColor
Definition chat_view.h:86
QColor otherUserColor
Definition chat_view.h:84
void redactMessages(const QString &userName, int amount)
Definition chat_view.cpp:496
void cardNameHovered(QString cardName)
QString hoveredContent
Definition chat_view.h:67
void leaveEvent(QEvent *event) override
Definition chat_view.cpp:527
void checkMention(QTextCursor &cursor, QString &message, const QString &userName, UserLevelFlags userLevel)
Definition chat_view.cpp:318
void messageClickedSignal()
void checkTag(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:273
QString lastSender
Definition chat_view.h:56
void openLink(const QUrl &link)
Definition chat_view.cpp:626
QTextCharFormat defaultFormat
Definition chat_view.h:62
void appendUrlTag(QTextCursor &cursor, QString url)
Definition chat_view.cpp:126
void actMessageClicked()
Definition chat_view.cpp:454
QTextCharFormat highlightFormat
Definition chat_view.h:60
void appendHtml(const QString &html)
Definition chat_view.cpp:88
QColor serverMessageColor
Definition chat_view.h:85
Definition tab_supervisor.h:83
Definition user_context_menu.h:26
Definition user_list_proxy.h:19
int relativePosition
Definition chat_view.h:35
UserMessagePosition(QTextCursor &cursor)
Definition chat_view.cpp:20
QTextBlock block
Definition chat_view.h:36
Definition card_ref.h:14
TODO: Document this.