fix logic when NOT using skins colors but make applying custom colors from settings work, great flexibility now

This commit is contained in:
Martin Rotter 2023-07-03 08:40:56 +02:00
parent cb6c49a36e
commit a10d6e2384
7 changed files with 34 additions and 27 deletions

View File

@ -39,11 +39,11 @@ QVariant MessagesForFiltersModel::data(const QModelIndex& index, int role) const
if (m_filteringDecisions.contains(index.row())) { if (m_filteringDecisions.contains(index.row())) {
switch (m_filteringDecisions.value(index.row())) { switch (m_filteringDecisions.value(index.row())) {
case MessageObject::FilteringAction::Accept: case MessageObject::FilteringAction::Accept:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::Allright); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::Allright);
case MessageObject::FilteringAction::Ignore: case MessageObject::FilteringAction::Ignore:
case MessageObject::FilteringAction::Purge: case MessageObject::FilteringAction::Purge:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgError); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgError);
default: default:
break; break;

View File

@ -476,9 +476,9 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
: QSqlQueryModel::data(idx_important); : QSqlQueryModel::data(idx_important);
if (dta.toInt() == 1) { if (dta.toInt() == 1) {
return qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole return qApp->skins()->colorForModel(role == Qt::ItemDataRole::ForegroundRole
? SkinEnums::PaletteColors::FgInteresting ? SkinEnums::PaletteColors::FgInteresting
: SkinEnums::PaletteColors::FgSelectedInteresting); : SkinEnums::PaletteColors::FgSelectedInteresting);
} }
} }
@ -487,9 +487,9 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
QVariant dta = m_cache->containsData(idx_read.row()) ? m_cache->data(idx_read) : QSqlQueryModel::data(idx_read); QVariant dta = m_cache->containsData(idx_read.row()) ? m_cache->data(idx_read) : QSqlQueryModel::data(idx_read);
if (dta.toInt() == 0) { if (dta.toInt() == 0) {
return qApp->skins()->currentSkin().colorForModel(role == Qt::ItemDataRole::ForegroundRole return qApp->skins()->colorForModel(role == Qt::ItemDataRole::ForegroundRole
? SkinEnums::PaletteColors::FgInteresting ? SkinEnums::PaletteColors::FgInteresting
: SkinEnums::PaletteColors::FgSelectedInteresting); : SkinEnums::PaletteColors::FgSelectedInteresting);
} }
} }

View File

