| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef SKINFACTORY_H |
| 4 | #define SKINFACTORY_H |
| 5 | |
| 6 | #include "core/message.h" |
| 7 | #include "gui/webviewers/webviewer.h" |
| 8 | |
| 9 | #include <QColor> |
| 10 | #include <QFont> |
| 11 | #include <QHash> |
| 12 | #include <QMetaType> |
| 13 | #include <QObject> |
| 14 | #include <QPalette> |
| 15 | #include <QStringList> |
| 16 | #include <QVariant> |
| 17 | |
| 18 | class RootItem; |
| 19 | |
| 20 | class SkinEnums : public QObject { |
| 21 | Q_OBJECT |
| 22 | |
| 23 | public: |
| 24 | enum class PaletteColors { |
| 25 | // Paint foreground of some interesting items (feeds with new articles, etc.). |
| 26 | FgInteresting = 1, |
| 27 | |
| 28 | // Paint foreground of some interesting items WHEN SELECTED (feeds with new articles, etc.). |
| 29 | FgSelectedInteresting = 2, |
| 30 | |
| 31 | // Paint foreground of some errored items (feeds with error, etc.). |
| 32 | FgError = 4, |
| 33 | |
| 34 | // Paint foreground of some errored items WHEN SELECTED (feeds with error, etc.). |
| 35 | FgSelectedError = 8, |
| 36 | |
| 37 | // OK-ish color (background of list with test results of article filter). |
| 38 | Allright = 16, |
| 39 | |
| 40 | // Foreground color of items with new articles. |
| 41 | FgNewMessages = 32, |
| 42 | |
| 43 | // Foreground color of selected items with new articles. |
| 44 | FgSelectedNewMessages = 64, |
| 45 | |
| 46 | // Foreground color of disabled items. |
| 47 | FgDisabledFeed = 128 |
| 48 | }; |
| 49 | |
| 50 | static QString palleteColorText(PaletteColors col); |
| 51 | |
| 52 | Q_ENUM(PaletteColors) |
| 53 | }; |
| 54 | |
| 55 | struct RSSGUARD_DLLSPEC Skin { |
| 56 | QString m_skinFolder; |
| 57 | QString m_baseName; |
| 58 | QString m_visibleName; |
| 59 | QString m_author; |
| 60 | QString m_version; |
| 61 | QString m_description; |
| 62 | QString m_rawData; |
| 63 | QString m_rawForcedData; |
| 64 | QString m_adblocked; |
| 65 | QString m_layoutMarkupWrapper; |
| 66 | QString m_enclosureImageMarkup; |
| 67 | QString m_layoutMarkup; |
| 68 | QString m_enclosureMarkup; |
| 69 | QHash<SkinEnums::PaletteColors, QColor> m_colorPalette; |
| 70 | QStringList m_forcedStyles; |
| 71 | bool m_forcedSkinColors; |
| 72 | QMultiHash<QPalette::ColorGroup, QPair<QPalette::ColorRole, QPair<QColor, Qt::BrushStyle>>> m_stylePalette; |
| 73 | |
| 74 | QVariant colorForModel(SkinEnums::PaletteColors type, |
| 75 | bool use_skin_colors, |
| 76 | bool ignore_custom_colors = false) const; |
| 77 | QPalette extractPalette() const; |
| 78 | }; |
| 79 | |
| 80 | uint qHash(const SkinEnums::PaletteColors& key); |
| 81 | |
| 82 | Q_DECLARE_METATYPE(Skin) |
| 83 | |
| 84 | class RSSGUARD_DLLSPEC SkinFactory : public QObject { |
| 85 | Q_OBJECT |
| 86 | |
| 87 | public: |
| 88 | explicit SkinFactory(QObject* parent = nullptr); |
| 89 | virtual ~SkinFactory() = default; |
| 90 | |
| 91 | // Loads skin name from settings and sets it as active. |
| 92 | void loadCurrentSkin(bool lite, bool replace_existing_qss); |
| 93 | Skin currentSkin() const; |
| 94 | |
| 95 | // Gets color for model from active skin. |
| 96 | QVariant colorForModel(SkinEnums::PaletteColors type, bool ignore_custom_colors = false) const; |
| 97 | |
| 98 | bool isStyleGoodForAlternativeStylePalette(const QString& style_name) const; |
| 99 | |
| 100 | // Returns the name of the skin, that should be activated |
| 101 | // after application restart. |
| 102 | QString selectedSkinName() const; |
| 103 | |
| 104 | QString adBlockedPage(const QString& url, const QString& filter); |
| 105 | |
| 106 | PreparedHtml prepareHtml(const QString& inner_html, const QUrl& base_url); |
| 107 | PreparedHtml generateHtmlOfArticles(const QList<Message>& messages, RootItem* root, int desired_width) const; |
| 108 | |
| 109 | // Gets skin about a particular skin. |
| 110 | Skin skinInfo(const QString& skin_name, bool lite, bool* ok = nullptr) const; |
| 111 | |
| 112 | // Returns list of installed skins. |
| 113 | QList<Skin> installedSkins() const; |
| 114 | |
| 115 | // Sets the desired skin as the active one if it exists. |
| 116 | void setCurrentSkinName(const QString& skin_name); |
| 117 | |
| 118 | QString customSkinBaseFolder() const; |
| 119 | bool styleIsFrozen() const; |
| 120 | QString currentStyle() const; |
| 121 | |
| 122 | private: |
| 123 | // Loads the skin from given skin_data. |
| 124 | void loadSkinFromData(const Skin& skin, bool replace_existing_qss); |
| 125 | |
| 126 | QString loadSkinFile(const QString& skin_folder, |
| 127 | bool lite, |
| 128 | const QString& file_name, |
| 129 | const QString& base_folder) const; |
| 130 | |
| 131 | // Holds name of the current skin. |
| 132 | Skin m_currentSkin; |
| 133 | QString m_currentStyle; |
| 134 | bool m_styleIsFrozen; |
| 135 | bool m_useSkinColors; |
| 136 | }; |
| 137 | |
| 138 | inline Skin SkinFactory::currentSkin() const { |
| 139 | return m_currentSkin; |
| 140 | } |
| 141 | |
| 142 | #endif // SKINFACTORY_H |