Cockatrice 2026-03-05-Development-2.11.0-beta.54
A 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 UserMessagePosition(QTextCursor &cursor);
33 QTextBlock block;
34};
35
36class ChatView : public QTextBrowser
37{
38 Q_OBJECT
39protected:
42
43private:
53 QString lastSender;
54 QString ownUserName;
55 QString mention;
56 QTextCharFormat mentionFormat;
57 QTextCharFormat highlightFormat;
58 QTextCharFormat mentionFormatOtherUser;
59 QTextCharFormat defaultFormat;
60 QStringList highlightedWords;
66 QMap<QString, QVector<UserMessagePosition>> userMessagePositions;
67
68 [[nodiscard]] QTextFragment getFragmentUnderMouse(const QPoint &pos) const;
69 QTextCursor prepareBlock(bool same = false);
70 void appendCardTag(QTextCursor &cursor, const QString &cardName);
71 void appendUrlTag(QTextCursor &cursor, QString url);
72 static QColor getCustomMentionColor();
73 static QColor getCustomHighlightColor();
74 void showSystemPopup(const QString &userName);
75 bool isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message);
76 void checkTag(QTextCursor &cursor, QString &message);
77 void checkMention(QTextCursor &cursor, QString &message, const QString &userName, UserLevelFlags userLevel);
78 void checkWord(QTextCursor &cursor, QString &message);
79 QString extractNextWord(QString &message, QString &rest);
80
81 QColor otherUserColor = QColor(0, 65, 255); // dark blue
82 QColor serverMessageColor = QColor(0x85, 0x15, 0x15);
83 QColor linkColor;
84
85private slots:
86 void openLink(const QUrl &link);
87 void actMessageClicked();
89 void refreshBlockColors();
90
91public:
92 ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
93 void retranslateUi();
94 void appendHtml(const QString &html);
95 void virtual appendHtmlServerMessage(const QString &html,
96 bool optionalIsBold = false,
97 QString optionalFontColor = QString());
98 void appendMessage(QString message,
99 RoomMessageTypeFlags messageType = {},
100 const ServerInfo_User &userInfo = {},
101 bool playerBold = false);
102 void clearChat();
103 void redactMessages(const QString &userName, int amount);
104
105protected:
106#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
107 void enterEvent(QEnterEvent *event) override;
108#else
109 void enterEvent(QEvent *event) override;
110#endif
111 void leaveEvent(QEvent *event) override;
112 void mouseMoveEvent(QMouseEvent *event) override;
113 void mousePressEvent(QMouseEvent *event) override;
114 void mouseReleaseEvent(QMouseEvent *event) override;
115signals:
116 void openMessageDialog(const QString &userName, bool focus);
117 void cardNameHovered(QString cardName);
118 void showCardInfoPopup(const QPoint &pos, const CardRef &cardRef);
119 void deleteCardInfoPopup(QString cardName);
120 void addMentionTag(QString mentionTag);
122 void showMentionPopup(const QString &userName);
123};
124
125#endif
Definition abstract_game.h:21
void appendCardTag(QTextCursor &cursor, const QString &cardName)
Definition chat_view.cpp:161
bool showTimestamps
Definition chat_view.h:62
bool evenNumber
Definition chat_view.h:61
HoveredItemType
Definition chat_view.h:45
@ HoveredNothing
Definition chat_view.h:46
@ HoveredUrl
Definition chat_view.h:47
@ HoveredCard
Definition chat_view.h:48
@ HoveredUser
Definition chat_view.h:49
ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent=nullptr)
Definition chat_view.cpp:26
void showSystemPopup(const QString &userName)
Definition chat_view.cpp:504
void checkWord(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:427
void mousePressEvent(QMouseEvent *event) override
Definition chat_view.cpp:618
AbstractGame *const game
Definition chat_view.h:41
QTextFragment getFragmentUnderMouse(const QPoint &pos) const
Definition chat_view.cpp:577
HoveredItemType hoveredItemType
Definition chat_view.h:63
QString ownUserName
Definition chat_view.h:54
QAction * messageClicked
Definition chat_view.h:65
QString mention
Definition chat_view.h:55
void openMessageDialog(const QString &userName, bool focus)
void mouseReleaseEvent(QMouseEvent *event) override
Definition chat_view.cpp:663
void appendMessage(QString message, RoomMessageTypeFlags messageType={}, const ServerInfo_User &userInfo={}, bool playerBold=false)
Definition chat_view.cpp:193
void addMentionTag(QString mentionTag)
static QColor getCustomHighlightColor()
Definition chat_view.cpp:523
void showMentionPopup(const QString &userName)
QTextCursor prepareBlock(bool same=false)
Definition chat_view.cpp:106
TabSupervisor *const tabSupervisor
Definition chat_view.h:40
QString extractNextWord(QString &message, QString &rest)
Definition chat_view.cpp:463
UserContextMenu * userContextMenu
Definition chat_view.h:52
void retranslateUi()
Definition chat_view.cpp:101
static QColor getCustomMentionColor()
Definition chat_view.cpp:512
QTextCharFormat mentionFormat
Definition chat_view.h:56
bool isModeratorSendingGlobal(QFlags< ServerInfo_User::UserLevelFlag > userLevelFlag, QString message)
Definition chat_view.cpp:488
virtual void appendHtmlServerMessage(const QString &html, bool optionalIsBold=false, QString optionalFontColor=QString())
Definition chat_view.cpp:145
void enterEvent(QEnterEvent *event) override
Definition chat_view.cpp:564
void clearChat()
Definition chat_view.cpp:534
QTextCharFormat mentionFormatOtherUser
Definition chat_view.h:58
void adjustColorsToPalette()
Definition chat_view.cpp:54
void mouseMoveEvent(QMouseEvent *event) override
Definition chat_view.cpp:590
QStringList highlightedWords
Definition chat_view.h:60
const UserListProxy *const userListProxy
Definition chat_view.h:51
void deleteCardInfoPopup(QString cardName)
QMap< QString, QVector< UserMessagePosition > > userMessagePositions
Definition chat_view.h:66
void showCardInfoPopup(const QPoint &pos, const CardRef &cardRef)
QColor linkColor
Definition chat_view.h:83
QColor otherUserColor
Definition chat_view.h:81
void redactMessages(const QString &userName, int amount)
Definition chat_view.cpp:541
void cardNameHovered(QString cardName)
QString hoveredContent
Definition chat_view.h:64
void leaveEvent(QEvent *event) override
Definition chat_view.cpp:572
void checkMention(QTextCursor &cursor, QString &message, const QString &userName, UserLevelFlags userLevel)
Definition chat_view.cpp:363
void messageClickedSignal()
void checkTag(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:318
void refreshBlockColors()
Definition chat_view.cpp:69
QString lastSender
Definition chat_view.h:53
void openLink(const QUrl &link)
Definition chat_view.cpp:671
QTextCharFormat defaultFormat
Definition chat_view.h:59
void appendUrlTag(QTextCursor &cursor, QString url)
Definition chat_view.cpp:175
void actMessageClicked()
Definition chat_view.cpp:499
QTextCharFormat highlightFormat
Definition chat_view.h:57
void appendHtml(const QString &html)
Definition chat_view.cpp:137
QColor serverMessageColor
Definition chat_view.h:82
Definition tab_supervisor.h:83
Definition user_context_menu.h:26
Definition user_list_proxy.h:19
int relativePosition
Definition chat_view.h:32
UserMessagePosition(QTextCursor &cursor)
Definition chat_view.cpp:20
QTextBlock block
Definition chat_view.h:33
static constexpr int amount
Definition deck_hash_performance_test.cpp:5
Definition card_ref.h:14
TODO: Document this.