From 49d3ad73d5c0aaefbd6eb2dc26fc06cb57549b6d Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 17 Jan 2015 13:23:30 +0100 Subject: [PATCH 1/2] Uername block highlighting I was able to find a simple way to achive the block highlighting. --- cockatrice/src/chatview.cpp | 23 +++++++++++++++++------ cockatrice/src/chatview.h | 4 ++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index e1e3a55d..d8f2ed42 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -18,6 +18,13 @@ ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _sh userContextMenu = new UserContextMenu(tabSupervisor, this, game); connect(userContextMenu, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool))); + userName = QString::fromStdString(tabSupervisor->getUserInfo()->name()); + mention = "@" + userName.toLower(); + + mentionFormat.setFontWeight(QFont::Bold); + mentionFormat.setForeground(QBrush(Qt::white)); + mentionFormat.setBackground(QBrush(QColor(190, 25, 85))); + viewport()->setCursor(Qt::IBeamCursor); setReadOnly(true); setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); @@ -104,7 +111,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use QTextCharFormat senderFormat; if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) { senderFormat.setFontWeight(QFont::Bold); - senderFormat.setForeground(QBrush(QColor(255, 120, 0))); + senderFormat.setForeground(QBrush(QColor(190, 25, 85))); } else { senderFormat.setForeground(Qt::blue); if (playerBold) @@ -172,15 +179,19 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use } if (settingsCache->getChatMention()) { - if (message.toLower().contains("@" + QString::fromStdString(tabSupervisor->getUserInfo()->name()).toLower())) { - messageFormat.setFontWeight(QFont::Bold); - messageFormat.setForeground(QBrush(QColor(255, 120, 0))); + if (message.toLower().contains(mention)) { + int mentionIndex; + while ((mentionIndex = message.toLower().indexOf(mention)) != -1) { + cursor.insertText(message.left(mentionIndex), defaultFormat); + cursor.insertText(userName, mentionFormat); + message = message.mid(mentionIndex + mention.size()); + } } } if (!message.isEmpty()) - cursor.insertText(message, messageFormat); - + cursor.insertText(message, defaultFormat); + if (atBottom) verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } diff --git a/cockatrice/src/chatview.h b/cockatrice/src/chatview.h index 1e8a2022..32eca922 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -22,6 +22,10 @@ private: enum HoveredItemType { HoveredNothing, HoveredUrl, HoveredCard, HoveredUser }; UserContextMenu *userContextMenu; QString lastSender; + QString userName; + QString mention; + QTextCharFormat mentionFormat; + QTextCharFormat defaultFormat; bool evenNumber; bool showTimestamps; HoveredItemType hoveredItemType; From ece56ff3f2d24e904d5536f416ceaad6226171c6 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Sat, 17 Jan 2015 15:03:41 +0100 Subject: [PATCH 2/2] Added @ back in Added the @ back to the chat, this will help if a user does not have the newest version of the client. --- cockatrice/src/chatview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index d8f2ed42..3deffaba 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -183,7 +183,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use int mentionIndex; while ((mentionIndex = message.toLower().indexOf(mention)) != -1) { cursor.insertText(message.left(mentionIndex), defaultFormat); - cursor.insertText(userName, mentionFormat); + cursor.insertText("@" + userName, mentionFormat); message = message.mid(mentionIndex + mention.size()); } }