refactor: remove ColorProvider::setColor (#5112)
We now either: 1) Rely on the setting updating the color 2) Use ColorProvider::color to set the underlying color
This commit is contained in:
@@ -112,6 +112,7 @@
|
|||||||
- Dev: Refactored the SplitOverlay code. (#5082)
|
- Dev: Refactored the SplitOverlay code. (#5082)
|
||||||
- Dev: Refactored the TwitchBadges structure, making it less of a singleton. (#5096)
|
- Dev: Refactored the TwitchBadges structure, making it less of a singleton. (#5096)
|
||||||
- Dev: Refactored the ChatterinoBadges structure, making it less of a singleton. (#5103)
|
- Dev: Refactored the ChatterinoBadges structure, making it less of a singleton. (#5103)
|
||||||
|
- Dev: Refactored the ColorProvider class a bit. (#5112)
|
||||||
- Dev: Moved the Network files to their own folder. (#5089)
|
- Dev: Moved the Network files to their own folder. (#5089)
|
||||||
- Dev: Fixed deadlock and use-after-free in tests. (#4981)
|
- Dev: Fixed deadlock and use-after-free in tests. (#4981)
|
||||||
- Dev: Moved all `.clang-format` files to the root directory. (#5037)
|
- Dev: Moved all `.clang-format` files to the root directory. (#5037)
|
||||||
|
|||||||
@@ -465,8 +465,6 @@ void HighlightModel::customRowSetData(const std::vector<QStandardItem *> &row,
|
|||||||
const auto setColor = [&](auto &setting, ColorType ty) {
|
const auto setColor = [&](auto &setting, ColorType ty) {
|
||||||
auto color = value.value<QColor>();
|
auto color = value.value<QColor>();
|
||||||
setting.setValue(color.name(QColor::HexArgb));
|
setting.setValue(color.name(QColor::HexArgb));
|
||||||
const_cast<ColorProvider &>(ColorProvider::instance())
|
|
||||||
.updateColor(ty, color);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
|
if (rowIndex == HighlightRowIndexes::SelfHighlightRow)
|
||||||
|
|||||||
@@ -103,10 +103,6 @@ void UserHighlightModel::customRowSetData(
|
|||||||
// Update the setting with the new value
|
// Update the setting with the new value
|
||||||
getSettings()->selfMessageHighlightColor.setValue(
|
getSettings()->selfMessageHighlightColor.setValue(
|
||||||
colorName);
|
colorName);
|
||||||
// Update the color provider with the new color to be used for future
|
|
||||||
const_cast<ColorProvider &>(ColorProvider::instance())
|
|
||||||
.updateColor(ColorType::SelfMessageHighlight,
|
|
||||||
QColor(colorName));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "providers/colors/ColorProvider.hpp"
|
#include "providers/colors/ColorProvider.hpp"
|
||||||
|
|
||||||
|
#include "common/QLogging.hpp"
|
||||||
#include "controllers/highlights/HighlightPhrase.hpp"
|
#include "controllers/highlights/HighlightPhrase.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
|
||||||
@@ -14,24 +15,16 @@ const ColorProvider &ColorProvider::instance()
|
|||||||
}
|
}
|
||||||
|
|
||||||
ColorProvider::ColorProvider()
|
ColorProvider::ColorProvider()
|
||||||
: typeColorMap_()
|
|
||||||
, defaultColors_()
|
|
||||||
{
|
{
|
||||||
this->initTypeColorMap();
|
this->initTypeColorMap();
|
||||||
this->initDefaultColors();
|
this->initDefaultColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::shared_ptr<QColor> ColorProvider::color(ColorType type) const
|
std::shared_ptr<QColor> ColorProvider::color(ColorType type) const
|
||||||
{
|
{
|
||||||
return this->typeColorMap_.at(type);
|
return this->typeColorMap_.at(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorProvider::updateColor(ColorType type, QColor color)
|
|
||||||
{
|
|
||||||
auto colorPtr = this->typeColorMap_.at(type);
|
|
||||||
*colorPtr = std::move(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
QSet<QColor> ColorProvider::recentColors() const
|
QSet<QColor> ColorProvider::recentColors() const
|
||||||
{
|
{
|
||||||
QSet<QColor> retVal;
|
QSet<QColor> retVal;
|
||||||
@@ -40,12 +33,12 @@ QSet<QColor> ColorProvider::recentColors() const
|
|||||||
* Currently, only colors used in highlight phrases are considered. This
|
* Currently, only colors used in highlight phrases are considered. This
|
||||||
* may change at any point in the future.
|
* may change at any point in the future.
|
||||||
*/
|
*/
|
||||||
for (auto phrase : getSettings()->highlightedMessages)
|
for (const auto &phrase : getSettings()->highlightedMessages)
|
||||||
{
|
{
|
||||||
retVal.insert(*phrase.getColor());
|
retVal.insert(*phrase.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto userHl : getSettings()->highlightedUsers)
|
for (const auto &userHl : getSettings()->highlightedUsers)
|
||||||
{
|
{
|
||||||
retVal.insert(*userHl.getColor());
|
retVal.insert(*userHl.getColor());
|
||||||
}
|
}
|
||||||
@@ -67,117 +60,74 @@ void ColorProvider::initTypeColorMap()
|
|||||||
{
|
{
|
||||||
// Read settings for custom highlight colors and save them in map.
|
// Read settings for custom highlight colors and save them in map.
|
||||||
// If no custom values can be found, set up default values instead.
|
// If no custom values can be found, set up default values instead.
|
||||||
|
// Set up a signal to the respective setting for updating the color when it's changed
|
||||||
|
auto initColor = [this](ColorType colorType, QStringSetting &setting,
|
||||||
|
QColor fallbackColor) {
|
||||||
|
const auto &colorString = setting.getValue();
|
||||||
|
QColor color(colorString);
|
||||||
|
if (color.isValid())
|
||||||
|
{
|
||||||
|
this->typeColorMap_.insert({
|
||||||
|
colorType,
|
||||||
|
std::make_shared<QColor>(color),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->typeColorMap_.insert({
|
||||||
|
colorType,
|
||||||
|
std::make_shared<QColor>(fallbackColor),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QString customColor = getSettings()->selfHighlightColor;
|
setting.connect(
|
||||||
if (QColor(customColor).isValid())
|
[this, colorType](const auto &colorString) {
|
||||||
{
|
QColor color(colorString);
|
||||||
this->typeColorMap_.insert(
|
if (color.isValid())
|
||||||
{ColorType::SelfHighlight, std::make_shared<QColor>(customColor)});
|
{
|
||||||
}
|
// Update color based on the update from the setting
|
||||||
else
|
*this->typeColorMap_.at(colorType) = color;
|
||||||
{
|
}
|
||||||
this->typeColorMap_.insert(
|
else
|
||||||
{ColorType::SelfHighlight,
|
{
|
||||||
std::make_shared<QColor>(
|
qCWarning(chatterinoCommon)
|
||||||
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)});
|
<< "Updated"
|
||||||
}
|
<< static_cast<std::underlying_type_t<ColorType>>(
|
||||||
|
colorType)
|
||||||
|
<< "to invalid color" << colorString;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false);
|
||||||
|
};
|
||||||
|
|
||||||
customColor = getSettings()->selfMessageHighlightColor;
|
initColor(ColorType::SelfHighlight, getSettings()->selfHighlightColor,
|
||||||
if (QColor(customColor).isValid())
|
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR);
|
||||||
{
|
|
||||||
this->typeColorMap_.insert({ColorType::SelfMessageHighlight,
|
|
||||||
std::make_shared<QColor>(customColor)});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::SelfMessageHighlight,
|
|
||||||
std::make_shared<QColor>(
|
|
||||||
HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->subHighlightColor;
|
initColor(ColorType::SelfMessageHighlight,
|
||||||
if (QColor(customColor).isValid())
|
getSettings()->selfMessageHighlightColor,
|
||||||
{
|
HighlightPhrase::FALLBACK_SELF_MESSAGE_HIGHLIGHT_COLOR);
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::Subscription, std::make_shared<QColor>(customColor)});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::Subscription,
|
|
||||||
std::make_shared<QColor>(HighlightPhrase::FALLBACK_SUB_COLOR)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->whisperHighlightColor;
|
initColor(ColorType::Subscription, getSettings()->subHighlightColor,
|
||||||
if (QColor(customColor).isValid())
|
HighlightPhrase::FALLBACK_SUB_COLOR);
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::Whisper, std::make_shared<QColor>(customColor)});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::Whisper,
|
|
||||||
std::make_shared<QColor>(
|
|
||||||
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->redeemedHighlightColor;
|
initColor(ColorType::Whisper, getSettings()->whisperHighlightColor,
|
||||||
if (QColor(customColor).isValid())
|
HighlightPhrase::FALLBACK_HIGHLIGHT_COLOR);
|
||||||
{
|
|
||||||
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)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->firstMessageHighlightColor;
|
initColor(ColorType::RedeemedHighlight,
|
||||||
if (QColor(customColor).isValid())
|
getSettings()->redeemedHighlightColor,
|
||||||
{
|
HighlightPhrase::FALLBACK_REDEEMED_HIGHLIGHT_COLOR);
|
||||||
this->typeColorMap_.insert({ColorType::FirstMessageHighlight,
|
|
||||||
std::make_shared<QColor>(customColor)});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::FirstMessageHighlight,
|
|
||||||
std::make_shared<QColor>(
|
|
||||||
HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->elevatedMessageHighlightColor;
|
initColor(ColorType::FirstMessageHighlight,
|
||||||
if (QColor(customColor).isValid())
|
getSettings()->firstMessageHighlightColor,
|
||||||
{
|
HighlightPhrase::FALLBACK_FIRST_MESSAGE_HIGHLIGHT_COLOR);
|
||||||
this->typeColorMap_.insert({ColorType::ElevatedMessageHighlight,
|
|
||||||
std::make_shared<QColor>(customColor)});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::ElevatedMessageHighlight,
|
|
||||||
std::make_shared<QColor>(
|
|
||||||
HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR)});
|
|
||||||
}
|
|
||||||
|
|
||||||
customColor = getSettings()->threadHighlightColor;
|
initColor(ColorType::ElevatedMessageHighlight,
|
||||||
if (QColor(customColor).isValid())
|
getSettings()->elevatedMessageHighlightColor,
|
||||||
{
|
HighlightPhrase::FALLBACK_ELEVATED_MESSAGE_HIGHLIGHT_COLOR);
|
||||||
this->typeColorMap_.insert({ColorType::ThreadMessageHighlight,
|
|
||||||
std::make_shared<QColor>(customColor)});
|
initColor(ColorType::ThreadMessageHighlight,
|
||||||
}
|
getSettings()->threadHighlightColor,
|
||||||
else
|
HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR);
|
||||||
{
|
|
||||||
this->typeColorMap_.insert(
|
|
||||||
{ColorType::ThreadMessageHighlight,
|
|
||||||
std::make_shared<QColor>(
|
|
||||||
HighlightPhrase::FALLBACK_THREAD_HIGHLIGHT_COLOR)});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorProvider::initDefaultColors()
|
void ColorProvider::initDefaultColors()
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ public:
|
|||||||
* of already parsed predefined (self highlights, subscriptions,
|
* of already parsed predefined (self highlights, subscriptions,
|
||||||
* and whispers) highlights.
|
* and whispers) highlights.
|
||||||
*/
|
*/
|
||||||
const std::shared_ptr<QColor> color(ColorType type) const;
|
std::shared_ptr<QColor> color(ColorType type) const;
|
||||||
|
|
||||||
void updateColor(ColorType type, QColor color);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a set of recently used colors used anywhere in Chatterino.
|
* @brief Return a set of recently used colors used anywhere in Chatterino.
|
||||||
|
|||||||
Reference in New Issue
Block a user