Merge pull request #1257 from ctrlaltca/messageparser

Chatview: split message parser and add "highlight words"
This commit is contained in:
Zach 2015-07-15 20:00:08 -04:00
commit e0b71d3b05
6 changed files with 333 additions and 230 deletions

View file

@ -53,14 +53,15 @@ QTextCursor ChatView::prepareBlock(bool same)
QTextCursor cursor(document()->lastBlock()); QTextCursor cursor(document()->lastBlock());
cursor.movePosition(QTextCursor::End); cursor.movePosition(QTextCursor::End);
if (!same) { if (same) {
cursor.insertHtml("<br>");
} else {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
if ((evenNumber = !evenNumber)) if ((evenNumber = !evenNumber))
blockFormat.setBackground(palette().alternateBase()); blockFormat.setBackground(palette().alternateBase());
blockFormat.setBottomMargin(4); blockFormat.setBottomMargin(4);
cursor.insertBlock(blockFormat); cursor.insertBlock(blockFormat);
} else }
cursor.insertHtml("<br>");
return cursor; return cursor;
} }
@ -126,6 +127,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
QTextCursor cursor = prepareBlock(sameSender); QTextCursor cursor = prepareBlock(sameSender);
lastSender = sender; lastSender = sender;
// timestamp
if (showTimestamps && !sameSender) { if (showTimestamps && !sameSender) {
QTextCharFormat timeFormat; QTextCharFormat timeFormat;
timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR)); timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR));
@ -135,6 +137,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] ")); cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] "));
} }
// nickname
QTextCharFormat senderFormat; QTextCharFormat senderFormat;
if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) { if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
senderFormat.setForeground(QBrush(getCustomMentionColor())); senderFormat.setForeground(QBrush(getCustomMentionColor()));
@ -146,7 +149,9 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
} }
senderFormat.setAnchor(true); senderFormat.setAnchor(true);
senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender); senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender);
if (!sameSender) { if (sameSender) {
cursor.insertText(" ");
} else {
if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) { if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) {
const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize(); const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize();
QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); QMap<QString, UserListTWI *> buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers();
@ -157,92 +162,57 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
if (!sender.isEmpty()) if (!sender.isEmpty())
sender.append(": "); sender.append(": ");
cursor.insertText(sender); cursor.insertText(sender);
} else
cursor.insertText(" ");
QTextCharFormat messageFormat;
if (sender.isEmpty()) {
messageFormat.setForeground(Qt::darkGreen);
messageFormat.setFontWeight(QFont::Bold);
} }
cursor.setCharFormat(messageFormat);
int index = -1, bracketFirstIndex = -1, mentionFirstIndex = -1, urlFirstIndex = -1; // use different color for server messages
defaultFormat = QTextCharFormat();
if (sender.isEmpty()) {
defaultFormat.setForeground(Qt::darkGreen);
defaultFormat.setFontWeight(QFont::Bold);
}
cursor.setCharFormat(defaultFormat);
bool mentionEnabled = settingsCache->getChatMention(); bool mentionEnabled = settingsCache->getChatMention();
const QRegExp urlStarter = QRegExp("https?://|\\bwww\\."); highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts);
const QRegExp phraseEnder = QRegExp("\\s");
const QRegExp notALetterOrNumber = QRegExp("[^a-zA-Z0-9]");
// parse the message
while (message.size()) while (message.size())
{ {
// search for the first [ or @ QChar c = message.at(0);
bracketFirstIndex = message.indexOf('['); switch(c.toLatin1())
mentionFirstIndex = message.indexOf('@');
urlFirstIndex = message.indexOf(urlStarter);
bool startsWithBracket = (bracketFirstIndex != -1);
bool startsWithAtSymbol = (mentionFirstIndex != -1);
bool startsWithUrl = (urlFirstIndex != -1);
if (!startsWithBracket)
{ {
if (!startsWithAtSymbol) case '[':
{ checkTag(cursor, message);
if (!startsWithUrl) break;
{ case '@':
// No brackets, mentions, or urls. Send message as normal if(mentionEnabled) {
cursor.insertText(message); checkMention(cursor, message, sender, userLevel);
} else {
cursor.insertText(c, defaultFormat);
message = message.mid(1);
}
break;
case ' ':
cursor.insertText(c, defaultFormat);
message = message.mid(1);
break;
default:
if(c.isLetterOrNumber()) {
checkWord(cursor, message);
} else {
cursor.insertText(c, defaultFormat);
message = message.mid(1);
}
break; break;
} }
else
{
// There's a URL, lets begin!
index = urlFirstIndex;
}
}
else
{
if (!startsWithUrl)
{
// There's an @ symbol, lets begin!
index = mentionFirstIndex;
}
else
{
// There's both an @ symbol and URL, pick the first one... lets begin!
index = std::min(urlFirstIndex, mentionFirstIndex);
}
}
}
else
{
if (!startsWithAtSymbol)
{
// There's a [, look down!
index = bracketFirstIndex;
}
else
{
// There's both a [ and @, pick the first one... look down!
index = std::min(bracketFirstIndex, mentionFirstIndex);
} }
if (startsWithUrl) if (atBottom)
{ verticalScrollBar()->setValue(verticalScrollBar()->maximum());
// If there's a URL, pick the first one... then lets begin! }
// Otherwise, just "lets begin!"
index = std::min(index, urlFirstIndex);
}
}
if (index > 0) void ChatView::checkTag(QTextCursor &cursor, QString &message)
{ {
cursor.insertText(message.left(index), defaultFormat);
message = message.mid(index);
}
if (index == bracketFirstIndex) // The message now starts with a bracket ->> [ <<- that symbol
{
if (message.startsWith("[card]")) if (message.startsWith("[card]"))
{ {
message = message.mid(6); message = message.mid(6);
@ -254,8 +224,10 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
message = message.mid(closeTagIndex + 7); message = message.mid(closeTagIndex + 7);
appendCardTag(cursor, cardName); appendCardTag(cursor, cardName);
return;
} }
else if (message.startsWith("[["))
if (message.startsWith("[["))
{ {
message = message.mid(2); message = message.mid(2);
int closeTagIndex = message.indexOf("]]"); int closeTagIndex = message.indexOf("]]");
@ -266,8 +238,10 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
message = message.mid(closeTagIndex + 2); message = message.mid(closeTagIndex + 2);
appendCardTag(cursor, cardName); appendCardTag(cursor, cardName);
return;
} }
else if (message.startsWith("[url]"))
if (message.startsWith("[url]"))
{ {
message = message.mid(5); message = message.mid(5);
int closeTagIndex = message.indexOf("[/url]"); int closeTagIndex = message.indexOf("[/url]");
@ -278,46 +252,24 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
message = message.mid(closeTagIndex + 6); message = message.mid(closeTagIndex + 6);
appendUrlTag(cursor, url); appendUrlTag(cursor, url);
return;
} }
else
{ // no valid tag found
// Not a valid tag checkWord(cursor, message);
cursor.insertText("[", defaultFormat); }
message = message.mid(1);
} void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &sender, UserLevelFlags userLevel)
} {
else if (index == urlFirstIndex) // The message now starts with either: www. , http:// , or https:// const QRegExp notALetterOrNumber = QRegExp("[^a-zA-Z0-9]");
{
int urlEndIndex = message.indexOf(phraseEnder, 0); int firstSpace = message.indexOf(' ');
if (urlEndIndex == -1)
urlEndIndex = message.size();
QString urlText = message.left(urlEndIndex);
QUrl qUrl(urlText);
if (qUrl.isValid())
appendUrlTag(cursor, urlText);
else
cursor.insertText(urlText);
if (urlEndIndex == -1)
message.clear();
else
message = message.mid(urlEndIndex);
}
else if (index == mentionFirstIndex)
{
int firstSpace = message.indexOf(" ");
QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1); QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1);
QString mentionIntact = fullMentionUpToSpaceOrEnd; QString mentionIntact = fullMentionUpToSpaceOrEnd;
if ((!mentionEnabled && !isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) || tabSupervisor->getIsLocalGame())
{
cursor.insertText("@");
message = message.mid(1);
}
else
{
QMap<QString, UserListTWI *> userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers(); QMap<QString, UserListTWI *> userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers();
do while (fullMentionUpToSpaceOrEnd.size())
{ {
if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this? if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this?
{ {
@ -334,9 +286,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
QString ref = sender.left(sender.length() - 2); QString ref = sender.left(sender.length() - 2);
showSystemPopup(ref); showSystemPopup(ref);
} }
} } else {
else
{
QString correctUserName = getNameFromUserList(userList, fullMentionUpToSpaceOrEnd); QString correctUserName = getNameFromUserList(userList, fullMentionUpToSpaceOrEnd);
UserListTWI *vlu = userList.value(correctUserName); UserListTWI *vlu = userList.value(correctUserName);
mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName); mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName);
@ -346,10 +296,10 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
} }
cursor.setCharFormat(defaultFormat); cursor.setCharFormat(defaultFormat);
break; return;
} }
else if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd))
{ if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) {
// Moderator Sending Global Message // Moderator Sending Global Message
mentionFormat.setBackground(QBrush(getCustomMentionColor())); mentionFormat.setBackground(QBrush(getCustomMentionColor()));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
@ -363,33 +313,92 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
} }
cursor.setCharFormat(defaultFormat); cursor.setCharFormat(defaultFormat);
break; return;
} }
else if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2)
if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2)
{ {
cursor.insertText("@" + mentionIntact, defaultFormat); cursor.insertText("@" + mentionIntact, defaultFormat);
message = message.mid(mentionIntact.size() + 1); message = message.mid(mentionIntact.size() + 1);
cursor.setCharFormat(defaultFormat); cursor.setCharFormat(defaultFormat);
break; return;
} }
else
{
fullMentionUpToSpaceOrEnd.chop(1); fullMentionUpToSpaceOrEnd.chop(1);
} }
}
while (fullMentionUpToSpaceOrEnd.size()); // no valid mention found
} checkWord(cursor, message);
} }
else
void ChatView::checkWord(QTextCursor &cursor, QString &message)
{
// extract the first word
QString rest;
QString fullWordUpToSpaceOrEnd = extractNextWord(message, rest);
// check urls
if (fullWordUpToSpaceOrEnd.startsWith("http://", Qt::CaseInsensitive) ||
fullWordUpToSpaceOrEnd.startsWith("https://", Qt::CaseInsensitive) ||
fullWordUpToSpaceOrEnd.startsWith("www.", Qt::CaseInsensitive))
{ {
message = message.mid(1); // Not certain when this would ever be reached, but just incase lets skip the character QUrl qUrl(fullWordUpToSpaceOrEnd);
if (qUrl.isValid())
{
appendUrlTag(cursor, fullWordUpToSpaceOrEnd);
cursor.insertText(rest, defaultFormat);
return;
} }
} }
if (atBottom) // check word mentions
verticalScrollBar()->setValue(verticalScrollBar()->maximum()); foreach (QString word, highlightedWords)
{
if (fullWordUpToSpaceOrEnd.compare(word, Qt::CaseInsensitive) == 0)
{
// You have received a valid mention of custom word!!
highlightFormat.setBackground(QBrush(getCustomHighlightColor()));
highlightFormat.setForeground(settingsCache->getChatHighlightForeground() ? QBrush(Qt::white) : QBrush(Qt::black));
cursor.insertText(fullWordUpToSpaceOrEnd, highlightFormat);
cursor.insertText(rest, defaultFormat);
QApplication::alert(this);
return;
}
}
// not a special word; just print it
cursor.insertText(fullWordUpToSpaceOrEnd + rest, defaultFormat);
} }
QString ChatView::extractNextWord(QString &message, QString &rest)
{
// get the first next space and extract the word
QString word;
int firstSpace = message.indexOf(' ');
if(firstSpace == -1)
{
word = message;
message.clear();
} else {
word = message.mid(0, firstSpace);
message = message.mid(firstSpace);
}
// remove any punctution from the end and pass it separately
for (int len = word.size() - 1; len >= 0; --len)
{
if(word.at(len).isLetterOrNumber())
{
rest = word.mid(len + 1);
return word.mid(0, len + 1);
}
}
rest = word;
return QString();
}
bool ChatView::isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message) bool ChatView::isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message)
{ {
int userLevel = QString::number(userLevelFlag).toInt(); int userLevel = QString::number(userLevelFlag).toInt();
@ -415,13 +424,18 @@ void ChatView::showSystemPopup(QString &sender) {
emit showMentionPopup(sender); emit showMentionPopup(sender);
} }
QColor ChatView::getCustomMentionColor() { QColor ChatView::getCustomMentionColor() {
QColor customColor; QColor customColor;
customColor.setNamedColor("#" + settingsCache->getChatMentionColor()); customColor.setNamedColor("#" + settingsCache->getChatMentionColor());
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR; return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
} }
QColor ChatView::getCustomHighlightColor() {
QColor customColor;
customColor.setNamedColor("#" + settingsCache->getChatHighlightColor());
return customColor.isValid() ? customColor : DEFAULT_MENTION_COLOR;
}
/** /**
Returns the correct case version of the provided username, if no correct casing version Returns the correct case version of the provided username, if no correct casing version
was found then the provided name is not available and will return an empty QString. was found then the provided name is not available and will return an empty QString.

View file

@ -27,8 +27,10 @@ private:
QString userName; QString userName;
QString mention; QString mention;
QTextCharFormat mentionFormat; QTextCharFormat mentionFormat;
QTextCharFormat highlightFormat;
QTextCharFormat mentionFormatOtherUser; QTextCharFormat mentionFormatOtherUser;
QTextCharFormat defaultFormat; QTextCharFormat defaultFormat;
QStringList highlightedWords;
bool evenNumber; bool evenNumber;
bool showTimestamps; bool showTimestamps;
HoveredItemType hoveredItemType; HoveredItemType hoveredItemType;
@ -41,9 +43,14 @@ private:
QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName); QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName);
bool isFullMentionAValidUser(QMap<QString, UserListTWI *> &userList, QString userNameToMatch); bool isFullMentionAValidUser(QMap<QString, UserListTWI *> &userList, QString userNameToMatch);
QColor getCustomMentionColor(); QColor getCustomMentionColor();
QColor getCustomHighlightColor();
bool shouldShowSystemPopup(); bool shouldShowSystemPopup();
void showSystemPopup(QString &sender); void showSystemPopup(QString &sender);
bool isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message); bool isModeratorSendingGlobal(QFlags<ServerInfo_User::UserLevelFlag> userLevelFlag, QString message);
void checkTag(QTextCursor &cursor, QString &message);
void checkMention(QTextCursor &cursor, QString &message, QString &sender, UserLevelFlags userLevel);
void checkWord(QTextCursor &cursor, QString &message);
QString extractNextWord(QString &message, QString &rest);
private slots: private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);
void actMessageClicked(); void actMessageClicked();

View file

@ -580,6 +580,9 @@ MessagesSettingsPage::MessagesSettingsPage()
invertMentionForeground.setChecked(settingsCache->getChatMentionForeground()); invertMentionForeground.setChecked(settingsCache->getChatMentionForeground());
connect(&invertMentionForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextColor(int))); connect(&invertMentionForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextColor(int)));
invertHighlightForeground.setChecked(settingsCache->getChatHighlightForeground());
connect(&invertHighlightForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextHighlightColor(int)));
mentionColor = new QLineEdit(); mentionColor = new QLineEdit();
mentionColor->setText(settingsCache->getChatMentionColor()); mentionColor->setText(settingsCache->getChatMentionColor());
updateMentionPreview(); updateMentionPreview();
@ -591,6 +594,11 @@ MessagesSettingsPage::MessagesSettingsPage()
mentionPopups.setChecked(settingsCache->getShowMentionPopup()); mentionPopups.setChecked(settingsCache->getShowMentionPopup());
connect(&mentionPopups, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowMentionPopups(int))); connect(&mentionPopups, SIGNAL(stateChanged(int)), settingsCache, SLOT(setShowMentionPopups(int)));
customAlertString = new QLineEdit();
customAlertString->setPlaceholderText("Word1 Word2 Word3");
customAlertString->setText(settingsCache->getHighlightWords());
connect(customAlertString, SIGNAL(textChanged(QString)), settingsCache, SLOT(setHighlightWords(QString)));
QGridLayout *chatGrid = new QGridLayout; QGridLayout *chatGrid = new QGridLayout;
chatGrid->addWidget(&chatMentionCheckBox, 0, 0); chatGrid->addWidget(&chatMentionCheckBox, 0, 0);
chatGrid->addWidget(&invertMentionForeground, 0, 1); chatGrid->addWidget(&invertMentionForeground, 0, 1);
@ -603,6 +611,20 @@ MessagesSettingsPage::MessagesSettingsPage()
chatGroupBox = new QGroupBox; chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatGrid); chatGroupBox->setLayout(chatGrid);
highlightColor = new QLineEdit();
highlightColor->setText(settingsCache->getChatHighlightColor());
updateHighlightPreview();
connect(highlightColor, SIGNAL(textChanged(QString)), this, SLOT(updateHighlightColor(QString)));
QGridLayout *highlightNotice = new QGridLayout;
highlightNotice->addWidget(highlightColor, 0, 2);
highlightNotice->addWidget(&invertHighlightForeground, 0, 1);
highlightNotice->addWidget(&hexHighlightLabel, 1, 2);
highlightNotice->addWidget(customAlertString, 0, 0);
highlightNotice->addWidget(&customAlertStringLabel, 1, 0);
highlightGroupBox = new QGroupBox;
highlightGroupBox->setLayout(highlightNotice);
QSettings settings; QSettings settings;
messageList = new QListWidget; messageList = new QListWidget;
settings.beginGroup("messages"); settings.beginGroup("messages");
@ -633,6 +655,7 @@ MessagesSettingsPage::MessagesSettingsPage()
mainLayout->addWidget(messageShortcuts); mainLayout->addWidget(messageShortcuts);
mainLayout->addWidget(chatGroupBox); mainLayout->addWidget(chatGroupBox);
mainLayout->addWidget(highlightGroupBox);
setLayout(mainLayout); setLayout(mainLayout);
@ -648,16 +671,35 @@ void MessagesSettingsPage::updateColor(const QString &value) {
} }
} }
void MessagesSettingsPage::updateHighlightColor(const QString &value) {
QColor colorToSet;
colorToSet.setNamedColor("#" + value);
if (colorToSet.isValid()) {
settingsCache->setChatHighlightColor(value);
updateHighlightPreview();
}
}
void MessagesSettingsPage::updateTextColor(int value) { void MessagesSettingsPage::updateTextColor(int value) {
settingsCache->setChatMentionForeground(value); settingsCache->setChatMentionForeground(value);
updateMentionPreview(); updateMentionPreview();
} }
void MessagesSettingsPage::updateTextHighlightColor(int value) {
settingsCache->setChatHighlightForeground(value);
updateHighlightPreview();
}
void MessagesSettingsPage::updateMentionPreview() { void MessagesSettingsPage::updateMentionPreview() {
mentionColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatMentionColor() + mentionColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatMentionColor() +
";color: " + (settingsCache->getChatMentionForeground() ? "white" : "black") + ";}"); ";color: " + (settingsCache->getChatMentionForeground() ? "white" : "black") + ";}");
} }
void MessagesSettingsPage::updateHighlightPreview() {
highlightColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatHighlightColor() +
";color: " + (settingsCache->getChatHighlightForeground() ? "white" : "black") + ";}");
}
void MessagesSettingsPage::storeSettings() void MessagesSettingsPage::storeSettings()
{ {
QSettings settings; QSettings settings;
@ -688,15 +730,18 @@ void MessagesSettingsPage::actRemove()
void MessagesSettingsPage::retranslateUi() void MessagesSettingsPage::retranslateUi()
{ {
chatGroupBox->setTitle(tr("Chat settings")); chatGroupBox->setTitle(tr("Chat settings"));
highlightGroupBox->setTitle(tr("Custom alert words"));
chatMentionCheckBox.setText(tr("Enable chat mentions")); chatMentionCheckBox.setText(tr("Enable chat mentions"));
messageShortcuts->setTitle(tr("In-game message macros")); messageShortcuts->setTitle(tr("In-game message macros"));
ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat")); ignoreUnregUsersMainChat.setText(tr("Ignore chat room messages sent by unregistered users"));
ignoreUnregUsersMainChat.setText(tr("Ignore chat room messages sent by unregistered users.")); ignoreUnregUserMessages.setText(tr("Ignore private messages sent by unregistered users"));
ignoreUnregUserMessages.setText(tr("Ignore private messages sent by unregistered users."));
invertMentionForeground.setText(tr("Invert text color")); invertMentionForeground.setText(tr("Invert text color"));
messagePopups.setText(tr("Enable desktop notifications for private messages.")); invertHighlightForeground.setText(tr("Invert text color"));
messagePopups.setText(tr("Enable desktop notifications for private messages"));
mentionPopups.setText(tr("Enable desktop notification for mentions.")); mentionPopups.setText(tr("Enable desktop notification for mentions."));
hexLabel.setText(tr("(Color is hexadecimal)")); hexLabel.setText(tr("(Color is hexadecimal)"));
hexHighlightLabel.setText(tr("(Color is hexadecimal)"));
customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only"));
} }

View file

@ -160,24 +160,33 @@ private slots:
void actAdd(); void actAdd();
void actRemove(); void actRemove();
void updateColor(const QString &value); void updateColor(const QString &value);
void updateHighlightColor(const QString &value);
void updateTextColor(int value); void updateTextColor(int value);
void updateTextHighlightColor(int value);
private: private:
QListWidget *messageList; QListWidget *messageList;
QAction *aAdd; QAction *aAdd;
QAction *aRemove; QAction *aRemove;
QCheckBox chatMentionCheckBox; QCheckBox chatMentionCheckBox;
QCheckBox invertMentionForeground; QCheckBox invertMentionForeground;
QCheckBox invertHighlightForeground;
QCheckBox ignoreUnregUsersMainChat; QCheckBox ignoreUnregUsersMainChat;
QCheckBox ignoreUnregUserMessages; QCheckBox ignoreUnregUserMessages;
QCheckBox messagePopups; QCheckBox messagePopups;
QCheckBox mentionPopups; QCheckBox mentionPopups;
QGroupBox *chatGroupBox; QGroupBox *chatGroupBox;
QGroupBox *highlightGroupBox;
QGroupBox *messageShortcuts; QGroupBox *messageShortcuts;
QLineEdit *mentionColor; QLineEdit *mentionColor;
QLineEdit *highlightColor;
QLineEdit *customAlertString;
QLabel hexLabel; QLabel hexLabel;
QLabel hexHighlightLabel;
QLabel customAlertStringLabel;
void storeSettings(); void storeSettings();
void updateMentionPreview(); void updateMentionPreview();
void updateHighlightPreview();
}; };
class SoundSettingsPage : public AbstractSettingsPage { class SoundSettingsPage : public AbstractSettingsPage {

View file

@ -56,7 +56,9 @@ SettingsCache::SettingsCache()
tapAnimation = settings->value("cards/tapanimation", true).toBool(); tapAnimation = settings->value("cards/tapanimation", true).toBool();
chatMention = settings->value("chat/mention", true).toBool(); chatMention = settings->value("chat/mention", true).toBool();
chatMentionForeground = settings->value("chat/mentionforeground", true).toBool(); chatMentionForeground = settings->value("chat/mentionforeground", true).toBool();
chatHighlightForeground = settings->value("chat/highlightforeground", true).toBool();
chatMentionColor = settings->value("chat/mentioncolor", "A6120D").toString(); chatMentionColor = settings->value("chat/mentioncolor", "A6120D").toString();
chatHighlightColor = settings->value("chat/highlightcolor", "A6120D").toString();
zoneViewSortByName = settings->value("zoneview/sortbyname", true).toBool(); zoneViewSortByName = settings->value("zoneview/sortbyname", true).toBool();
zoneViewSortByType = settings->value("zoneview/sortbytype", true).toBool(); zoneViewSortByType = settings->value("zoneview/sortbytype", true).toBool();
@ -82,6 +84,8 @@ SettingsCache::SettingsCache()
masterVolume = settings->value("sound/mastervolume", 100).toInt(); masterVolume = settings->value("sound/mastervolume", 100).toInt();
cardInfoViewMode = settings->value("cards/cardinfoviewmode", 0).toInt(); cardInfoViewMode = settings->value("cards/cardinfoviewmode", 0).toInt();
highlightWords = settings->value("personal/highlightWords", QString()).toString();
} }
void SettingsCache::setCardInfoViewMode(const int _viewMode) { void SettingsCache::setCardInfoViewMode(const int _viewMode) {
@ -89,6 +93,11 @@ void SettingsCache::setCardInfoViewMode(const int _viewMode) {
settings->setValue("cards/cardinfoviewmode", cardInfoViewMode); settings->setValue("cards/cardinfoviewmode", cardInfoViewMode);
} }
void SettingsCache::setHighlightWords(const QString &_highlightWords) {
highlightWords = _highlightWords;
settings->setValue("personal/highlightWords", highlightWords);
}
void SettingsCache::setMasterVolume(int _masterVolume) { void SettingsCache::setMasterVolume(int _masterVolume) {
masterVolume = _masterVolume; masterVolume = _masterVolume;
settings->setValue("sound/mastervolume", masterVolume); settings->setValue("sound/mastervolume", masterVolume);
@ -314,11 +323,21 @@ void SettingsCache::setChatMentionForeground(int _chatMentionForeground) {
settings->setValue("chat/mentionforeground", chatMentionForeground); settings->setValue("chat/mentionforeground", chatMentionForeground);
} }
void SettingsCache::setChatHighlightForeground(int _chatHighlightForeground) {
chatHighlightForeground = _chatHighlightForeground;
settings->setValue("chat/highlightforeground", chatHighlightForeground);
}
void SettingsCache::setChatMentionColor(const QString &_chatMentionColor) { void SettingsCache::setChatMentionColor(const QString &_chatMentionColor) {
chatMentionColor = _chatMentionColor; chatMentionColor = _chatMentionColor;
settings->setValue("chat/mentioncolor", chatMentionColor); settings->setValue("chat/mentioncolor", chatMentionColor);
} }
void SettingsCache::setChatHighlightColor(const QString &_chatHighlightColor) {
chatHighlightColor = _chatHighlightColor;
settings->setValue("chat/highlightcolor", chatHighlightColor);
}
void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName)
{ {
zoneViewSortByName = _zoneViewSortByName; zoneViewSortByName = _zoneViewSortByName;

View file

@ -65,7 +65,9 @@ private:
bool tapAnimation; bool tapAnimation;
bool chatMention; bool chatMention;
QString chatMentionColor; QString chatMentionColor;
QString chatHighlightColor;
bool chatMentionForeground; bool chatMentionForeground;
bool chatHighlightForeground;
bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView; bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView;
bool soundEnabled; bool soundEnabled;
QString soundPath; QString soundPath;
@ -85,6 +87,7 @@ private:
bool leftJustified; bool leftJustified;
int masterVolume; int masterVolume;
int cardInfoViewMode; int cardInfoViewMode;
QString highlightWords;
public: public:
SettingsCache(); SettingsCache();
const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; } const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; }
@ -100,6 +103,7 @@ public:
QString getPlayerBgPath() const { return playerBgPath; } QString getPlayerBgPath() const { return playerBgPath; }
QString getCardBackPicturePath() const { return cardBackPicturePath; } QString getCardBackPicturePath() const { return cardBackPicturePath; }
QString getChatMentionColor() const { return chatMentionColor; } QString getChatMentionColor() const { return chatMentionColor; }
QString getChatHighlightColor() const { return chatHighlightColor; }
bool getPicDownload() const { return picDownload; } bool getPicDownload() const { return picDownload; }
bool getPicDownloadHq() const { return picDownloadHq; } bool getPicDownloadHq() const { return picDownloadHq; }
bool getNotificationsEnabled() const { return notificationsEnabled; } bool getNotificationsEnabled() const { return notificationsEnabled; }
@ -117,6 +121,7 @@ public:
bool getTapAnimation() const { return tapAnimation; } bool getTapAnimation() const { return tapAnimation; }
bool getChatMention() const { return chatMention; } bool getChatMention() const { return chatMention; }
bool getChatMentionForeground() const { return chatMentionForeground; } bool getChatMentionForeground() const { return chatMentionForeground; }
bool getChatHighlightForeground() const { return chatHighlightForeground; }
bool getZoneViewSortByName() const { return zoneViewSortByName; } bool getZoneViewSortByName() const { return zoneViewSortByName; }
bool getZoneViewSortByType() const { return zoneViewSortByType; } bool getZoneViewSortByType() const { return zoneViewSortByType; }
/** /**
@ -143,6 +148,7 @@ public:
int getMasterVolume() const { return masterVolume; } int getMasterVolume() const { return masterVolume; }
int getCardInfoViewMode() const { return cardInfoViewMode; } int getCardInfoViewMode() const { return cardInfoViewMode; }
QStringList getCountries() const; QStringList getCountries() const;
QString getHighlightWords() const { return highlightWords; }
public slots: public slots:
void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); void setMainWindowGeometry(const QByteArray &_mainWindowGeometry);
void setLang(const QString &_lang); void setLang(const QString &_lang);
@ -157,6 +163,7 @@ public slots:
void setPlayerBgPath(const QString &_playerBgPath); void setPlayerBgPath(const QString &_playerBgPath);
void setCardBackPicturePath(const QString &_cardBackPicturePath); void setCardBackPicturePath(const QString &_cardBackPicturePath);
void setChatMentionColor(const QString &_chatMentionColor); void setChatMentionColor(const QString &_chatMentionColor);
void setChatHighlightColor(const QString &_chatHighlightColor);
void setPicDownload(int _picDownload); void setPicDownload(int _picDownload);
void setPicDownloadHq(int _picDownloadHq); void setPicDownloadHq(int _picDownloadHq);
void setNotificationsEnabled(int _notificationsEnabled); void setNotificationsEnabled(int _notificationsEnabled);
@ -173,6 +180,7 @@ public slots:
void setTapAnimation(int _tapAnimation); void setTapAnimation(int _tapAnimation);
void setChatMention(int _chatMention); void setChatMention(int _chatMention);
void setChatMentionForeground(int _chatMentionForeground); void setChatMentionForeground(int _chatMentionForeground);
void setChatHighlightForeground(int _chatHighlightForeground);
void setZoneViewSortByName(int _zoneViewSortByName); void setZoneViewSortByName(int _zoneViewSortByName);
void setZoneViewSortByType(int _zoneViewSortByType); void setZoneViewSortByType(int _zoneViewSortByType);
void setZoneViewPileView(int _zoneViewPileView); void setZoneViewPileView(int _zoneViewPileView);
@ -194,6 +202,7 @@ public slots:
void setLeftJustified( const int _leftJustified); void setLeftJustified( const int _leftJustified);
void setMasterVolume(const int _masterVolume); void setMasterVolume(const int _masterVolume);
void setCardInfoViewMode(const int _viewMode); void setCardInfoViewMode(const int _viewMode);
void setHighlightWords(const QString &_highlightWords);
}; };
extern SettingsCache *settingsCache; extern SettingsCache *settingsCache;