File indexing completed on 2024-05-12 15:59:15
0001 /* 0002 * This file is part of the KDE project 0003 * SPDX-FileCopyrightText: 2014 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef THEME_H 0009 #define THEME_H 0010 0011 #include <QObject> 0012 #include <QVariantMap> 0013 0014 class QQmlEngine; 0015 0016 #include "krita_sketch_export.h" 0017 0018 class KRITA_SKETCH_EXPORT Theme : public QObject 0019 { 0020 Q_OBJECT 0021 /** 0022 * \property id 0023 * \brief 0024 * 0025 * \get id() const 0026 * \set setId() 0027 * \notify idChanged() 0028 */ 0029 Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged) 0030 /** 0031 * \property name 0032 * \brief The user-visible name of this theme. 0033 * 0034 * \get name() const 0035 * \set setName() 0036 * \notify nameChanged() 0037 */ 0038 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0039 /** 0040 * \property colors 0041 * \brief A JavaScript object describing the colors to be used by this theme. 0042 * 0043 * \get colors() const 0044 * \set setColors() 0045 * \notify colorsChanged() 0046 */ 0047 Q_PROPERTY(QVariantMap colors READ colors WRITE setColors NOTIFY colorsChanged) 0048 /** 0049 * \property sizes 0050 * \brief A JavaScript object describing a number of sizes to be used by this theme. 0051 * 0052 * \get sizes() const 0053 * \set setSizes() 0054 * \notify sizesChanged() 0055 */ 0056 Q_PROPERTY(QVariantMap sizes READ sizes WRITE setSizes NOTIFY sizesChanged) 0057 /** 0058 * \property fonts 0059 * \brief A JavaScript object describing the fonts to be used by this theme. 0060 * 0061 * \get fonts() const 0062 * \set setFonts() 0063 * \notify fontsChanged() 0064 */ 0065 Q_PROPERTY(QVariantMap fonts READ fonts WRITE setFonts NOTIFY fontsChanged) 0066 /** 0067 * \property iconPath 0068 * \brief The path used to look up icons from the theme. 0069 * 0070 * Relative paths are relative to the theme directory. 0071 * 0072 * \default "icons/" 0073 * \get iconPath() const 0074 * \set setIconPath() 0075 * \notify iconPathChanged() 0076 */ 0077 Q_PROPERTY(QString iconPath READ iconPath WRITE setIconPath NOTIFY iconPathChanged) 0078 /** 0079 * \property imagePath 0080 * \brief The path used to look up images from the theme. 0081 * 0082 * Relative paths are relative to the theme directory. 0083 * 0084 * \default "images/" 0085 * \get imagePath() const 0086 * \set setImagePath() 0087 * \notify imagePathChanged() 0088 */ 0089 Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged) 0090 /** 0091 * \property fontPath 0092 * \brief A path containing additional fonts to load. 0093 * 0094 * The fontPath specifies a directory that will be searched for font files. These 0095 * font files will then be made available for use in the theme. 0096 * 0097 * \default "fonts/" 0098 * \get fontPath() const 0099 * \set setFontPath() 0100 * \notify fontPathChanged() 0101 */ 0102 Q_PROPERTY(QString fontPath READ fontPath WRITE setFontPath NOTIFY fontPathChanged) 0103 public: 0104 0105 static Theme *instance(); 0106 explicit Theme(QObject *parent = nullptr); 0107 ~Theme() override; 0108 0109 /** 0110 * Getter for property #id. 0111 */ 0112 QString id() const; 0113 /** 0114 * Setter for property #id. 0115 */ 0116 void setId(const QString& newValue); 0117 0118 /** 0119 * Getter for property #name. 0120 */ 0121 QString name() const; 0122 /** 0123 * Setter for property #name. 0124 */ 0125 void setName(const QString& newValue); 0126 0127 /** 0128 * Getter for property #colors. 0129 */ 0130 QVariantMap colors() const; 0131 /** 0132 * Setter for property #colors. 0133 */ 0134 void setColors(const QVariantMap& newValue); 0135 0136 /** 0137 * Getter for property #sizes. 0138 */ 0139 QVariantMap sizes() const; 0140 /** 0141 * Setter for property #sizes. 0142 */ 0143 void setSizes(const QVariantMap& newValue); 0144 0145 /** 0146 * Getter for property #fonts. 0147 */ 0148 QVariantMap fonts() const; 0149 /** 0150 * Setter for property #fonts. 0151 */ 0152 void setFonts(const QVariantMap& newValue); 0153 0154 /** 0155 * Getter for property #iconPath. 0156 */ 0157 QString iconPath() const; 0158 /** 0159 * Setter for property #iconPath. 0160 */ 0161 void setIconPath(const QString& newValue); 0162 0163 /** 0164 * Getter for property #imagePath. 0165 */ 0166 QString imagePath() const; 0167 /** 0168 * Setter for property #imagePath. 0169 */ 0170 void setImagePath(const QString& newValue); 0171 0172 /** 0173 * Getter for property #fontPath. 0174 */ 0175 QString fontPath() const; 0176 /** 0177 * Setter for property #fontPath. 0178 */ 0179 void setFontPath(const QString& newValue); 0180 0181 /** 0182 * Get a single color from the theme. 0183 * 0184 * \param name The color to get. 0185 * \return The color asked for, or a default color if it is not defined in the theme. 0186 */ 0187 Q_INVOKABLE QColor color(const QString& name); 0188 /** 0189 * Get a single size value from the theme. 0190 */ 0191 Q_INVOKABLE float size(const QString& name); 0192 /** 0193 * Get an icon from the theme. 0194 */ 0195 Q_INVOKABLE QUrl icon(const QString& name); 0196 /** 0197 * Get a font from the theme. 0198 */ 0199 Q_INVOKABLE QFont font(const QString& name); 0200 /** 0201 * Get an image from the theme. 0202 */ 0203 Q_INVOKABLE QUrl image(const QString& name); 0204 0205 static Theme *load(const QString &id, QQmlEngine *engine = nullptr); 0206 0207 Q_SIGNALS: 0208 void idChanged(); 0209 void nameChanged(); 0210 void colorsChanged(); 0211 void sizesChanged(); 0212 void fontsChanged(); 0213 void iconPathChanged(); 0214 void imagePathChanged(); 0215 void fontPathChanged(); 0216 void fontCacheRebuilt(); 0217 0218 protected: 0219 bool eventFilter(QObject *, QEvent *) override; 0220 0221 private: 0222 0223 static QString themePath(const QString &id); 0224 0225 class Private; 0226 Private * const d; 0227 }; 0228 0229 #endif // THEME_H