Cockatrice 2026-01-14-Development-2.11.0-beta.46
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 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();
88
89public:
90 ChatView(TabSupervisor *_tabSupervisor, AbstractGame *_game, bool _showTimestamps, QWidget *parent = nullptr);
91 void retranslateUi();
92 void appendHtml(const QString &html);
93 void virtual appendHtmlServerMessage(const QString &html,
94 bool optionalIsBold = false,
95 QString optionalFontColor = QString());
96 void appendMessage(QString message,
97 RoomMessageTypeFlags messageType = {},
98 const ServerInfo_User &userInfo = {},
99 bool playerBold = false);
100 void clearChat();
101 void redactMessages(const QString &userName, int amount);
102
103protected:
104#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
105 void enterEvent(QEnterEvent *event) override;
106#else
107 void enterEvent(QEvent *event) override;
108#endif
109 void leaveEvent(QEvent *event) override;
110 void mouseMoveEvent(QMouseEvent *event) override;
111 void mousePressEvent(QMouseEvent *event) override;
112 void mouseReleaseEvent(QMouseEvent *event) override;
113signals:
114 void openMessageDialog(const QString &userName, bool focus);
115 void cardNameHovered(QString cardName);
116 void showCardInfoPopup(const QPoint &pos, const CardRef &cardRef);
117 void deleteCardInfoPopup(QString cardName);
118 void addMentionTag(QString mentionTag);
120 void showMentionPopup(const QString &userName);
121};
122
123#endif
Definition abstract_game.h:21
void appendCardTag(QTextCursor &cursor, const QString &cardName)
Definition chat_view.cpp:112
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:455
void checkWord(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:378
void mousePressEvent(QMouseEvent *event) override
Definition chat_view.cpp:569
AbstractGame *const game
Definition chat_view.h:41
QTextFragment getFragmentUnderMouse(const QPoint &pos) const
Definition chat_view.cpp:528
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:614
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:474
void showMentionPopup(const QString &userName)
QTextCursor prepareBlock(bool same=false)
Definition chat_view.cpp:65
TabSupervisor *const tabSupervisor
Definition chat_view.h:40
QString extractNextWord(QString &message, QString &rest)
Definition chat_view.cpp:414
UserContextMenu * userContextMenu
Definition chat_view.h:52
void retranslateUi()
Definition chat_view.cpp:60
static QColor getCustomMentionColor()
Definition chat_view.cpp:463
QTextCharFormat mentionFormat
Definition chat_view.h:56
bool isModeratorSendingGlobal(QFlags< ServerInfo_User::UserLevelFlag > userLevelFlag, QString message)
Definition chat_view.cpp:439
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:515
void clearChat()
Definition chat_view.cpp:485
QTextCharFormat mentionFormatOtherUser
Definition chat_view.h:58
void mouseMoveEvent(QMouseEvent *event) override
Definition chat_view.cpp:541
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:492
void cardNameHovered(QString cardName)
QString hoveredContent
Definition chat_view.h:64
void leaveEvent(QEvent *event) override
Definition chat_view.cpp:523
void checkMention(QTextCursor &cursor, QString &message, const QString &userName, UserLevelFlags userLevel)
Definition chat_view.cpp:314
void messageClickedSignal()
void checkTag(QTextCursor &cursor, QString &message)
Definition chat_view.cpp:269
QString lastSender
Definition chat_view.h:53
void openLink(const QUrl &link)
Definition chat_view.cpp:622
QTextCharFormat defaultFormat
Definition chat_view.h:59
void appendUrlTag(QTextCursor &cursor, QString url)
Definition chat_view.cpp:126
void actMessageClicked()
Definition chat_view.cpp:450
QTextCharFormat highlightFormat
Definition chat_view.h:57
void appendHtml(const QString &html)
Definition chat_view.cpp:88
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.