From 097f4ccb3a087aa75910809304401c9e89ff8740 Mon Sep 17 00:00:00 2001 From: fourtf Date: Wed, 15 Apr 2020 23:15:45 +0200 Subject: [PATCH] refined highlight and added bits highlights --- src/Application.cpp | 5 ++ src/controllers/highlights/HighlightModel.cpp | 78 ++++++++++++++++--- src/controllers/highlights/HighlightModel.hpp | 2 + .../highlights/HighlightPhrase.cpp | 2 + .../highlights/HighlightPhrase.hpp | 1 + src/messages/Message.cpp | 6 ++ src/messages/Message.hpp | 1 + src/messages/layouts/MessageLayout.cpp | 9 +++ src/providers/colors/ColorProvider.cpp | 29 +++++-- src/providers/colors/ColorProvider.hpp | 7 +- src/providers/twitch/TwitchMessageBuilder.cpp | 7 ++ src/singletons/Settings.hpp | 11 +++ src/widgets/Scrollbar.cpp | 12 ++- src/widgets/helper/ScrollbarHighlight.cpp | 8 +- src/widgets/helper/ScrollbarHighlight.hpp | 4 +- .../settingspages/HighlightingPage.cpp | 4 +- 16 files changed, 164 insertions(+), 22 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index a72d9bb3..6934ebbd 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -120,6 +120,11 @@ int Application::run(QApplication &qtApp) getSettings()->moderationActions.delayedItemsChanged.connect( [this] { this->windows->forceLayoutChannelViews(); }); + getSettings()->highlightedMessages.delayedItemsChanged.connect( + [this] { this->windows->forceLayoutChannelViews(); }); + getSettings()->highlightedUsers.delayedItemsChanged.connect( + [this] { this->windows->forceLayoutChannelViews(); }); + return qtApp.exec(); } diff --git a/src/controllers/highlights/HighlightModel.cpp b/src/controllers/highlights/HighlightModel.cpp index ef134c12..e1b6e410 100644 --- a/src/controllers/highlights/HighlightModel.cpp +++ b/src/controllers/highlights/HighlightModel.cpp @@ -2,6 +2,7 @@ #include "Application.hpp" #include "singletons/Settings.hpp" +#include "singletons/WindowManager.hpp" #include "util/StandardItemHelper.hpp" namespace chatterino { @@ -88,10 +89,11 @@ void HighlightModel::afterInit() QUrl(getSettings()->whisperHighlightSoundUrl.getValue()); setFilePathItem(whisperRow[Column::SoundPath], whisperSound, false); - auto whisperColor = ColorProvider::instance().color(ColorType::Whisper); - setColorItem(whisperRow[Column::Color], *whisperColor, false); + // auto whisperColor = ColorProvider::instance().color(ColorType::Whisper); + // setColorItem(whisperRow[Column::Color], *whisperColor, false); + whisperRow[Column::Color]->setFlags(Qt::ItemFlag::NoItemFlags); - this->insertCustomRow(whisperRow, 1); + this->insertCustomRow(whisperRow, WHISPER_ROW); // Highlight settings for subscription messages std::vector subRow = this->createRow(); @@ -113,6 +115,31 @@ void HighlightModel::afterInit() setColorItem(subRow[Column::Color], *subColor, false); this->insertCustomRow(subRow, 2); + + // Highlight settings for redeemed highlight messages + std::vector redeemedRow = this->createRow(); + setBoolItem(redeemedRow[Column::Pattern], + getSettings()->enableRedeemedHighlight.getValue(), true, false); + redeemedRow[Column::Pattern]->setData("Highlights redeemed with Bits", + Qt::DisplayRole); + setBoolItem(redeemedRow[Column::FlashTaskbar], + getSettings()->enableRedeemedHighlightTaskbar.getValue(), true, + false); + setBoolItem(redeemedRow[Column::PlaySound], + getSettings()->enableRedeemedHighlightSound.getValue(), true, + false); + redeemedRow[Column::UseRegex]->setFlags(0); + redeemedRow[Column::CaseSensitive]->setFlags(0); + + QUrl RedeemedSound = + QUrl(getSettings()->redeemedHighlightSoundUrl.getValue()); + setFilePathItem(redeemedRow[Column::SoundPath], RedeemedSound, false); + + auto RedeemedColor = + ColorProvider::instance().color(ColorType::RedeemedHighlight); + setColorItem(redeemedRow[Column::Color], *RedeemedColor, false); + + this->insertCustomRow(redeemedRow, 3); } void HighlightModel::customRowSetData(const std::vector &row, @@ -128,7 +155,7 @@ void HighlightModel::customRowSetData(const std::vector &row, { getSettings()->enableSelfHighlight.setValue(value.toBool()); } - else if (rowIndex == 1) + else if (rowIndex == WHISPER_ROW) { getSettings()->enableWhisperHighlight.setValue( value.toBool()); @@ -137,6 +164,11 @@ void HighlightModel::customRowSetData(const std::vector &row, { getSettings()->enableSubHighlight.setValue(value.toBool()); } + else if (rowIndex == 3) + { + getSettings()->enableRedeemedHighlight.setValue( + value.toBool()); + } } } break; @@ -148,7 +180,7 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableSelfHighlightTaskbar.setValue( value.toBool()); } - else if (rowIndex == 1) + else if (rowIndex == WHISPER_ROW) { getSettings()->enableWhisperHighlightTaskbar.setValue( value.toBool()); @@ -158,6 +190,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableSubHighlightTaskbar.setValue( value.toBool()); } + else if (rowIndex == 3) + { + getSettings()->enableRedeemedHighlightTaskbar.setValue( + value.toBool()); + } } } break; @@ -169,7 +206,7 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableSelfHighlightSound.setValue( value.toBool()); } - else if (rowIndex == 1) + else if (rowIndex == WHISPER_ROW) { getSettings()->enableWhisperHighlightSound.setValue( value.toBool()); @@ -179,6 +216,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->enableSubHighlightSound.setValue( value.toBool()); } + else if (rowIndex == 3) + { + getSettings()->enableRedeemedHighlightSound.setValue( + value.toBool()); + } } } break; @@ -199,7 +241,7 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->selfHighlightSoundUrl.setValue( value.toString()); } - else if (rowIndex == 1) + else if (rowIndex == WHISPER_ROW) { getSettings()->whisperHighlightSoundUrl.setValue( value.toString()); @@ -209,6 +251,11 @@ void HighlightModel::customRowSetData(const std::vector &row, getSettings()->subHighlightSoundUrl.setValue( value.toString()); } + else if (rowIndex == 3) + { + getSettings()->redeemedHighlightSoundUrl.setValue( + value.toString()); + } } } break; @@ -221,18 +268,27 @@ void HighlightModel::customRowSetData(const std::vector &row, { getSettings()->selfHighlightColor.setValue(colorName); } - else if (rowIndex == 1) - { - getSettings()->whisperHighlightColor.setValue(colorName); - } + // else if (rowIndex == WHISPER_ROW) + // { + // getSettings()->whisperHighlightColor.setValue(colorName); + // } else if (rowIndex == 2) { getSettings()->subHighlightColor.setValue(colorName); } + else if (rowIndex == 3) + { + getSettings()->redeemedHighlightColor.setValue(colorName); + const_cast(ColorProvider::instance()) + .updateColor(ColorType::RedeemedHighlight, + QColor(colorName)); + } } } break; } + + getApp()->windows->forceLayoutChannelViews(); } } // namespace chatterino diff --git a/src/controllers/highlights/HighlightModel.hpp b/src/controllers/highlights/HighlightModel.hpp index aa37b4ff..92acd2e0 100644 --- a/src/controllers/highlights/HighlightModel.hpp +++ b/src/controllers/highlights/HighlightModel.hpp @@ -23,6 +23,8 @@ public: Color = 6 }; + constexpr static int WHISPER_ROW = 1; + protected: // turn a vector item into a model row virtual HighlightPhrase getItemFromRow( diff --git a/src/controllers/highlights/HighlightPhrase.cpp b/src/controllers/highlights/HighlightPhrase.cpp index 94529b62..5ffd5b36 100644 --- a/src/controllers/highlights/HighlightPhrase.cpp +++ b/src/controllers/highlights/HighlightPhrase.cpp @@ -3,6 +3,8 @@ namespace chatterino { QColor HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR = QColor(127, 63, 73, 127); +QColor HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR = + QColor(28, 126, 141, 90); QColor HighlightPhrase::FALLBACK_SUB_COLOR = QColor(196, 102, 255, 100); bool HighlightPhrase::operator==(const HighlightPhrase &other) const diff --git a/src/controllers/highlights/HighlightPhrase.hpp b/src/controllers/highlights/HighlightPhrase.hpp index cbabb3e4..268ae354 100644 --- a/src/controllers/highlights/HighlightPhrase.hpp +++ b/src/controllers/highlights/HighlightPhrase.hpp @@ -75,6 +75,7 @@ public: * Qt>=5.13. */ static QColor FALLBACK_HIGHLIGHT_COLOR; + static QColor FALLBACK_REDEEMED_HIGHLIGHT_COLOR; static QColor FALLBACK_SUB_COLOR; private: diff --git a/src/messages/Message.cpp b/src/messages/Message.cpp index 218fa3a7..912eeefe 100644 --- a/src/messages/Message.cpp +++ b/src/messages/Message.cpp @@ -35,6 +35,12 @@ SBHighlight Message::getScrollBarHighlight() const return SBHighlight( ColorProvider::instance().color(ColorType::Subscription)); } + else if (this->flags.has(MessageFlag::RedeemedHighlight)) + { + return SBHighlight( + ColorProvider::instance().color(ColorType::RedeemedHighlight), + SBHighlight::Default, true); + } return SBHighlight(); } diff --git a/src/messages/Message.hpp b/src/messages/Message.hpp index 3b5bb97a..e9456dc8 100644 --- a/src/messages/Message.hpp +++ b/src/messages/Message.hpp @@ -34,6 +34,7 @@ enum class MessageFlag : uint32_t { HighlightedWhisper = (1 << 17), Debug = (1 << 18), Similar = (1 << 19), + RedeemedHighlight = (1 << 20), }; using MessageFlags = FlagsEnum; diff --git a/src/messages/layouts/MessageLayout.cpp b/src/messages/layouts/MessageLayout.cpp index c048bd62..e7eaa2ef 100644 --- a/src/messages/layouts/MessageLayout.cpp +++ b/src/messages/layouts/MessageLayout.cpp @@ -263,6 +263,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/) { auto app = getApp(); + auto settings = getSettings(); QPainter painter(buffer); painter.setRenderHint(QPainter::SmoothPixmapTransform); @@ -296,6 +297,14 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, backgroundColor, *ColorProvider::instance().color(ColorType::Subscription)); } + else if (this->message_->flags.has(MessageFlag::RedeemedHighlight) && + settings->enableRedeemedHighlight.getValue()) + { + // Blend highlight color with usual background color + backgroundColor = blendColors( + backgroundColor, + *ColorProvider::instance().color(ColorType::RedeemedHighlight)); + } else if (this->message_->flags.has(MessageFlag::AutoMod)) { backgroundColor = QColor("#404040"); diff --git a/src/providers/colors/ColorProvider.cpp b/src/providers/colors/ColorProvider.cpp index 43d65124..ad35db05 100644 --- a/src/providers/colors/ColorProvider.cpp +++ b/src/providers/colors/ColorProvider.cpp @@ -105,16 +105,35 @@ void ColorProvider::initTypeColorMap() std::make_shared( HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)}); } + + customColor = getSettings()->redeemedHighlightColor; + if (QColor(customColor).isValid()) + { + this->typeColorMap_.insert({ColorType::RedeemedHighlight, + std::make_shared(customColor)}); + } + else + { + this->typeColorMap_.insert( + {ColorType::RedeemedHighlight, + std::make_shared( + HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR)}); + } } void ColorProvider::initDefaultColors() { // Init default colors - this->defaultColors_.emplace_back(31, 141, 43, 127); // Green-ish - this->defaultColors_.emplace_back(28, 126, 141, 127); // Blue-ish - this->defaultColors_.emplace_back(136, 141, 49, 127); // Golden-ish - this->defaultColors_.emplace_back(143, 48, 24, 127); // Red-ish - this->defaultColors_.emplace_back(28, 141, 117, 127); // Cyan-ish + this->defaultColors_.emplace_back(75, 127, 107, 100); // Teal + this->defaultColors_.emplace_back(105, 127, 63, 100); // Olive + this->defaultColors_.emplace_back(63, 83, 127, 100); // Blue + this->defaultColors_.emplace_back(72, 127, 63, 100); // Green + + this->defaultColors_.emplace_back(31, 141, 43, 115); // Green + this->defaultColors_.emplace_back(28, 126, 141, 90); // Blue + this->defaultColors_.emplace_back(136, 141, 49, 90); // Golden + this->defaultColors_.emplace_back(143, 48, 24, 127); // Red + this->defaultColors_.emplace_back(28, 141, 117, 90); // Cyan this->defaultColors_.push_back(HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR); this->defaultColors_.push_back(HighlightPhrase::FALLBACK_SUB_COLOR); diff --git a/src/providers/colors/ColorProvider.hpp b/src/providers/colors/ColorProvider.hpp index e038b17f..1595c53d 100644 --- a/src/providers/colors/ColorProvider.hpp +++ b/src/providers/colors/ColorProvider.hpp @@ -2,7 +2,12 @@ namespace chatterino { -enum class ColorType { SelfHighlight, Subscription, Whisper }; +enum class ColorType { + SelfHighlight, + Subscription, + Whisper, + RedeemedHighlight +}; class ColorProvider { diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index f8e2b279..02a45a8f 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -295,6 +295,13 @@ MessagePtr TwitchMessageBuilder::build() this->historicalMessage_ = this->tags.contains("historical"); + if (this->tags.contains("msg-id") && + this->tags["msg-id"].toString().split(';').contains( + "highlighted-message")) + { + this->message().flags.set(MessageFlag::RedeemedHighlight); + } + // timestamp if (this->historicalMessage_) { diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index c95b0e50..46f95075 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -205,6 +205,17 @@ public: QStringSetting whisperHighlightColor = { "/highlighting/whisperHighlightColor", ""}; + BoolSetting enableRedeemedHighlight = { + "/highlighting/redeemedHighlight/highlighted", true}; + BoolSetting enableRedeemedHighlightSound = { + "/highlighting/redeemedHighlight/enableSound", false}; + BoolSetting enableRedeemedHighlightTaskbar = { + "/highlighting/redeemedHighlight/enableTaskbarFlashing", false}; + QStringSetting redeemedHighlightSoundUrl = { + "/highlighting/redeemedHighlightSoundUrl", ""}; + QStringSetting redeemedHighlightColor = { + "/highlighting/redeemedHighlightColor", ""}; + BoolSetting enableSubHighlight = { "/highlighting/subHighlight/subsHighlighted", true}; BoolSetting enableSubHighlightSound = { diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index 9af6c307..7638b5a7 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -3,6 +3,7 @@ #include "Application.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" +#include "singletons/WindowManager.hpp" #include "widgets/helper/ChannelView.hpp" #include @@ -242,6 +243,8 @@ void Scrollbar::paintEvent(QPaintEvent *) QPainter painter(this); painter.fillRect(rect(), this->theme->scrollbars.background); + bool enableRedeemedHighlights = getSettings()->enableRedeemedHighlight; + // painter.fillRect(QRect(xOffset, 0, width(), this->buttonHeight), // this->themeManager->ScrollbarArrow); // painter.fillRect(QRect(xOffset, height() - this->buttonHeight, @@ -274,7 +277,8 @@ void Scrollbar::paintEvent(QPaintEvent *) int w = this->width(); float y = 0; float dY = float(this->height()) / float(snapshotLength); - int highlightHeight = int(std::ceil(dY)); + int highlightHeight = + int(std::ceil(std::max(this->scale() * 2, dY))); for (size_t i = 0; i < snapshotLength; i++) { @@ -282,7 +286,13 @@ void Scrollbar::paintEvent(QPaintEvent *) if (!highlight.isNull()) { + if (highlight.isRedeemedHighlight() && !enableRedeemedHighlights) + { + continue; + } + QColor color = highlight.getColor(); + color.setAlpha(255); switch (highlight.getStyle()) { diff --git a/src/widgets/helper/ScrollbarHighlight.cpp b/src/widgets/helper/ScrollbarHighlight.cpp index 02aafff2..ab18354e 100644 --- a/src/widgets/helper/ScrollbarHighlight.cpp +++ b/src/widgets/helper/ScrollbarHighlight.cpp @@ -13,9 +13,10 @@ ScrollbarHighlight::ScrollbarHighlight() } ScrollbarHighlight::ScrollbarHighlight(const std::shared_ptr color, - Style style) + Style style, bool isRedeemedHighlight) : color_(color) , style_(style) + , isRedeemedHighlight_(isRedeemedHighlight) { } @@ -29,6 +30,11 @@ ScrollbarHighlight::Style ScrollbarHighlight::getStyle() const return this->style_; } +bool ScrollbarHighlight::isRedeemedHighlight() const +{ + return this->isRedeemedHighlight_; +} + bool ScrollbarHighlight::isNull() const { return this->style_ == None; diff --git a/src/widgets/helper/ScrollbarHighlight.hpp b/src/widgets/helper/ScrollbarHighlight.hpp index 22fbc48f..50fc0c93 100644 --- a/src/widgets/helper/ScrollbarHighlight.hpp +++ b/src/widgets/helper/ScrollbarHighlight.hpp @@ -17,15 +17,17 @@ public: ScrollbarHighlight(); ScrollbarHighlight(const std::shared_ptr color, - Style style = Default); + Style style = Default, bool isRedeemedHighlight = false); QColor getColor() const; Style getStyle() const; + bool isRedeemedHighlight() const; bool isNull() const; private: std::shared_ptr color_; Style style_; + bool isRedeemedHighlight_; }; } // namespace chatterino diff --git a/src/widgets/settingspages/HighlightingPage.cpp b/src/widgets/settingspages/HighlightingPage.cpp index 2ba16f62..f6076d6b 100644 --- a/src/widgets/settingspages/HighlightingPage.cpp +++ b/src/widgets/settingspages/HighlightingPage.cpp @@ -29,7 +29,6 @@ namespace chatterino { HighlightingPage::HighlightingPage() { - auto app = getApp(); LayoutCreator layoutCreator(this); auto layout = layoutCreator.emplace().withoutMargin(); @@ -228,7 +227,8 @@ void HighlightingPage::tableCellClicked(const QModelIndex &clicked, Qt::CheckStateRole); } } - else if (clicked.column() == Column::Color) + else if (clicked.column() == Column::Color && + clicked.row() != HighlightModel::WHISPER_ROW) { auto initial = view->getModel()->data(clicked, Qt::DecorationRole).value();