From 0334fe3c8fc6d4731d06e8ef7609e18c0ee2ef96 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Thu, 22 Jan 2015 09:32:56 +0100 Subject: [PATCH] Other mentions -- DRAFT -- Mentions about other players currently in the room will be highlighted. They are also clickable for mentions and right clickable for context options. --- cockatrice/src/chatview.cpp | 44 +++++++++++++++++++++++++++++-------- cockatrice/src/chatview.h | 3 ++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index c6d87f70..5f24fde9 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -6,10 +6,11 @@ #include "chatview.h" #include "user_level.h" #include "user_context_menu.h" -#include "tab_supervisor.h" #include "pixmapgenerator.h" #include "settingscache.h" #include "main.h" +#include "userlist.h" +#include "tab_userlists.h" ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _showTimestamps, QWidget *parent) : QTextBrowser(parent), tabSupervisor(_tabSupervisor), game(_game), evenNumber(true), showTimestamps(_showTimestamps), hoveredItemType(HoveredNothing) @@ -25,6 +26,10 @@ ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _sh mentionFormat.setForeground(QBrush(Qt::white)); mentionFormat.setBackground(QBrush(QColor(190, 25, 85))); + mentionFormatOtherUser.setForeground(Qt::white); + mentionFormatOtherUser.setBackground(QBrush(QColor(0, 65, 255, 155))); //toned down dark blue + mentionFormatOtherUser.setAnchor(true); + viewport()->setCursor(Qt::IBeamCursor); setReadOnly(true); setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse); @@ -111,9 +116,9 @@ 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(190, 25, 85))); + senderFormat.setForeground(QBrush(QColor(190, 25, 85))); // maroon } else { - senderFormat.setForeground(Qt::blue); + senderFormat.setForeground(QBrush(QColor(0, 65, 255))); // dark blue if (playerBold) senderFormat.setFontWeight(QFont::Bold); } @@ -179,14 +184,35 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use } if (settingsCache->getChatMention()) { - if (message.toLower().contains(mention)) { - int mentionIndex; - while ((mentionIndex = message.toLower().indexOf(mention)) != -1) { - cursor.insertText(message.left(mentionIndex), defaultFormat); + index = 0; + from = 0; + while((index = message.indexOf('@', from)) != -1) { + cursor.insertText(message.left(index), defaultFormat); + message = message.mid(index); + if (message.isEmpty()) + break; + // you have been mentioned + if (message.toLower().startsWith(mention)) { cursor.insertText("@" + userName, mentionFormat); - message = message.mid(mentionIndex + mention.size()); + message = message.mid(mention.size()); } - } + // another user has been mentioned + else { + int mentionEndIndex = message.indexOf(" "); + if (mentionEndIndex == -1) + mentionEndIndex = message.size(); // there is no text after the mention + QString userMention = message.left(mentionEndIndex); + QString userName = userMention.right(userMention.size()-1).normalized(QString::NormalizationForm_D); + QMap userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers(); + if (userList.contains(userName)) { + UserListTWI *vlu = userList.value(userName); + mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + userName); + cursor.insertText("@" + userName, mentionFormatOtherUser); + } else + cursor.insertText("@" + userName, defaultFormat); + message = message.mid(userName.size() + 1); + } + } } if (!message.isEmpty()) diff --git a/cockatrice/src/chatview.h b/cockatrice/src/chatview.h index 1730617d..68037d4a 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -6,11 +6,11 @@ #include #include #include "user_level.h" +#include "tab_supervisor.h" class QTextTable; class QMouseEvent; class UserContextMenu; -class TabSupervisor; class TabGame; class ChatView : public QTextBrowser { @@ -25,6 +25,7 @@ private: QString userName; QString mention; QTextCharFormat mentionFormat; + QTextCharFormat mentionFormatOtherUser; QTextCharFormat defaultFormat; bool evenNumber; bool showTimestamps;