Commit e0b71d3b authored by Zach's avatar Zach
Browse files

Merge pull request #1257 from ctrlaltca/messageparser

Chatview: split message parser and add "highlight words"
parents 1d425f5b ef831d27
This diff is collapsed.
...@@ -27,8 +27,10 @@ private: ...@@ -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: ...@@ -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();
......
...@@ -580,6 +580,9 @@ MessagesSettingsPage::MessagesSettingsPage() ...@@ -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() ...@@ -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);
...@@ -602,6 +610,20 @@ MessagesSettingsPage::MessagesSettingsPage() ...@@ -602,6 +610,20 @@ MessagesSettingsPage::MessagesSettingsPage()
chatGrid->addWidget(&mentionPopups, 4, 0); chatGrid->addWidget(&mentionPopups, 4, 0);
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;
...@@ -628,11 +650,12 @@ MessagesSettingsPage::MessagesSettingsPage() ...@@ -628,11 +650,12 @@ MessagesSettingsPage::MessagesSettingsPage()
messageShortcuts = new QGroupBox; messageShortcuts = new QGroupBox;
messageShortcuts->setLayout(messageListLayout); messageShortcuts->setLayout(messageListLayout);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
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) { ...@@ -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() ...@@ -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"));
} }
......
...@@ -160,24 +160,33 @@ private slots: ...@@ -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 {
......
...@@ -56,7 +56,9 @@ SettingsCache::SettingsCache() ...@@ -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() ...@@ -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) { ...@@ -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) { ...@@ -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;
......
...@@ -65,7 +65,9 @@ private: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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: ...@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment