diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index 6af5f104..00dbd3a6 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -53,14 +53,15 @@ QTextCursor ChatView::prepareBlock(bool same) QTextCursor cursor(document()->lastBlock()); cursor.movePosition(QTextCursor::End); - if (!same) { + if (same) { + cursor.insertHtml("
"); + } else { QTextBlockFormat blockFormat; if ((evenNumber = !evenNumber)) blockFormat.setBackground(palette().alternateBase()); blockFormat.setBottomMargin(4); cursor.insertBlock(blockFormat); - } else - cursor.insertHtml("
"); + } return cursor; } @@ -126,6 +127,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use QTextCursor cursor = prepareBlock(sameSender); lastSender = sender; + // timestamp if (showTimestamps && !sameSender) { QTextCharFormat timeFormat; timeFormat.setForeground(QColor(SERVER_MESSAGE_COLOR)); @@ -134,7 +136,8 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use cursor.setCharFormat(timeFormat); cursor.insertText(QDateTime::currentDateTime().toString("[hh:mm:ss] ")); } - + + // nickname QTextCharFormat senderFormat; if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) { senderFormat.setForeground(QBrush(getCustomMentionColor())); @@ -146,7 +149,9 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use } senderFormat.setAnchor(true); senderFormat.setAnchorHref("user://" + QString::number(userLevel) + "_" + sender); - if (!sameSender) { + if (sameSender) { + cursor.insertText(" "); + } else { if (!sender.isEmpty() && tabSupervisor->getUserListsTab()) { const int pixelSize = QFontInfo(cursor.charFormat().font()).pixelSize(); QMap buddyList = tabSupervisor->getUserListsTab()->getBuddyList()->getUsers(); @@ -157,232 +162,48 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use if (!sender.isEmpty()) sender.append(": "); 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(); - const QRegExp urlStarter = QRegExp("https?://|\\bwww\\."); - const QRegExp phraseEnder = QRegExp("\\s"); - const QRegExp notALetterOrNumber = QRegExp("[^a-zA-Z0-9]"); - + highlightedWords = settingsCache->getHighlightWords().split(' ', QString::SkipEmptyParts); + + // parse the message while (message.size()) { - // search for the first [ or @ - bracketFirstIndex = message.indexOf('['); - mentionFirstIndex = message.indexOf('@'); - urlFirstIndex = message.indexOf(urlStarter); - - bool startsWithBracket = (bracketFirstIndex != -1); - bool startsWithAtSymbol = (mentionFirstIndex != -1); - bool startsWithUrl = (urlFirstIndex != -1); - - if (!startsWithBracket) + QChar c = message.at(0); + switch(c.toLatin1()) { - if (!startsWithAtSymbol) - { - if (!startsWithUrl) - { - // No brackets, mentions, or urls. Send message as normal - cursor.insertText(message); - break; + case '[': + checkTag(cursor, message); + break; + case '@': + if(mentionEnabled) { + checkMention(cursor, message, sender, userLevel); + } else { + cursor.insertText(c, defaultFormat); + message = message.mid(1); } - 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 there's a URL, pick the first one... then lets begin! - // Otherwise, just "lets begin!" - index = std::min(index, urlFirstIndex); - } - } - - if (index > 0) - { - 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]")) - { - message = message.mid(6); - int closeTagIndex = message.indexOf("[/card]"); - QString cardName = message.left(closeTagIndex); - if (closeTagIndex == -1) - message.clear(); - else - message = message.mid(closeTagIndex + 7); - - appendCardTag(cursor, cardName); - } - else if (message.startsWith("[[")) - { - message = message.mid(2); - int closeTagIndex = message.indexOf("]]"); - QString cardName = message.left(closeTagIndex); - if (closeTagIndex == -1) - message.clear(); - else - message = message.mid(closeTagIndex + 2); - - appendCardTag(cursor, cardName); - } - else if (message.startsWith("[url]")) - { - message = message.mid(5); - int closeTagIndex = message.indexOf("[/url]"); - QString url = message.left(closeTagIndex); - if (closeTagIndex == -1) - message.clear(); - else - message = message.mid(closeTagIndex + 6); - - appendUrlTag(cursor, url); - } - else - { - // Not a valid tag - cursor.insertText("[", defaultFormat); + break; + case ' ': + cursor.insertText(c, defaultFormat); message = message.mid(1); - } - } - else if (index == urlFirstIndex) // The message now starts with either: www. , http:// , or https:// - { - int urlEndIndex = message.indexOf(phraseEnder, 0); - 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 mentionIntact = fullMentionUpToSpaceOrEnd; - - if ((!mentionEnabled && !isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) || tabSupervisor->getIsLocalGame()) - { - cursor.insertText("@"); - message = message.mid(1); - } - else - { - QMap userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers(); - - do - { - if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this? - { - if (userName.toLower() == fullMentionUpToSpaceOrEnd.toLower()) // Is this user you? - { - // You have received a valid mention!! - mentionFormat.setBackground(QBrush(getCustomMentionColor())); - mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); - cursor.insertText(mention, mentionFormat); - message = message.mid(mention.size()); - QApplication::alert(this); - if (settingsCache->getShowMentionPopup() && shouldShowSystemPopup()) - { - QString ref = sender.left(sender.length() - 2); - showSystemPopup(ref); - } - } - else - { - QString correctUserName = getNameFromUserList(userList, fullMentionUpToSpaceOrEnd); - UserListTWI *vlu = userList.value(correctUserName); - mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName); - cursor.insertText("@" + correctUserName, mentionFormatOtherUser); - - message = message.mid(correctUserName.size() + 1); - } - - cursor.setCharFormat(defaultFormat); - break; - } - else if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) - { - // Moderator Sending Global Message - mentionFormat.setBackground(QBrush(getCustomMentionColor())); - mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); - cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat); - message = message.mid(fullMentionUpToSpaceOrEnd.size() + 1); - QApplication::alert(this); - if (settingsCache->getShowMentionPopup() && shouldShowSystemPopup()) - { - QString ref = sender.left(sender.length() - 2); - showSystemPopup(ref); - } - - cursor.setCharFormat(defaultFormat); - break; - } - else if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2) - { - cursor.insertText("@" + mentionIntact, defaultFormat); - message = message.mid(mentionIntact.size() + 1); - cursor.setCharFormat(defaultFormat); - break; - } - else - { - fullMentionUpToSpaceOrEnd.chop(1); - } + break; + default: + if(c.isLetterOrNumber()) { + checkWord(cursor, message); + } else { + cursor.insertText(c, defaultFormat); + message = message.mid(1); } - while (fullMentionUpToSpaceOrEnd.size()); - } - } - else - { - message = message.mid(1); // Not certain when this would ever be reached, but just incase lets skip the character + break; } } @@ -390,6 +211,194 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } +void ChatView::checkTag(QTextCursor &cursor, QString &message) +{ + if (message.startsWith("[card]")) + { + message = message.mid(6); + int closeTagIndex = message.indexOf("[/card]"); + QString cardName = message.left(closeTagIndex); + if (closeTagIndex == -1) + message.clear(); + else + message = message.mid(closeTagIndex + 7); + + appendCardTag(cursor, cardName); + return; + } + + if (message.startsWith("[[")) + { + message = message.mid(2); + int closeTagIndex = message.indexOf("]]"); + QString cardName = message.left(closeTagIndex); + if (closeTagIndex == -1) + message.clear(); + else + message = message.mid(closeTagIndex + 2); + + appendCardTag(cursor, cardName); + return; + } + + if (message.startsWith("[url]")) + { + message = message.mid(5); + int closeTagIndex = message.indexOf("[/url]"); + QString url = message.left(closeTagIndex); + if (closeTagIndex == -1) + message.clear(); + else + message = message.mid(closeTagIndex + 6); + + appendUrlTag(cursor, url); + return; + } + + // no valid tag found + checkWord(cursor, message); +} + +void ChatView::checkMention(QTextCursor &cursor, QString &message, QString &sender, UserLevelFlags userLevel) +{ + const QRegExp notALetterOrNumber = QRegExp("[^a-zA-Z0-9]"); + + int firstSpace = message.indexOf(' '); + QString fullMentionUpToSpaceOrEnd = (firstSpace == -1) ? message.mid(1) : message.mid(1, firstSpace - 1); + QString mentionIntact = fullMentionUpToSpaceOrEnd; + + QMap userList = tabSupervisor->getUserListsTab()->getAllUsersList()->getUsers(); + + while (fullMentionUpToSpaceOrEnd.size()) + { + if (isFullMentionAValidUser(userList, fullMentionUpToSpaceOrEnd)) // Is there a user online named this? + { + if (userName.toLower() == fullMentionUpToSpaceOrEnd.toLower()) // Is this user you? + { + // You have received a valid mention!! + mentionFormat.setBackground(QBrush(getCustomMentionColor())); + mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); + cursor.insertText(mention, mentionFormat); + message = message.mid(mention.size()); + QApplication::alert(this); + if (settingsCache->getShowMentionPopup() && shouldShowSystemPopup()) + { + QString ref = sender.left(sender.length() - 2); + showSystemPopup(ref); + } + } else { + QString correctUserName = getNameFromUserList(userList, fullMentionUpToSpaceOrEnd); + UserListTWI *vlu = userList.value(correctUserName); + mentionFormatOtherUser.setAnchorHref("user://" + QString::number(vlu->getUserInfo().user_level()) + "_" + correctUserName); + cursor.insertText("@" + correctUserName, mentionFormatOtherUser); + + message = message.mid(correctUserName.size() + 1); + } + + cursor.setCharFormat(defaultFormat); + return; + } + + if (isModeratorSendingGlobal(userLevel, fullMentionUpToSpaceOrEnd)) { + // Moderator Sending Global Message + mentionFormat.setBackground(QBrush(getCustomMentionColor())); + mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white) : QBrush(Qt::black)); + cursor.insertText("@" + fullMentionUpToSpaceOrEnd, mentionFormat); + message = message.mid(fullMentionUpToSpaceOrEnd.size() + 1); + QApplication::alert(this); + if (settingsCache->getShowMentionPopup() && shouldShowSystemPopup()) + { + QString ref = sender.left(sender.length() - 2); + showSystemPopup(ref); + } + + cursor.setCharFormat(defaultFormat); + return; + } + + if (fullMentionUpToSpaceOrEnd.right(1).indexOf(notALetterOrNumber) == -1 || fullMentionUpToSpaceOrEnd.size() < 2) + { + cursor.insertText("@" + mentionIntact, defaultFormat); + message = message.mid(mentionIntact.size() + 1); + cursor.setCharFormat(defaultFormat); + return; + } + + fullMentionUpToSpaceOrEnd.chop(1); + } + + // no valid mention found + checkWord(cursor, message); +} + +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)) + { + QUrl qUrl(fullWordUpToSpaceOrEnd); + if (qUrl.isValid()) + { + appendUrlTag(cursor, fullWordUpToSpaceOrEnd); + cursor.insertText(rest, defaultFormat); + return; + } + } + + // check word mentions + 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 userLevelFlag, QString message) { int userLevel = QString::number(userLevelFlag).toInt(); @@ -415,13 +424,18 @@ void ChatView::showSystemPopup(QString &sender) { emit showMentionPopup(sender); } - QColor ChatView::getCustomMentionColor() { QColor customColor; customColor.setNamedColor("#" + settingsCache->getChatMentionColor()); 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 was found then the provided name is not available and will return an empty QString. diff --git a/cockatrice/src/chatview.h b/cockatrice/src/chatview.h index ccf28efa..d8fdc764 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -27,8 +27,10 @@ private: QString userName; QString mention; QTextCharFormat mentionFormat; + QTextCharFormat highlightFormat; QTextCharFormat mentionFormatOtherUser; QTextCharFormat defaultFormat; + QStringList highlightedWords; bool evenNumber; bool showTimestamps; HoveredItemType hoveredItemType; @@ -41,9 +43,14 @@ private: QString getNameFromUserList(QMap &userList, QString &userName); bool isFullMentionAValidUser(QMap &userList, QString userNameToMatch); QColor getCustomMentionColor(); + QColor getCustomHighlightColor(); bool shouldShowSystemPopup(); void showSystemPopup(QString &sender); bool isModeratorSendingGlobal(QFlags 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: void openLink(const QUrl &link); void actMessageClicked(); diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 86a0fd4a..c20ca78d 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -580,6 +580,9 @@ MessagesSettingsPage::MessagesSettingsPage() invertMentionForeground.setChecked(settingsCache->getChatMentionForeground()); 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->setText(settingsCache->getChatMentionColor()); updateMentionPreview(); @@ -591,6 +594,11 @@ MessagesSettingsPage::MessagesSettingsPage() mentionPopups.setChecked(settingsCache->getShowMentionPopup()); 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; chatGrid->addWidget(&chatMentionCheckBox, 0, 0); chatGrid->addWidget(&invertMentionForeground, 0, 1); @@ -602,6 +610,20 @@ MessagesSettingsPage::MessagesSettingsPage() chatGrid->addWidget(&mentionPopups, 4, 0); chatGroupBox = new QGroupBox; 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; messageList = new QListWidget; @@ -628,11 +650,12 @@ MessagesSettingsPage::MessagesSettingsPage() messageShortcuts = new QGroupBox; messageShortcuts->setLayout(messageListLayout); - + QVBoxLayout *mainLayout = new QVBoxLayout; - + mainLayout->addWidget(messageShortcuts); mainLayout->addWidget(chatGroupBox); + mainLayout->addWidget(highlightGroupBox); 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) { settingsCache->setChatMentionForeground(value); updateMentionPreview(); } +void MessagesSettingsPage::updateTextHighlightColor(int value) { + settingsCache->setChatHighlightForeground(value); + updateHighlightPreview(); +} + void MessagesSettingsPage::updateMentionPreview() { mentionColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatMentionColor() + ";color: " + (settingsCache->getChatMentionForeground() ? "white" : "black") + ";}"); } +void MessagesSettingsPage::updateHighlightPreview() { + highlightColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatHighlightColor() + + ";color: " + (settingsCache->getChatHighlightForeground() ? "white" : "black") + ";}"); +} + void MessagesSettingsPage::storeSettings() { QSettings settings; @@ -688,15 +730,18 @@ void MessagesSettingsPage::actRemove() void MessagesSettingsPage::retranslateUi() { chatGroupBox->setTitle(tr("Chat settings")); + highlightGroupBox->setTitle(tr("Custom alert words")); chatMentionCheckBox.setText(tr("Enable chat mentions")); 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.")); - ignoreUnregUserMessages.setText(tr("Ignore private 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")); 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.")); hexLabel.setText(tr("(Color is hexadecimal)")); + hexHighlightLabel.setText(tr("(Color is hexadecimal)")); + customAlertStringLabel.setText(tr("Separate words with a space, alphanumeric characters only")); } diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 5b2f06e5..e3c8b158 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -160,24 +160,33 @@ private slots: void actAdd(); void actRemove(); void updateColor(const QString &value); + void updateHighlightColor(const QString &value); void updateTextColor(int value); + void updateTextHighlightColor(int value); private: QListWidget *messageList; QAction *aAdd; QAction *aRemove; QCheckBox chatMentionCheckBox; QCheckBox invertMentionForeground; + QCheckBox invertHighlightForeground; QCheckBox ignoreUnregUsersMainChat; QCheckBox ignoreUnregUserMessages; QCheckBox messagePopups; QCheckBox mentionPopups; QGroupBox *chatGroupBox; + QGroupBox *highlightGroupBox; QGroupBox *messageShortcuts; QLineEdit *mentionColor; + QLineEdit *highlightColor; + QLineEdit *customAlertString; QLabel hexLabel; + QLabel hexHighlightLabel; + QLabel customAlertStringLabel; void storeSettings(); void updateMentionPreview(); + void updateHighlightPreview(); }; class SoundSettingsPage : public AbstractSettingsPage { diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 202a0356..50a0a9cc 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -56,7 +56,9 @@ SettingsCache::SettingsCache() tapAnimation = settings->value("cards/tapanimation", true).toBool(); chatMention = settings->value("chat/mention", true).toBool(); chatMentionForeground = settings->value("chat/mentionforeground", true).toBool(); + chatHighlightForeground = settings->value("chat/highlightforeground", true).toBool(); chatMentionColor = settings->value("chat/mentioncolor", "A6120D").toString(); + chatHighlightColor = settings->value("chat/highlightcolor", "A6120D").toString(); zoneViewSortByName = settings->value("zoneview/sortbyname", true).toBool(); zoneViewSortByType = settings->value("zoneview/sortbytype", true).toBool(); @@ -82,6 +84,8 @@ SettingsCache::SettingsCache() masterVolume = settings->value("sound/mastervolume", 100).toInt(); cardInfoViewMode = settings->value("cards/cardinfoviewmode", 0).toInt(); + + highlightWords = settings->value("personal/highlightWords", QString()).toString(); } void SettingsCache::setCardInfoViewMode(const int _viewMode) { @@ -89,6 +93,11 @@ void SettingsCache::setCardInfoViewMode(const int _viewMode) { settings->setValue("cards/cardinfoviewmode", cardInfoViewMode); } +void SettingsCache::setHighlightWords(const QString &_highlightWords) { + highlightWords = _highlightWords; + settings->setValue("personal/highlightWords", highlightWords); +} + void SettingsCache::setMasterVolume(int _masterVolume) { masterVolume = _masterVolume; settings->setValue("sound/mastervolume", masterVolume); @@ -314,11 +323,21 @@ void SettingsCache::setChatMentionForeground(int _chatMentionForeground) { settings->setValue("chat/mentionforeground", chatMentionForeground); } +void SettingsCache::setChatHighlightForeground(int _chatHighlightForeground) { + chatHighlightForeground = _chatHighlightForeground; + settings->setValue("chat/highlightforeground", chatHighlightForeground); +} + void SettingsCache::setChatMentionColor(const QString &_chatMentionColor) { chatMentionColor = _chatMentionColor; settings->setValue("chat/mentioncolor", chatMentionColor); } +void SettingsCache::setChatHighlightColor(const QString &_chatHighlightColor) { + chatHighlightColor = _chatHighlightColor; + settings->setValue("chat/highlightcolor", chatHighlightColor); +} + void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) { zoneViewSortByName = _zoneViewSortByName; diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index c838f74e..20483f56 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -65,7 +65,9 @@ private: bool tapAnimation; bool chatMention; QString chatMentionColor; + QString chatHighlightColor; bool chatMentionForeground; + bool chatHighlightForeground; bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView; bool soundEnabled; QString soundPath; @@ -85,6 +87,7 @@ private: bool leftJustified; int masterVolume; int cardInfoViewMode; + QString highlightWords; public: SettingsCache(); const QByteArray &getMainWindowGeometry() const { return mainWindowGeometry; } @@ -100,6 +103,7 @@ public: QString getPlayerBgPath() const { return playerBgPath; } QString getCardBackPicturePath() const { return cardBackPicturePath; } QString getChatMentionColor() const { return chatMentionColor; } + QString getChatHighlightColor() const { return chatHighlightColor; } bool getPicDownload() const { return picDownload; } bool getPicDownloadHq() const { return picDownloadHq; } bool getNotificationsEnabled() const { return notificationsEnabled; } @@ -117,6 +121,7 @@ public: bool getTapAnimation() const { return tapAnimation; } bool getChatMention() const { return chatMention; } bool getChatMentionForeground() const { return chatMentionForeground; } + bool getChatHighlightForeground() const { return chatHighlightForeground; } bool getZoneViewSortByName() const { return zoneViewSortByName; } bool getZoneViewSortByType() const { return zoneViewSortByType; } /** @@ -143,6 +148,7 @@ public: int getMasterVolume() const { return masterVolume; } int getCardInfoViewMode() const { return cardInfoViewMode; } QStringList getCountries() const; + QString getHighlightWords() const { return highlightWords; } public slots: void setMainWindowGeometry(const QByteArray &_mainWindowGeometry); void setLang(const QString &_lang); @@ -157,6 +163,7 @@ public slots: void setPlayerBgPath(const QString &_playerBgPath); void setCardBackPicturePath(const QString &_cardBackPicturePath); void setChatMentionColor(const QString &_chatMentionColor); + void setChatHighlightColor(const QString &_chatHighlightColor); void setPicDownload(int _picDownload); void setPicDownloadHq(int _picDownloadHq); void setNotificationsEnabled(int _notificationsEnabled); @@ -173,6 +180,7 @@ public slots: void setTapAnimation(int _tapAnimation); void setChatMention(int _chatMention); void setChatMentionForeground(int _chatMentionForeground); + void setChatHighlightForeground(int _chatHighlightForeground); void setZoneViewSortByName(int _zoneViewSortByName); void setZoneViewSortByType(int _zoneViewSortByType); void setZoneViewPileView(int _zoneViewPileView); @@ -194,6 +202,7 @@ public slots: void setLeftJustified( const int _leftJustified); void setMasterVolume(const int _masterVolume); void setCardInfoViewMode(const int _viewMode); + void setHighlightWords(const QString &_highlightWords); }; extern SettingsCache *settingsCache;