diff --git a/cockatrice/src/chatview.cpp b/cockatrice/src/chatview.cpp index ed6beccfa..c0cb827ab 100644 --- a/cockatrice/src/chatview.cpp +++ b/cockatrice/src/chatview.cpp @@ -116,9 +116,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use QTextCharFormat senderFormat; if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) { - QColor customColor; - customColor.setNamedColor("#" + settingsCache->getChatMentionColor()); - senderFormat.setForeground(customColor.isValid() ? QBrush(customColor) : QBrush(DEFAULT_MENTION_COLOR)); + senderFormat.setForeground(QBrush(getCustomMentionColor())); senderFormat.setFontWeight(QFont::Bold); } else { senderFormat.setForeground(QBrush(OTHER_USER_COLOR)); @@ -195,9 +193,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use break; // you have been mentioned if (message.toLower().startsWith(mention)) { - QColor customColor; - customColor.setNamedColor("#" + settingsCache->getChatMentionColor()); - mentionFormat.setBackground(customColor.isValid() ? QBrush(customColor) : QBrush(DEFAULT_MENTION_COLOR)); + mentionFormat.setBackground(QBrush(getCustomMentionColor())); mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white):QBrush(Qt::black)); cursor.insertText("@" + userName, mentionFormat); message = message.mid(mention.size()); @@ -231,6 +227,12 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } +QColor ChatView::getCustomMentionColor() { + QColor customColor; + customColor.setNamedColor("#" + settingsCache->getChatMentionColor()); + 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 17cdd398d..693a7f8d6 100644 --- a/cockatrice/src/chatview.h +++ b/cockatrice/src/chatview.h @@ -37,6 +37,7 @@ private: void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendUrlTag(QTextCursor &cursor, QString url); QString getNameFromUserList(QMap &userList, QString &userName); + QColor getCustomMentionColor(); private slots: void openLink(const QUrl &link); public: diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 865ad6d27..7905b5a9f 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -566,7 +566,6 @@ void DeckEditorSettingsPage::radioPriceTagSourceClicked(bool checked) MessagesSettingsPage::MessagesSettingsPage() { - chatMentionCheckBox.setChecked(settingsCache->getChatMention()); connect(&chatMentionCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setChatMention(int))); @@ -574,18 +573,18 @@ MessagesSettingsPage::MessagesSettingsPage() connect(&ignoreUnregUsersMainChat, SIGNAL(stateChanged(int)), settingsCache, SLOT(setIgnoreUnregisteredUsers(int))); invertMentionForeground.setChecked(settingsCache->getChatMentionForeground()); - connect(&invertMentionForeground, SIGNAL(stateChanged(int)), settingsCache, SLOT(setChatMentionForeground(int))); + connect(&invertMentionForeground, SIGNAL(stateChanged(int)), this, SLOT(updateTextColor(int))); mentionColor = new QLineEdit(); mentionColor->setText(settingsCache->getChatMentionColor()); - connect(mentionColor, SIGNAL(textChanged(QString)), settingsCache, SLOT(setChatMentionColor(QString))); + updateMentionPreview(); + connect(mentionColor, SIGNAL(textChanged(QString)), this, SLOT(updateColor(QString))); QGridLayout *chatGrid = new QGridLayout; chatGrid->addWidget(&chatMentionCheckBox, 0, 0); - chatGrid->addWidget(&mentionColorLabel, 1, 0); - chatGrid->addWidget(mentionColor, 1, 1); - chatGrid->addWidget(&invertMentionForeground, 2, 0); - chatGrid->addWidget(&ignoreUnregUsersMainChat, 3, 0); + chatGrid->addWidget(&invertMentionForeground, 0, 1); + chatGrid->addWidget(mentionColor, 0, 2); + chatGrid->addWidget(&ignoreUnregUsersMainChat, 1, 0); chatGroupBox = new QGroupBox; chatGroupBox->setLayout(chatGrid); @@ -624,6 +623,25 @@ MessagesSettingsPage::MessagesSettingsPage() retranslateUi(); } +void MessagesSettingsPage::updateColor(const QString &value) { + QColor colorToSet; + colorToSet.setNamedColor("#" + value); + if (colorToSet.isValid()) { + settingsCache->setChatMentionColor(value); + updateMentionPreview(); + } +} + +void MessagesSettingsPage::updateTextColor(int value) { + settingsCache->setChatMentionForeground(value); + updateMentionPreview(); +} + +void MessagesSettingsPage::updateMentionPreview() { + mentionColor->setStyleSheet("QLineEdit{background:#" + settingsCache->getChatMentionColor() + + ";color: " + (settingsCache->getChatMentionForeground() ? "white" : "black") + ";}"); +} + void MessagesSettingsPage::storeSettings() { QSettings settings; @@ -656,11 +674,10 @@ void MessagesSettingsPage::retranslateUi() aAdd->setText(tr("&Add")); aRemove->setText(tr("&Remove")); chatGroupBox->setTitle(tr("Chat settings")); - chatMentionCheckBox.setText(tr("Enable chat mentions ('@yourusername' in chat log will be highlighted)")); + chatMentionCheckBox.setText(tr("Enable chat mentions")); messageShortcuts->setTitle(tr("In-game message macros")); ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat")); - mentionColorLabel.setText(tr("Username/Mention color:")); - invertMentionForeground.setText(tr("Invert mention text color (white)")); + invertMentionForeground.setText(tr("Invert text color")); } DlgSettings::DlgSettings(QWidget *parent) diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 9b3974321..a7935d942 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -156,6 +156,8 @@ public: private slots: void actAdd(); void actRemove(); + void updateColor(const QString &value); + void updateTextColor(int value); private: QListWidget *messageList; QAction *aAdd; @@ -166,9 +168,9 @@ private: QGroupBox *chatGroupBox; QGroupBox *messageShortcuts; QLineEdit *mentionColor; - QLabel mentionColorLabel; void storeSettings(); + void updateMentionPreview(); }; class DlgSettings : public QDialog {