[Chat] Don't tag cards that have no match in the database (#7078)

* [Chat] Don't tag cards that have no match in the database (#2217)

Took 6 minutes


Took 4 minutes

* Highlight not found but attempted tag

Took 6 minutes

* Change color to not be server message color

Took 3 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-08-08 22:18:11 +02:00 • committed by GitHub
parent c4316c40e9
commit ba203440af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 6 deletions

View file

@ -13,6 +13,7 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QMouseEvent> #include <QMouseEvent>
#include <QScrollBar> #include <QScrollBar>
#include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/network/server/remote/user_level.h> #include <libcockatrice/network/server/remote/user_level.h>
#include <libcockatrice/settings/chat_settings.h> #include <libcockatrice/settings/chat_settings.h>
@ -62,12 +63,14 @@ void ChatView::adjustColorsToPalette()
serverMessageColor = QColor(0xFF, 0x73, 0x83); serverMessageColor = QColor(0xFF, 0x73, 0x83);
otherUserColor = otherUserColor.lighter(150); otherUserColor = otherUserColor.lighter(150);
linkColor = QColor(71, 158, 252); linkColor = QColor(71, 158, 252);
unresolvedCardTagColor = QColor(0xFF, 0xA5, 0x00);
} else { } else {
document()->setDefaultStyleSheet(R"( document()->setDefaultStyleSheet(R"(
a { text-decoration: none; color: blue; } a { text-decoration: none; color: blue; }
.blue { color: blue } .blue { color: blue }
)"); )");
linkColor = palette().link().color(); linkColor = palette().link().color();
unresolvedCardTagColor = QColor(0xA0, 0x52, 0x2D);
} }
QTimer::singleShot(0, this, &ChatView::refreshBlockColors); QTimer::singleShot(0, this, &ChatView::refreshBlockColors);
@ -173,13 +176,22 @@ void ChatView::appendHtmlServerMessage(const QString &html, bool optionalIsBold,
void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName) void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
{ {
QTextCharFormat oldFormat = cursor.charFormat(); QTextCharFormat oldFormat = cursor.charFormat();
QTextCharFormat anchorFormat = oldFormat; QTextCharFormat cardFormat = oldFormat;
anchorFormat.setForeground(linkColor); cardFormat.setFontItalic(true);
anchorFormat.setAnchor(true);
anchorFormat.setAnchorHref("card://" + cardName);
anchorFormat.setFontItalic(true);
cursor.setCharFormat(anchorFormat); if (!CardDatabaseManager::query()->lookupCardByName(cardName)) {
cardFormat.setForeground(unresolvedCardTagColor);
cursor.setCharFormat(cardFormat);
cursor.insertText(cardName);
cursor.setCharFormat(oldFormat);
return;
}
cardFormat.setForeground(linkColor);
cardFormat.setAnchor(true);
cardFormat.setAnchorHref("card://" + cardName);
cursor.setCharFormat(cardFormat);
cursor.insertText(cardName); cursor.insertText(cardName);
cursor.setCharFormat(oldFormat); cursor.setCharFormat(oldFormat);
} }

View file

@ -81,6 +81,7 @@ private:
QColor otherUserColor = QColor(0, 65, 255); // dark blue QColor otherUserColor = QColor(0, 65, 255); // dark blue
QColor serverMessageColor = QColor(0x85, 0x15, 0x15); QColor serverMessageColor = QColor(0x85, 0x15, 0x15);
QColor linkColor; QColor linkColor;
QColor unresolvedCardTagColor;
private slots: private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);