refined highlight and added bits highlights

This commit is contained in:
fourtf 2020-04-15 23:15:45 +02:00
parent ebfcb49e8c
commit 097f4ccb3a
16 changed files with 164 additions and 22 deletions

View file

@ -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();
}

View file

@ -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<QStandardItem *> 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<QStandardItem *> 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<QStandardItem *> &row,
@ -128,7 +155,7 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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<QStandardItem *> &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 &>(ColorProvider::instance())
.updateColor(ColorType::RedeemedHighlight,
QColor(colorName));
}
}
}
break;
}
getApp()->windows->forceLayoutChannelViews();
}
} // namespace chatterino

View file

@ -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(

View file

@ -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

View file

@ -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:

View file

@ -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();
}

View file

@ -34,6 +34,7 @@ enum class MessageFlag : uint32_t {
HighlightedWhisper = (1 << 17),
Debug = (1 << 18),
Similar = (1 << 19),
RedeemedHighlight = (1 << 20),
};
using MessageFlags = FlagsEnum<MessageFlag>;

View file

@ -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");

View file

@ -105,16 +105,35 @@ void ColorProvider::initTypeColorMap()
std::make_shared<QColor>(
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)});
}
customColor = getSettings()->redeemedHighlightColor;
if (QColor(customColor).isValid())
{
this->typeColorMap_.insert({ColorType::RedeemedHighlight,
std::make_shared<QColor>(customColor)});
}
else
{
this->typeColorMap_.insert(
{ColorType::RedeemedHighlight,
std::make_shared<QColor>(
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);

View file

@ -2,7 +2,12 @@
namespace chatterino {
enum class ColorType { SelfHighlight, Subscription, Whisper };
enum class ColorType {
SelfHighlight,
Subscription,
Whisper,
RedeemedHighlight
};
class ColorProvider
{

View file

@ -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_)
{

View file

@ -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 = {

View file

@ -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 <QDebug>
@ -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<float>(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())
{

View file

@ -13,9 +13,10 @@ ScrollbarHighlight::ScrollbarHighlight()
}
ScrollbarHighlight::ScrollbarHighlight(const std::shared_ptr<QColor> 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;

View file

@ -17,15 +17,17 @@ public:
ScrollbarHighlight();
ScrollbarHighlight(const std::shared_ptr<QColor> 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<QColor> color_;
Style style_;
bool isRedeemedHighlight_;
};
} // namespace chatterino

View file

@ -29,7 +29,6 @@ namespace chatterino {
HighlightingPage::HighlightingPage()
{
auto app = getApp();
LayoutCreator<HighlightingPage> layoutCreator(this);
auto layout = layoutCreator.emplace<QVBoxLayout>().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<QColor>();