Updated color setting

+ live preview added
+ will now only store the color if valid
This commit is contained in:
Matt Lowe 2015-01-30 01:54:57 +01:00
parent ec8a2de2eb
commit de38a294b5
4 changed files with 39 additions and 17 deletions

View file

@ -116,9 +116,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
QTextCharFormat senderFormat; QTextCharFormat senderFormat;
if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) { if (tabSupervisor && tabSupervisor->getUserInfo() && (sender == QString::fromStdString(tabSupervisor->getUserInfo()->name()))) {
QColor customColor; senderFormat.setForeground(QBrush(getCustomMentionColor()));
customColor.setNamedColor("#" + settingsCache->getChatMentionColor());
senderFormat.setForeground(customColor.isValid() ? QBrush(customColor) : QBrush(DEFAULT_MENTION_COLOR));
senderFormat.setFontWeight(QFont::Bold); senderFormat.setFontWeight(QFont::Bold);
} else { } else {
senderFormat.setForeground(QBrush(OTHER_USER_COLOR)); senderFormat.setForeground(QBrush(OTHER_USER_COLOR));
@ -195,9 +193,7 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
break; break;
// you have been mentioned // you have been mentioned
if (message.toLower().startsWith(mention)) { if (message.toLower().startsWith(mention)) {
QColor customColor; mentionFormat.setBackground(QBrush(getCustomMentionColor()));
customColor.setNamedColor("#" + settingsCache->getChatMentionColor());
mentionFormat.setBackground(customColor.isValid() ? QBrush(customColor) : QBrush(DEFAULT_MENTION_COLOR));
mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white):QBrush(Qt::black)); mentionFormat.setForeground(settingsCache->getChatMentionForeground() ? QBrush(Qt::white):QBrush(Qt::black));
cursor.insertText("@" + userName, mentionFormat); cursor.insertText("@" + userName, mentionFormat);
message = message.mid(mention.size()); message = message.mid(mention.size());
@ -231,6 +227,12 @@ void ChatView::appendMessage(QString message, QString sender, UserLevelFlags use
verticalScrollBar()->setValue(verticalScrollBar()->maximum()); 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 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

@ -37,6 +37,7 @@ private:
void appendCardTag(QTextCursor &cursor, const QString &cardName); void appendCardTag(QTextCursor &cursor, const QString &cardName);
void appendUrlTag(QTextCursor &cursor, QString url); void appendUrlTag(QTextCursor &cursor, QString url);
QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName); QString getNameFromUserList(QMap<QString, UserListTWI *> &userList, QString &userName);
QColor getCustomMentionColor();
private slots: private slots:
void openLink(const QUrl &link); void openLink(const QUrl &link);
public: public:

View file

@ -566,7 +566,6 @@ void DeckEditorSettingsPage::radioPriceTagSourceClicked(bool checked)
MessagesSettingsPage::MessagesSettingsPage() MessagesSettingsPage::MessagesSettingsPage()
{ {
chatMentionCheckBox.setChecked(settingsCache->getChatMention()); chatMentionCheckBox.setChecked(settingsCache->getChatMention());
connect(&chatMentionCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setChatMention(int))); connect(&chatMentionCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setChatMention(int)));
@ -574,18 +573,18 @@ MessagesSettingsPage::MessagesSettingsPage()
connect(&ignoreUnregUsersMainChat, SIGNAL(stateChanged(int)), settingsCache, SLOT(setIgnoreUnregisteredUsers(int))); connect(&ignoreUnregUsersMainChat, SIGNAL(stateChanged(int)), settingsCache, SLOT(setIgnoreUnregisteredUsers(int)));
invertMentionForeground.setChecked(settingsCache->getChatMentionForeground()); 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 = new QLineEdit();
mentionColor->setText(settingsCache->getChatMentionColor()); 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; QGridLayout *chatGrid = new QGridLayout;
chatGrid->addWidget(&chatMentionCheckBox, 0, 0); chatGrid->addWidget(&chatMentionCheckBox, 0, 0);
chatGrid->addWidget(&mentionColorLabel, 1, 0); chatGrid->addWidget(&invertMentionForeground, 0, 1);
chatGrid->addWidget(mentionColor, 1, 1); chatGrid->addWidget(mentionColor, 0, 2);
chatGrid->addWidget(&invertMentionForeground, 2, 0); chatGrid->addWidget(&ignoreUnregUsersMainChat, 1, 0);
chatGrid->addWidget(&ignoreUnregUsersMainChat, 3, 0);
chatGroupBox = new QGroupBox; chatGroupBox = new QGroupBox;
chatGroupBox->setLayout(chatGrid); chatGroupBox->setLayout(chatGrid);
@ -624,6 +623,25 @@ MessagesSettingsPage::MessagesSettingsPage()
retranslateUi(); 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() void MessagesSettingsPage::storeSettings()
{ {
QSettings settings; QSettings settings;
@ -656,11 +674,10 @@ void MessagesSettingsPage::retranslateUi()
aAdd->setText(tr("&Add")); aAdd->setText(tr("&Add"));
aRemove->setText(tr("&Remove")); aRemove->setText(tr("&Remove"));
chatGroupBox->setTitle(tr("Chat settings")); 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")); messageShortcuts->setTitle(tr("In-game message macros"));
ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat")); ignoreUnregUsersMainChat.setText(tr("Ignore unregistered users in main chat"));
mentionColorLabel.setText(tr("Username/Mention color:")); invertMentionForeground.setText(tr("Invert text color"));
invertMentionForeground.setText(tr("Invert mention text color (white)"));
} }
DlgSettings::DlgSettings(QWidget *parent) DlgSettings::DlgSettings(QWidget *parent)

View file

@ -156,6 +156,8 @@ public:
private slots: private slots:
void actAdd(); void actAdd();
void actRemove(); void actRemove();
void updateColor(const QString &value);
void updateTextColor(int value);
private: private:
QListWidget *messageList; QListWidget *messageList;
QAction *aAdd; QAction *aAdd;
@ -166,9 +168,9 @@ private:
QGroupBox *chatGroupBox; QGroupBox *chatGroupBox;
QGroupBox *messageShortcuts; QGroupBox *messageShortcuts;
QLineEdit *mentionColor; QLineEdit *mentionColor;
QLabel mentionColorLabel;
void storeSettings(); void storeSettings();
void updateMentionPreview();
}; };
class DlgSettings : public QDialog { class DlgSettings : public QDialog {