mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-01-28 16:20:34 +01:00
use direct enums in metadata.xml, allow for custom dynamcic colors in lists for selected items
This commit is contained in:
parent
a286d67779
commit
f1baf56dcf
@ -26,7 +26,7 @@
|
||||
<url type="donation">https://github.com/sponsors/martinrotter</url>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="4.0.4" date="2021-11-18"/>
|
||||
<release version="4.0.4" date="2021-11-19"/>
|
||||
</releases>
|
||||
<content_rating type="oars-1.0">
|
||||
<content_attribute id="violence-cartoon">none</content_attribute>
|
||||
|
@ -4,8 +4,10 @@
|
||||
<name>Martin Rotter</name>
|
||||
</author>
|
||||
<palette>
|
||||
<color key="1">#7ae2ff</color>
|
||||
<color key="2">#f08f84</color>
|
||||
<color key="3">#77dd77</color>
|
||||
<color key="FgInteresting">#3A4EE4</color>
|
||||
<color key="FgSelectedInteresting">#ff66cc</color>
|
||||
<color key="FgError">#4EE43A</color>
|
||||
<color key="FgSelectedError">#ff99ff</color>
|
||||
<color key="Allright">#00ff99</color>
|
||||
</palette>
|
||||
</skin>
|
@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<skin version="0.01">
|
||||
<author>
|
||||
<name>Maki Blackwell</name>
|
||||
</author>
|
||||
<palette>
|
||||
<color key="1">#3A4EE4</color>
|
||||
<color key="2">#E43A4E</color>
|
||||
<color key="3">#4EE43A</color>
|
||||
<color key="FgInteresting">#3A4EE4</color>
|
||||
<color key="FgSelectedInteresting">#ff66cc</color>
|
||||
<color key="FgError">#4EE43A</color>
|
||||
<color key="FgSelectedError">#ff99ff</color>
|
||||
<color key="Allright">#00ff99</color>
|
||||
</palette>
|
||||
</skin>
|
||||
</skin>
|
@ -10,8 +10,10 @@
|
||||
|
||||
Specifically, they are taken from enumeration "PaletteColors".
|
||||
-->
|
||||
<color key="1">#00BFFF</color>
|
||||
<color key="2">#FF0000</color>
|
||||
<color key="3">#32CD32</color>
|
||||
<color key="FgInteresting">#3A4EE4</color>
|
||||
<color key="FgSelectedInteresting">#ff66cc</color>
|
||||
<color key="FgError">#4EE43A</color>
|
||||
<color key="FgSelectedError">#ff99ff</color>
|
||||
<color key="Allright">#00ff99</color>
|
||||
</palette>
|
||||
</skin>
|
@ -4,8 +4,10 @@
|
||||
<name>Martin Rotter</name>
|
||||
</author>
|
||||
<palette>
|
||||
<color key="1">#4861f0</color>
|
||||
<color key="2">#d93636</color>
|
||||
<color key="3">#77dd77</color>
|
||||
<color key="FgInteresting">#3A4EE4</color>
|
||||
<color key="FgSelectedInteresting">#ff66cc</color>
|
||||
<color key="FgError">#4EE43A</color>
|
||||
<color key="FgSelectedError">#ff99ff</color>
|
||||
<color key="Allright">#00ff99</color>
|
||||
</palette>
|
||||
</skin>
|
@ -39,11 +39,11 @@ QVariant MessagesForFiltersModel::data(const QModelIndex& index, int role) const
|
||||
if (m_filteringDecisions.contains(index.row())) {
|
||||
switch (m_filteringDecisions.value(index.row())) {
|
||||
case MessageObject::FilteringAction::Accept:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Allright];
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::Allright];
|
||||
|
||||
case MessageObject::FilteringAction::Ignore:
|
||||
case MessageObject::FilteringAction::Purge:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Error];
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgError];
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -386,19 +386,28 @@ QVariant MessagesModel::data(const QModelIndex& idx, int role) const {
|
||||
}
|
||||
|
||||
case Qt::ItemDataRole::ForegroundRole:
|
||||
case HIGHLIGHTED_FOREGROUND_TITLE_ROLE:
|
||||
switch (m_messageHighlighter) {
|
||||
case MessageHighlighter::HighlightImportant: {
|
||||
QModelIndex idx_important = index(idx.row(), MSG_DB_IMPORTANT_INDEX);
|
||||
QVariant dta = m_cache->containsData(idx_important.row()) ? m_cache->data(idx_important) : QSqlQueryModel::data(idx_important);
|
||||
|
||||
return dta.toInt() == 1 ? qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Highlight] : QVariant();
|
||||
return dta.toInt() == 1
|
||||
? qApp->skins()->currentSkin().m_colorPalette[role == Qt::ItemDataRole::ForegroundRole
|
||||
? SkinEnums::PaletteColors::FgInteresting
|
||||
: SkinEnums::PaletteColors::FgSelectedInteresting]
|
||||
: QVariant();
|
||||
}
|
||||
|
||||
case MessageHighlighter::HighlightUnread: {
|
||||
QModelIndex idx_read = index(idx.row(), MSG_DB_READ_INDEX);
|
||||
QVariant dta = m_cache->containsData(idx_read.row()) ? m_cache->data(idx_read) : QSqlQueryModel::data(idx_read);
|
||||
|
||||
return dta.toInt() == 0 ? qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Highlight] : QVariant();
|
||||
return dta.toInt() == 0
|
||||
? qApp->skins()->currentSkin().m_colorPalette[role == Qt::ItemDataRole::ForegroundRole
|
||||
? SkinEnums::PaletteColors::FgInteresting
|
||||
: SkinEnums::PaletteColors::FgSelectedInteresting]
|
||||
: QVariant();
|
||||
}
|
||||
|
||||
case MessageHighlighter::NoHighlighting:
|
||||
|
@ -46,6 +46,9 @@
|
||||
#define MSG_SCORE_MAX 100.0
|
||||
#define MSG_SCORE_MIN 0.0
|
||||
|
||||
#define LOWER_TITLE_ROLE 64
|
||||
#define HIGHLIGHTED_FOREGROUND_TITLE_ROLE 128
|
||||
|
||||
#define SOUNDS_BUILTIN_DIRECTORY ":/sounds"
|
||||
#define ARGUMENTS_LIST_SEPARATOR "\n"
|
||||
#define IS_IN_ARRAY(offset, array) ((offset >= 0) && (offset < array.count()))
|
||||
@ -57,7 +60,6 @@
|
||||
#define SCRIPT_SOURCE_TYPE_REGEXP "^.+#.*$"
|
||||
#define TEXT_TITLE_LIMIT 30
|
||||
#define TEXT_TOOLTIP_LIMIT 50
|
||||
#define LOWER_TITLE_ROLE 64
|
||||
#define RESELECT_MESSAGE_THRESSHOLD 500
|
||||
#define ICON_SIZE_SETTINGS 16
|
||||
#define TRAY_ICON_BUBBLE_TIMEOUT 20000
|
||||
|
@ -169,7 +169,7 @@ QString MessageBrowser::prepareHtmlForMessage(const Message& message) {
|
||||
"</style></head>"
|
||||
"<body>%1</body>"
|
||||
"</html>").arg(html,
|
||||
qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Highlight].name());
|
||||
qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgInteresting].name());
|
||||
}
|
||||
|
||||
bool MessageBrowser::eventFilter(QObject* watched, QEvent* event) {
|
||||
|
@ -19,7 +19,7 @@ void StyledItemDelegateWithoutFocus::paint(QPainter* painter,
|
||||
if ((item_option.state & QStyle::StateFlag::State_Selected) == QStyle::StateFlag::State_Selected &&
|
||||
index.data(Qt::ItemDataRole::ForegroundRole).isValid()) {
|
||||
item_option.palette.setColor(QPalette::ColorRole::HighlightedText,
|
||||
index.data(Qt::ItemDataRole::ForegroundRole).value<QColor>());
|
||||
index.data(HIGHLIGHTED_FOREGROUND_TITLE_ROLE).value<QColor>());
|
||||
}
|
||||
|
||||
QStyledItemDelegate::paint(painter, item_option, index);
|
||||
|
@ -8,6 +8,8 @@
|
||||
#include <QDir>
|
||||
#include <QDomDocument>
|
||||
#include <QDomElement>
|
||||
#include <QMetaEnum>
|
||||
#include <QMetaObject>
|
||||
#include <QStyleFactory>
|
||||
#include <QToolTip>
|
||||
|
||||
@ -205,13 +207,15 @@ Skin SkinFactory::skinInfo(const QString& skin_name, bool* ok) const {
|
||||
skin.m_baseName = skin_name;
|
||||
|
||||
// Obtain color palette.
|
||||
QHash<Skin::PaletteColors, QColor> palette;
|
||||
QHash<SkinEnums::PaletteColors, QColor> palette;
|
||||
QDomNodeList colors_of_palette = skin_node.namedItem(QSL("palette")).toElement().elementsByTagName(QSL("color"));
|
||||
const QMetaObject& mo = SkinEnums::staticMetaObject;
|
||||
QMetaEnum enumer = mo.enumerator(mo.indexOfEnumerator(QSL("PaletteColors").toLocal8Bit().constData()));
|
||||
|
||||
for (int i = 0; i < colors_of_palette.size(); i++) {
|
||||
QDomElement elem_clr = colors_of_palette.item(i).toElement();
|
||||
|
||||
Skin::PaletteColors key = Skin::PaletteColors(elem_clr.attribute(QSL("key")).toInt());
|
||||
QString en_val = elem_clr.attribute(QSL("key"));
|
||||
SkinEnums::PaletteColors key = SkinEnums::PaletteColors(enumer.keyToValue(en_val.toLatin1()));
|
||||
QColor value = elem_clr.text();
|
||||
|
||||
if (value.isValid()) {
|
||||
@ -310,6 +314,6 @@ QList<Skin> SkinFactory::installedSkins() const {
|
||||
return skins;
|
||||
}
|
||||
|
||||
uint qHash(const Skin::PaletteColors& key) {
|
||||
uint qHash(const SkinEnums::PaletteColors& key) {
|
||||
return uint(key);
|
||||
}
|
||||
|
@ -10,21 +10,31 @@
|
||||
#include <QMetaType>
|
||||
#include <QStringList>
|
||||
|
||||
class SkinEnums : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class PaletteColors {
|
||||
// Paint foreground of some interesting items (feeds with new articles, etc.).
|
||||
FgInteresting = 1,
|
||||
|
||||
// Paint foreground of some interesting items WHEN SELECTED (feeds with new articles, etc.).
|
||||
FgSelectedInteresting = 2,
|
||||
|
||||
// Paint foreground of some errored items (feeds with error, etc.).
|
||||
FgError = 4,
|
||||
|
||||
// Paint foreground of some errored items WHEN SELECTED (feeds with error, etc.).
|
||||
FgSelectedError = 8,
|
||||
|
||||
// OK-ish color (background of list with test results of article filter).
|
||||
Allright = 16
|
||||
};
|
||||
|
||||
Q_ENUM(PaletteColors)
|
||||
};
|
||||
|
||||
struct RSSGUARD_DLLSPEC Skin {
|
||||
enum class PaletteColors {
|
||||
// Used to highlight foreground of some interesting articles.
|
||||
Highlight = 1,
|
||||
|
||||
// Foreground color of errorneous entries.
|
||||
Error = 2,
|
||||
|
||||
// OK-ish color.
|
||||
Allright = 3,
|
||||
|
||||
// Foreground color when item is highlighted/selected.
|
||||
HighlightedError = 4
|
||||
};
|
||||
|
||||
QString m_baseName;
|
||||
QString m_visibleName;
|
||||
QString m_author;
|
||||
@ -35,10 +45,10 @@ struct RSSGUARD_DLLSPEC Skin {
|
||||
QString m_enclosureImageMarkup;
|
||||
QString m_layoutMarkup;
|
||||
QString m_enclosureMarkup;
|
||||
QHash<Skin::PaletteColors, QColor> m_colorPalette;
|
||||
QHash<SkinEnums::PaletteColors, QColor> m_colorPalette;
|
||||
};
|
||||
|
||||
uint qHash(const Skin::PaletteColors& key);
|
||||
uint qHash(const SkinEnums::PaletteColors& key);
|
||||
|
||||
Q_DECLARE_METATYPE(Skin)
|
||||
|
||||
|
@ -53,16 +53,31 @@ QList<Message> Feed::undeletedMessages() const {
|
||||
|
||||
QVariant Feed::data(int column, int role) const {
|
||||
switch (role) {
|
||||
case Qt::ItemDataRole::ForegroundRole:
|
||||
case HIGHLIGHTED_FOREGROUND_TITLE_ROLE:
|
||||
switch (status()) {
|
||||
case Status::NewMessages:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Highlight];
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgSelectedInteresting];
|
||||
|
||||
case Status::NetworkError:
|
||||
case Status::ParsingError:
|
||||
case Status::AuthError:
|
||||
case Status::OtherError:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[Skin::PaletteColors::Error];
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgSelectedError];
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
case Qt::ItemDataRole::ForegroundRole:
|
||||
switch (status()) {
|
||||
case Status::NewMessages:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgInteresting];
|
||||
|
||||
case Status::NetworkError:
|
||||
case Status::ParsingError:
|
||||
case Status::AuthError:
|
||||
case Status::OtherError:
|
||||
return qApp->skins()->currentSkin().m_colorPalette[SkinEnums::PaletteColors::FgError];
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
|
Loading…
x
Reference in New Issue
Block a user