File indexing completed on 2024-05-05 17:04:27
0001 /* 0002 * This file is part of the KDE project 0003 * Copyright (C) 2014 Arjen Hiemstra <ahiemstra@heimr.nl> 0004 * 0005 * This program is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation; either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program; if not, write to the Free Software 0017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef THEME_H 0021 #define THEME_H 0022 0023 #include <QObject> 0024 #include <QVariantMap> 0025 #include <QIcon> 0026 0027 class Theme : public QObject 0028 { 0029 Q_OBJECT 0030 /** 0031 * \property id 0032 * \brief 0033 * 0034 * \get id() const 0035 * \set setId() 0036 * \notify idChanged() 0037 */ 0038 Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged) 0039 /** 0040 * \property name 0041 * \brief The user-visible name of this theme. 0042 * 0043 * \get name() const 0044 * \set setName() 0045 * \notify nameChanged() 0046 */ 0047 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0048 /** 0049 * \property inherits 0050 * \brief The id of the theme this theme inherits. 0051 * 0052 * If a certain property can not be found, the theme will try to get that property 0053 * from the inherited theme. 0054 * 0055 * \default None 0056 * \get inherits() const 0057 * \set setInherits() 0058 * \notify inheritsChanged() 0059 */ 0060 Q_PROPERTY(QString inherits READ inherits WRITE setInherits NOTIFY inheritsChanged) 0061 /** 0062 * \property colors 0063 * \brief A JavaScript object describing the colors to be used by this theme. 0064 * 0065 * \get colors() const 0066 * \set setColors() 0067 * \notify colorsChanged() 0068 */ 0069 Q_PROPERTY(QVariantMap colors READ colors WRITE setColors NOTIFY colorsChanged) 0070 /** 0071 * \property sizes 0072 * \brief A JavaScript object describing a number of sizes to be used by this theme. 0073 * 0074 * \get sizes() const 0075 * \set setSizes() 0076 * \notify sizesChanged() 0077 */ 0078 Q_PROPERTY(QVariantMap sizes READ sizes WRITE setSizes NOTIFY sizesChanged) 0079 /** 0080 * \property fonts 0081 * \brief A JavaScript object describing the fonts to be used by this theme. 0082 * 0083 * \get fonts() const 0084 * \set setFonts() 0085 * \notify fontsChanged() 0086 */ 0087 Q_PROPERTY(QVariantMap fonts READ fonts WRITE setFonts NOTIFY fontsChanged) 0088 /** 0089 * \property iconPath 0090 * \brief The path used to look up icons from the theme. 0091 * 0092 * Relative paths are relative to the theme directory. 0093 * 0094 * \default "icons/" 0095 * \get iconPath() const 0096 * \set setIconPath() 0097 * \notify iconPathChanged() 0098 */ 0099 Q_PROPERTY(QString iconPath READ iconPath WRITE setIconPath NOTIFY iconPathChanged) 0100 /** 0101 * \property imagePath 0102 * \brief The path used to look up images from the theme. 0103 * 0104 * Relative paths are relative to the theme directory. 0105 * 0106 * \default "images/" 0107 * \get imagePath() const 0108 * \set setImagePath() 0109 * \notify imagePathChanged() 0110 */ 0111 Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath NOTIFY imagePathChanged) 0112 /** 0113 * \property fontPath 0114 * \brief A path containing additional fonts to load. 0115 * 0116 * The fontPath specifies a directory that will be searched for font files. These 0117 * font files will then be made available for use in the theme. 0118 * 0119 * \default "fonts/" 0120 * \get fontPath() const 0121 * \set setFontPath() 0122 * \notify fontPathChanged() 0123 */ 0124 Q_PROPERTY(QString fontPath READ fontPath WRITE setFontPath NOTIFY fontPathChanged) 0125 public: 0126 explicit Theme(QObject* parent = 0); 0127 ~Theme() override; 0128 0129 /** 0130 * Getter for property #id. 0131 */ 0132 QString id() const; 0133 /** 0134 * Setter for property #id. 0135 */ 0136 void setId(const QString& newValue); 0137 0138 /** 0139 * Getter for property #name. 0140 */ 0141 QString name() const; 0142 /** 0143 * Setter for property #name. 0144 */ 0145 void setName(const QString& newValue); 0146 0147 /** 0148 * Getter for property #inherits. 0149 */ 0150 QString inherits() const; 0151 /** 0152 * Setter for property #inherits. 0153 */ 0154 void setInherits(const QString& newValue); 0155 0156 /** 0157 * Getter for property #colors. 0158 */ 0159 QVariantMap colors() const; 0160 /** 0161 * Setter for property #colors. 0162 */ 0163 void setColors(const QVariantMap& newValue); 0164 0165 /** 0166 * Getter for property #sizes. 0167 */ 0168 QVariantMap sizes() const; 0169 /** 0170 * Setter for property #sizes. 0171 */ 0172 void setSizes(const QVariantMap& newValue); 0173 0174 /** 0175 * Getter for property #fonts. 0176 */ 0177 QVariantMap fonts() const; 0178 /** 0179 * Setter for property #fonts. 0180 */ 0181 void setFonts(const QVariantMap& newValue); 0182 0183 /** 0184 * Getter for property #iconPath. 0185 */ 0186 QString iconPath() const; 0187 /** 0188 * Setter for property #iconPath. 0189 */ 0190 void setIconPath(const QString& newValue); 0191 0192 /** 0193 * Getter for property #imagePath. 0194 */ 0195 QString imagePath() const; 0196 /** 0197 * Setter for property #imagePath. 0198 */ 0199 void setImagePath(const QString& newValue); 0200 0201 /** 0202 * Getter for property #fontPath. 0203 */ 0204 QString fontPath() const; 0205 /** 0206 * Setter for property #fontPath. 0207 */ 0208 void setFontPath(const QString& newValue); 0209 0210 /** 0211 * Get a single color from the theme. 0212 * 0213 * \param name The color to get. 0214 * \return The color asked for, or a default color if it is not defined in the theme. 0215 */ 0216 Q_INVOKABLE QColor color(const QString& name); 0217 /** 0218 * Get a single size value from the theme. 0219 */ 0220 Q_INVOKABLE float size(const QString& name); 0221 /** 0222 * Get an icon from the theme. 0223 */ 0224 Q_INVOKABLE QUrl icon(const QString& name, bool useSystemFallback = false); 0225 /** 0226 * Get an icon from the theme. 0227 */ 0228 Q_INVOKABLE QIcon iconActual(const QString& name); 0229 /** 0230 * Get a font from the theme. 0231 */ 0232 Q_INVOKABLE QFont font(const QString& name); 0233 /** 0234 * Get an image from the theme. 0235 */ 0236 Q_INVOKABLE QUrl image(const QString& name); 0237 /** 0238 * Adjust a pixel size according to what it would be given that is what the pixel would 0239 * be on a 1080p monitor 0240 */ 0241 Q_INVOKABLE int adjustedPixel(const int& pixel) const; 0242 0243 static Theme* load(const QString& id, QObject* parent = 0); 0244 0245 Q_SIGNALS: 0246 void idChanged(); 0247 void nameChanged(); 0248 void inheritsChanged(); 0249 void colorsChanged(); 0250 void sizesChanged(); 0251 void fontsChanged(); 0252 void iconPathChanged(); 0253 void imagePathChanged(); 0254 void fontPathChanged(); 0255 void fontCacheRebuilt(); 0256 0257 protected: 0258 bool eventFilter(QObject*, QEvent*) override; 0259 0260 private: 0261 class Private; 0262 Private * const d; 0263 }; 0264 0265 #endif // THEME_H