@ -306,7 +306,7 @@ void SettingsGui::loadSettings() {
QColor clr = settings()->value(GROUP(CustomSkinColors), enumer.key(i)).toString(); QColor clr = settings()->value(GROUP(CustomSkinColors), enumer.key(i)).toString();
if (!clr.isValid()) { if (!clr.isValid()) {
clr = qApp->skins()->currentSkin().colorForModel(pal).value<QColor>(); clr = qApp->skins()->colorForModel(pal).value<QColor>();
} }
rst_btn->setObjectName(QString::number(enumer.value(i))); rst_btn->setObjectName(QString::number(enumer.value(i)));
@ -339,7 +339,7 @@ void SettingsGui::resetCustomSkinColor() {
auto* clr_btn = m_ui->m_gbCustomSkinColors->findChild<ColorToolButton*>(sender()->objectName()); auto* clr_btn = m_ui->m_gbCustomSkinColors->findChild<ColorToolButton*>(sender()->objectName());
SkinEnums::PaletteColors pal = SkinEnums::PaletteColors(sender()->objectName().toInt()); SkinEnums::PaletteColors pal = SkinEnums::PaletteColors(sender()->objectName().toInt());
clr_btn->setColor(qApp->skins()->currentSkin().colorForModel(pal, true).value<QColor>()); clr_btn->setColor(qApp->skins()->colorForModel(pal, true).value<QColor>());
} }
void SettingsGui::saveSettings() { void SettingsGui::saveSettings() {

View File

@ -37,7 +37,7 @@ TextBrowserViewer::TextBrowserViewer(QWidget* parent)
setDocument(m_document.data()); setDocument(m_document.data());
// Apply master CSS. // Apply master CSS.
QColor a_color = qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgInteresting).value<QColor>(); QColor a_color = qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgInteresting).value<QColor>();
if (!a_color.isValid()) { if (!a_color.isValid()) {
a_color = qApp->palette().color(QPalette::ColorRole::Highlight); a_color = qApp->palette().color(QPalette::ColorRole::Highlight);

View File

@ -19,7 +19,7 @@
#include <QTextDocument> #include <QTextDocument>
#include <QToolTip> #include <QToolTip>
SkinFactory::SkinFactory(QObject* parent) : QObject(parent), m_styleIsFrozen(false) {} SkinFactory::SkinFactory(QObject* parent) : QObject(parent), m_styleIsFrozen(false), m_useSkinColors(false) {}
void SkinFactory::loadCurrentSkin() { void SkinFactory::loadCurrentSkin() {
QList<QString> skin_names_to_try = {selectedSkinName(), QSL(APP_SKIN_DEFAULT)}; QList<QString> skin_names_to_try = {selectedSkinName(), QSL(APP_SKIN_DEFAULT)};
@ -47,6 +47,10 @@ void SkinFactory::loadCurrentSkin() {
qCriticalNN << LOGSEC_GUI << "Failed to load selected or default skin. Quitting!"; qCriticalNN << LOGSEC_GUI << "Failed to load selected or default skin. Quitting!";
} }
QVariant SkinFactory::colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_colors) const {
return m_currentSkin.colorForModel(type, m_useSkinColors, ignore_custom_colors);
}
bool SkinFactory::isStyleGoodForAlternativeStylePalette(const QString& style_name) const { bool SkinFactory::isStyleGoodForAlternativeStylePalette(const QString& style_name) const {
static QRegularExpression re = QRegularExpression(QSL("^(fusion|windows|qt[56]ct-style)$")); static QRegularExpression re = QRegularExpression(QSL("^(fusion|windows|qt[56]ct-style)$"));
@ -167,12 +171,11 @@ void SkinFactory::loadSkinFromData(const Skin& skin) {
// NOTE: We can do this because in Qt source code // NOTE: We can do this because in Qt source code
// they specifically set object name to style name. // they specifically set object name to style name.
m_currentStyle = qApp->style()->objectName(); m_currentStyle = qApp->style()->objectName();
m_useSkinColors =
const bool use_skin_colors =
skin.m_forcedSkinColors || qApp->settings()->value(GROUP(GUI), SETTING(GUI::ForcedSkinColors)).toBool(); skin.m_forcedSkinColors || qApp->settings()->value(GROUP(GUI), SETTING(GUI::ForcedSkinColors)).toBool();
if (isStyleGoodForAlternativeStylePalette(m_currentStyle)) { if (isStyleGoodForAlternativeStylePalette(m_currentStyle)) {
if (!skin.m_stylePalette.isEmpty() && use_skin_colors) { if (!skin.m_stylePalette.isEmpty() && m_useSkinColors) {
qDebugNN << LOGSEC_GUI << "Activating alternative palette."; qDebugNN << LOGSEC_GUI << "Activating alternative palette.";
QPalette pal = skin.extractPalette(); QPalette pal = skin.extractPalette();
@ -191,7 +194,7 @@ void SkinFactory::loadSkinFromData(const Skin& skin) {
} }
if (!skin.m_rawData.isEmpty()) { if (!skin.m_rawData.isEmpty()) {
if (qApp->styleSheet().simplified().isEmpty() && use_skin_colors) { if (qApp->styleSheet().simplified().isEmpty() && m_useSkinColors) {
qApp->setStyleSheet(skin.m_rawData); qApp->setStyleSheet(skin.m_rawData);
} }
else { else {
@ -529,7 +532,7 @@ uint qHash(const SkinEnums::PaletteColors& key) {
return uint(key); return uint(key);
} }
QVariant Skin::colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_colors) const { QVariant Skin::colorForModel(SkinEnums::PaletteColors type, bool use_skin_colors, bool ignore_custom_colors) const {
if (!ignore_custom_colors) { if (!ignore_custom_colors) {
bool enabled = qApp->settings()->value(GROUP(CustomSkinColors), SETTING(CustomSkinColors::Enabled)).toBool(); bool enabled = qApp->settings()->value(GROUP(CustomSkinColors), SETTING(CustomSkinColors::Enabled)).toBool();
@ -544,7 +547,7 @@ QVariant Skin::colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_c
} }
} }
return m_colorPalette.contains(type) ? m_colorPalette[type] : QVariant(); return (use_skin_colors & m_colorPalette.contains(type)) ? m_colorPalette[type] : QVariant();
} }
QPalette Skin::extractPalette() const { QPalette Skin::extractPalette() const {

View File

@ -70,7 +70,9 @@ struct RSSGUARD_DLLSPEC Skin {
bool m_forcedSkinColors; bool m_forcedSkinColors;
QMultiHash<QPalette::ColorGroup, QPair<QPalette::ColorRole, QPair<QColor, Qt::BrushStyle>>> m_stylePalette; QMultiHash<QPalette::ColorGroup, QPair<QPalette::ColorRole, QPair<QColor, Qt::BrushStyle>>> m_stylePalette;
QVariant colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_colors = false) const; QVariant colorForModel(SkinEnums::PaletteColors type,
bool use_skin_colors,
bool ignore_custom_colors = false) const;
QPalette extractPalette() const; QPalette extractPalette() const;
}; };
@ -89,6 +91,9 @@ class RSSGUARD_DLLSPEC SkinFactory : public QObject {
void loadCurrentSkin(); void loadCurrentSkin();
Skin currentSkin() const; Skin currentSkin() const;
// Gets color for model from active skin.
QVariant colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_colors = false) const;
bool isStyleGoodForAlternativeStylePalette(const QString& style_name) const; bool isStyleGoodForAlternativeStylePalette(const QString& style_name) const;
// Returns the name of the skin, that should be activated // Returns the name of the skin, that should be activated
@ -109,9 +114,7 @@ class RSSGUARD_DLLSPEC SkinFactory : public QObject {
void setCurrentSkinName(const QString& skin_name); void setCurrentSkinName(const QString& skin_name);
QString customSkinBaseFolder() const; QString customSkinBaseFolder() const;
bool styleIsFrozen() const; bool styleIsFrozen() const;
QString currentStyle() const; QString currentStyle() const;
private: private:
@ -124,6 +127,7 @@ class RSSGUARD_DLLSPEC SkinFactory : public QObject {
Skin m_currentSkin; Skin m_currentSkin;
QString m_currentStyle; QString m_currentStyle;
bool m_styleIsFrozen; bool m_styleIsFrozen;
bool m_useSkinColors;
}; };
inline Skin SkinFactory::currentSkin() const { inline Skin SkinFactory::currentSkin() const {

View File

@ -58,11 +58,11 @@ QVariant Feed::data(int column, int role) const {
case HIGHLIGHTED_FOREGROUND_TITLE_ROLE: case HIGHLIGHTED_FOREGROUND_TITLE_ROLE:
switch (status()) { switch (status()) {
case Status::NewMessages: case Status::NewMessages:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgSelectedNewMessages); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgSelectedNewMessages);
case Status::Normal: case Status::Normal:
if (countOfUnreadMessages() > 0) { if (countOfUnreadMessages() > 0) {
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgSelectedInteresting); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgSelectedInteresting);
} }
else { else {
return QVariant(); return QVariant();
@ -72,7 +72,7 @@ QVariant Feed::data(int column, int role) const {
case Status::ParsingError: case Status::ParsingError:
case Status::AuthError: case Status::AuthError:
case Status::OtherError: case Status::OtherError:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgSelectedError); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgSelectedError);
default: default:
return QVariant(); return QVariant();
@ -81,11 +81,11 @@ QVariant Feed::data(int column, int role) const {
case Qt::ItemDataRole::ForegroundRole: case Qt::ItemDataRole::ForegroundRole:
switch (status()) { switch (status()) {
case Status::NewMessages: case Status::NewMessages:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgNewMessages); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgNewMessages);
case Status::Normal: case Status::Normal:
if (countOfUnreadMessages() > 0) { if (countOfUnreadMessages() > 0) {
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgInteresting); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgInteresting);
} }
else { else {
return QVariant(); return QVariant();
@ -95,7 +95,7 @@ QVariant Feed::data(int column, int role) const {
case Status::ParsingError: case Status::ParsingError:
case Status::AuthError: case Status::AuthError:
case Status::OtherError: case Status::OtherError:
return qApp->skins()->currentSkin().colorForModel(SkinEnums::PaletteColors::FgError); return qApp->skins()->colorForModel(SkinEnums::PaletteColors::FgError);
default: default:
return QVariant(); return QVariant();