Fix server message color; try to detect words inside parentheses, punctuation, etc..

This commit is contained in:
Fabio Bas 2015-07-15 11:52:04 +02:00
parent 2e3e6c55ff
commit efe388bddd

View file

@ -158,12 +158,13 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
cursor.insertText(sender); cursor.insertText(sender);
} }
QTextCharFormat messageFormat; // use different color for server messages
defaultFormat = QTextCharFormat();
if (sender.isEmpty()) { if (sender.isEmpty()) {
messageFormat.setForeground(Qt::darkGreen); defaultFormat.setForeground(Qt::darkGreen);
messageFormat.setFontWeight(QFont::Bold); defaultFormat.setFontWeight(QFont::Bold);
} }
cursor.setCharFormat(messageFormat); cursor.setCharFormat(defaultFormat);
bool mentionEnabled = settingsCache->getChatMention(); bool mentionEnabled = settingsCache->getChatMention();
highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts); highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);
@ -178,17 +179,24 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
checkTag(cursor, message); checkTag(cursor, message);
break; break;
case '@': case '@':
if(mentionEnabled) if(mentionEnabled) {
checkMention(cursor, message, sender, userLevel); checkMention(cursor, message, sender, userLevel);
else } else {
checkWord(cursor, message); cursor.insertText(c, defaultFormat);
message = message.mid(1);
}
break; break;
case ' ': case ' ':
cursor.insertText(" ", defaultFormat); cursor.insertText(c, defaultFormat);
message = message.mid(1); message = message.mid(1);
break; break;
default: default:
checkWord(cursor, message); if(c.isLetterOrNumber()) {
checkWord(cursor, message);
} else {
cursor.insertText(c, defaultFormat);
message = message.mid(1);
}
break; break;
} }
} }
@ -346,7 +354,6 @@ void ChatView::checkWord(QTextCursor &cursor, QString &message)
highlightFormat.setBackground(QBrush(getCustomHighlightColor())); highlightFormat.setBackground(QBrush(getCustomHighlightColor()));
highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat); cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat);
cursor.setCharFormat(defaultFormat);
cursor.insertText(rest, defaultFormat); cursor.insertText(rest, defaultFormat);
QApplication::alert(this); QApplication::alert(this);
return; return;