Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
71a06703
Commit
71a06703
authored
Jan 22, 2015
by
poixen
Browse files
Merge pull request #578 from poixen/user_chat_mentions
User chat mentions
parents
11bb3260
497fed6b
Changes
2
Hide whitespace changes
Inline
Side-by-side
cockatrice/src/chatview.cpp
View file @
71a06703
...
...
@@ -6,10 +6,15 @@
#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"
const
QColor
OTHER_USER_MENTION_COLOR
=
QColor
(
145
,
210
,
255
);
// light blue
const
QColor
MENTION_COLOR
=
QColor
(
190
,
25
,
85
);
// maroon
const
QColor
OTHER_USER_COLOR
=
QColor
(
0
,
65
,
255
);
// dark blue
ChatView
::
ChatView
(
const
TabSupervisor
*
_tabSupervisor
,
TabGame
*
_game
,
bool
_showTimestamps
,
QWidget
*
parent
)
:
QTextBrowser
(
parent
),
tabSupervisor
(
_tabSupervisor
),
game
(
_game
),
evenNumber
(
true
),
showTimestamps
(
_showTimestamps
),
hoveredItemType
(
HoveredNothing
)
...
...
@@ -23,7 +28,12 @@ ChatView::ChatView(const TabSupervisor *_tabSupervisor, TabGame *_game, bool _sh
mentionFormat
.
setFontWeight
(
QFont
::
Bold
);
mentionFormat
.
setForeground
(
QBrush
(
Qt
::
white
));
mentionFormat
.
setBackground
(
QBrush
(
QColor
(
190
,
25
,
85
)));
mentionFormat
.
setBackground
(
QBrush
(
MENTION_COLOR
));
mentionFormatOtherUser
.
setFontWeight
(
QFont
::
Bold
);
mentionFormatOtherUser
.
setForeground
(
Qt
::
blue
);
mentionFormatOtherUser
.
setBackground
(
QBrush
(
OTHER_USER_MENTION_COLOR
));
mentionFormatOtherUser
.
setAnchor
(
true
);
viewport
()
->
setCursor
(
Qt
::
IBeamCursor
);
setReadOnly
(
true
);
...
...
@@ -111,9 +121,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
(
MENTION_COLOR
));
}
else
{
senderFormat
.
setForeground
(
Q
t
::
blue
);
senderFormat
.
setForeground
(
Q
Brush
(
OTHER_USER_COLOR
)
);
if
(
playerBold
)
senderFormat
.
setFontWeight
(
QFont
::
Bold
);
}
...
...
@@ -179,14 +189,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
<
QString
,
UserListTWI
*>
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
())
...
...
cockatrice/src/chatview.h
View file @
71a06703
...
...
@@ -6,11 +6,11 @@
#include
<QTextCursor>
#include
<QColor>
#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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment