Better Highlights (#1320)

* Support for user-defined sounds and colors

* Make color & sound columns selectable

* Add custom row for subscription highlights

* Add subscriptions to custom highlights and centrally manage highlight colors

* Dynamically update message highlight colors
This commit is contained in:
Leon Richardt
2020-01-25 11:03:10 +01:00
committed by pajlada
parent 00414eb779
commit 5957551d06
29 changed files with 1822 additions and 187 deletions
@@ -0,0 +1,113 @@
#include "controllers/highlights/HighlightPhrase.hpp"
namespace chatterino {
bool HighlightPhrase::operator==(const HighlightPhrase &other) const
{
return std::tie(this->pattern_, this->hasSound_, this->hasAlert_,
this->isRegex_, this->isCaseSensitive_, this->soundUrl_,
this->color_) == std::tie(other.pattern_, other.hasSound_,
other.hasAlert_, other.isRegex_,
other.isCaseSensitive_,
other.soundUrl_, other.color_);
}
/**
* @brief Create a new HighlightPhrase.
*
* Use this constructor when updating an existing HighlightPhrase's color.
*/
HighlightPhrase::HighlightPhrase(const QString &pattern, bool hasAlert,
bool hasSound, bool isRegex,
bool isCaseSensitive, const QString &soundUrl,
QColor color)
: pattern_(pattern)
, hasAlert_(hasAlert)
, hasSound_(hasSound)
, isRegex_(isRegex)
, isCaseSensitive_(isCaseSensitive)
, soundUrl_(soundUrl)
, regex_(isRegex_ ? pattern
: "\\b" + QRegularExpression::escape(pattern) + "\\b",
QRegularExpression::UseUnicodePropertiesOption |
(isCaseSensitive_ ? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption))
{
this->color_ = std::make_shared<QColor>(color);
}
/**
* @brief Create a new HighlightPhrase.
*
* Use this constructor when creating a new HighlightPhrase.
*/
HighlightPhrase::HighlightPhrase(const QString &pattern, bool hasAlert,
bool hasSound, bool isRegex,
bool isCaseSensitive, const QString &soundUrl,
std::shared_ptr<QColor> color)
: pattern_(pattern)
, hasAlert_(hasAlert)
, hasSound_(hasSound)
, isRegex_(isRegex)
, isCaseSensitive_(isCaseSensitive)
, soundUrl_(soundUrl)
, color_(color)
, regex_(isRegex_ ? pattern
: "\\b" + QRegularExpression::escape(pattern) + "\\b",
QRegularExpression::UseUnicodePropertiesOption |
(isCaseSensitive_ ? QRegularExpression::NoPatternOption
: QRegularExpression::CaseInsensitiveOption))
{
}
const QString &HighlightPhrase::getPattern() const
{
return this->pattern_;
}
bool HighlightPhrase::hasAlert() const
{
return this->hasAlert_;
}
bool HighlightPhrase::hasSound() const
{
return this->hasSound_;
}
bool HighlightPhrase::hasCustomSound() const
{
return !this->soundUrl_.isEmpty();
}
bool HighlightPhrase::isRegex() const
{
return this->isRegex_;
}
bool HighlightPhrase::isValid() const
{
return !this->pattern_.isEmpty() && this->regex_.isValid();
}
bool HighlightPhrase::isMatch(const QString &subject) const
{
return this->isValid() && this->regex_.match(subject).hasMatch();
}
bool HighlightPhrase::isCaseSensitive() const
{
return this->isCaseSensitive_;
}
const QUrl &HighlightPhrase::getSoundUrl() const
{
return this->soundUrl_;
}
const std::shared_ptr<QColor> HighlightPhrase::getColor() const
{
return this->color_;
}
} // namespace chatterino