diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index 676369169..329659fab 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -8,7 +8,7 @@ namespace chatterino { // commandmodel HighlightModel::HighlightModel(QObject *parent) - : SignalVectorModel(4, parent) + : SignalVectorModel(5, parent) { } @@ -16,12 +16,13 @@ HighlightModel::HighlightModel(QObject *parent) HighlightPhrase HighlightModel::getItemFromRow( std::vector &row, const HighlightPhrase &original) { - // key, alert, sound, regex + // key, alert, sound, regex, case-sensitivity return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(), row[1]->data(Qt::CheckStateRole).toBool(), row[2]->data(Qt::CheckStateRole).toBool(), - row[3]->data(Qt::CheckStateRole).toBool()}; + row[3]->data(Qt::CheckStateRole).toBool(), + row[4]->data(Qt::CheckStateRole).toBool()}; } // turns a row in the model into a vector item @@ -32,6 +33,7 @@ void HighlightModel::getRowFromItem(const HighlightPhrase &item, setBoolItem(row[1], item.getAlert()); setBoolItem(row[2], item.getSound()); setBoolItem(row[3], item.isRegex()); + setBoolItem(row[4], item.isCaseSensitive()); } void HighlightModel::afterInit() diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index 5db0c6999..0214fb000 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -15,21 +15,24 @@ public: bool operator==(const HighlightPhrase &other) const { return std::tie(this->pattern_, this->sound_, this->alert_, - this->isRegex_) == std::tie(other.pattern_, - other.sound_, other.alert_, - other.isRegex_); + this->isRegex_, this->caseSensitive_) == + std::tie(other.pattern_, other.sound_, other.alert_, + other.isRegex_, other.caseSensitive_); } HighlightPhrase(const QString &pattern, bool alert, bool sound, - bool isRegex) + bool isRegex, bool caseSensitive) : pattern_(pattern) , alert_(alert) , sound_(sound) , isRegex_(isRegex) - , regex_(isRegex_ ? pattern - : "\\b" + QRegularExpression::escape(pattern) + "\\b", - QRegularExpression::CaseInsensitiveOption | - QRegularExpression::UseUnicodePropertiesOption) + , caseSensitive_(caseSensitive) + , regex_( + isRegex_ ? pattern + : "\\b" + QRegularExpression::escape(pattern) + "\\b", + QRegularExpression::UseUnicodePropertiesOption | + (caseSensitive_ ? QRegularExpression::NoPatternOption + : QRegularExpression::CaseInsensitiveOption)) { } @@ -60,11 +63,17 @@ public: return this->isValid() && this->regex_.match(subject).hasMatch(); } + bool isCaseSensitive() const + { + return this->caseSensitive_; + } + private: QString pattern_; bool alert_; bool sound_; bool isRegex_; + bool caseSensitive_; QRegularExpression regex_; }; } // namespace chatterino @@ -82,6 +91,7 @@ struct Serialize { chatterino::rj::set(ret, "alert", value.getAlert(), a); chatterino::rj::set(ret, "sound", value.getSound(), a); chatterino::rj::set(ret, "regex", value.isRegex(), a); + chatterino::rj::set(ret, "case", value.isCaseSensitive(), a); return ret; } @@ -93,20 +103,24 @@ struct Deserialize { { if (!value.IsObject()) { - return chatterino::HighlightPhrase(QString(), true, false, false); + return chatterino::HighlightPhrase(QString(), true, false, false, + false); } QString _pattern; bool _alert = true; bool _sound = false; bool _isRegex = false; + bool _caseSensitive = false; chatterino::rj::getSafe(value, "pattern", _pattern); chatterino::rj::getSafe(value, "alert", _alert); chatterino::rj::getSafe(value, "sound", _sound); chatterino::rj::getSafe(value, "regex", _isRegex); + chatterino::rj::getSafe(value, "case", _caseSensitive); - return chatterino::HighlightPhrase(_pattern, _alert, _sound, _isRegex); + return chatterino::HighlightPhrase(_pattern, _alert, _sound, + _isRegex, _caseSensitive); } }; diff --git a/src/controllers/highlights/UserHighlightModel.cpp b/src/controllers/highlights/UserHighlightModel.cpp index e04c3403e..5e3ed12c5 100644 --- a/src/controllers/highlights/UserHighlightModel.cpp +++ b/src/controllers/highlights/UserHighlightModel.cpp @@ -8,7 +8,7 @@ namespace chatterino { // commandmodel UserHighlightModel::UserHighlightModel(QObject *parent) - : SignalVectorModel(4, parent) + : SignalVectorModel(5, parent) { } @@ -21,7 +21,8 @@ HighlightPhrase UserHighlightModel::getItemFromRow( return HighlightPhrase{row[0]->data(Qt::DisplayRole).toString(), row[1]->data(Qt::CheckStateRole).toBool(), row[2]->data(Qt::CheckStateRole).toBool(), - row[3]->data(Qt::CheckStateRole).toBool()}; + row[3]->data(Qt::CheckStateRole).toBool(), + row[4]->data(Qt::CheckStateRole).toBool()}; } // row into vector item @@ -32,6 +33,7 @@ void UserHighlightModel::getRowFromItem(const HighlightPhrase &item, setBoolItem(row[1], item.getAlert()); setBoolItem(row[2], item.getSound()); setBoolItem(row[3], item.isRegex()); + setBoolItem(row[4], item.isCaseSensitive()); } } // namespace chatterino diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 9b8d30cc2..0afcb6a68 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -952,7 +952,7 @@ void TwitchMessageBuilder::parseHighlights() { HighlightPhrase selfHighlight( currentUsername, getSettings()->enableSelfHighlightTaskbar, - getSettings()->enableSelfHighlightSound, false); + getSettings()->enableSelfHighlightSound, false, false); activeHighlights.emplace_back(std::move(selfHighlight)); } diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index ec970e2dc..3fda3fd71 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -57,7 +57,7 @@ HighlightingPage::HighlightingPage() view->addRegexHelpLink(); view->setTitles({"Pattern", "Flash\ntaskbar", "Play\nsound", - "Enable\nregex"}); + "Enable\nregex", "Case-\nsensitive"}); view->getTableView()->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed); view->getTableView()->horizontalHeader()->setSectionResizeMode( @@ -71,8 +71,8 @@ HighlightingPage::HighlightingPage() }); view->addButtonPressed.connect([] { - getApp()->highlights->phrases.appendItem( - HighlightPhrase{"my phrase", true, false, false}); + getApp()->highlights->phrases.appendItem(HighlightPhrase{ + "my phrase", true, false, false, false}); }); } @@ -87,6 +87,9 @@ HighlightingPage::HighlightingPage() .getElement(); view->addRegexHelpLink(); + + // Case-sensitivity doesn't make sense for user names so it is + // set to "false" by default & no checkbox is shown view->setTitles({"Username", "Flash\ntaskbar", "Play\nsound", "Enable\nregex"}); view->getTableView()->horizontalHeader()->setSectionResizeMode( @@ -103,7 +106,7 @@ HighlightingPage::HighlightingPage() view->addButtonPressed.connect([] { getApp()->highlights->highlightedUsers.appendItem( - HighlightPhrase{"highlighted user", true, false, + HighlightPhrase{"highlighted user", true, false, false, false}); }); }