| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | #ifndef QICONLOADER_P_H | 
| 41 | #define QICONLOADER_P_H | 
| 42 |  | 
| 43 | #include <QtGui/private/qtguiglobal_p.h> | 
| 44 |  | 
| 45 | #ifndef QT_NO_ICON | 
| 46 | // | 
| 47 | //  W A R N I N G | 
| 48 | //  ------------- | 
| 49 | // | 
| 50 | // This file is not part of the Qt API.  It exists purely as an | 
| 51 | // implementation detail.  This header file may change from version to | 
| 52 | // version without notice, or even be removed. | 
| 53 | // | 
| 54 | // We mean it. | 
| 55 | // | 
| 56 |  | 
| 57 | #include <QtGui/QIcon> | 
| 58 | #include <QtGui/QIconEngine> | 
| 59 | #include <QtGui/QPixmapCache> | 
| 60 | #include <private/qicon_p.h> | 
| 61 | #include <private/qfactoryloader_p.h> | 
| 62 | #include <QtCore/QHash> | 
| 63 | #include <QtCore/QVector> | 
| 64 | #include <QtCore/QTypeInfo> | 
| 65 |  | 
| 66 | QT_BEGIN_NAMESPACE | 
| 67 |  | 
| 68 | class QIconLoader; | 
| 69 |  | 
| 70 | struct QIconDirInfo | 
| 71 | { | 
| 72 |     enum Type { Fixed, Scalable, Threshold, Fallback }; | 
| 73 |     QIconDirInfo(const QString &_path = QString()) : | 
| 74 |             path(_path), | 
| 75 |             size(0), | 
| 76 |             maxSize(0), | 
| 77 |             minSize(0), | 
| 78 |             threshold(0), | 
| 79 |             scale(1), | 
| 80 |             type(Threshold) {} | 
| 81 |     QString path; | 
| 82 |     short size; | 
| 83 |     short maxSize; | 
| 84 |     short minSize; | 
| 85 |     short threshold; | 
| 86 |     short scale; | 
| 87 |     Type type; | 
| 88 | }; | 
| 89 | Q_DECLARE_TYPEINFO(QIconDirInfo, Q_MOVABLE_TYPE); | 
| 90 |  | 
| 91 | class QIconLoaderEngineEntry | 
| 92 |  { | 
| 93 | public: | 
| 94 |     virtual ~QIconLoaderEngineEntry() {} | 
| 95 |     virtual QPixmap pixmap(const QSize &size, | 
| 96 |                            QIcon::Mode mode, | 
| 97 |                            QIcon::State state) = 0; | 
| 98 |     QString filename; | 
| 99 |     QIconDirInfo dir; | 
| 100 | }; | 
| 101 |  | 
| 102 | struct ScalableEntry : public QIconLoaderEngineEntry | 
| 103 | { | 
| 104 |     QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; | 
| 105 |     QIcon svgIcon; | 
| 106 | }; | 
| 107 |  | 
| 108 | struct PixmapEntry : public QIconLoaderEngineEntry | 
| 109 | { | 
| 110 |     QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; | 
| 111 |     QPixmap basePixmap; | 
| 112 | }; | 
| 113 |  | 
| 114 | typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries; | 
| 115 |  | 
| 116 | struct QThemeIconInfo | 
| 117 | { | 
| 118 |     QThemeIconEntries entries; | 
| 119 |     QString iconName; | 
| 120 | }; | 
| 121 |  | 
| 122 | class QIconLoaderEngine : public QIconEngine | 
| 123 | { | 
| 124 | public: | 
| 125 |     QIconLoaderEngine(const QString& iconName = QString()); | 
| 126 |     ~QIconLoaderEngine(); | 
| 127 |  | 
| 128 |     void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; | 
| 129 |     QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; | 
| 130 |     QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override; | 
| 131 |     QIconEngine *clone() const override; | 
| 132 |     bool read(QDataStream &in) override; | 
| 133 |     bool write(QDataStream &out) const override; | 
| 134 |  | 
| 135 |     Q_GUI_EXPORT static QIconLoaderEngineEntry *entryForSize(const QThemeIconInfo &info, const QSize &size, int scale = 1); | 
| 136 |  | 
| 137 | private: | 
| 138 |     QString key() const override; | 
| 139 |     bool hasIcon() const; | 
| 140 |     void ensureLoaded(); | 
| 141 |     void virtual_hook(int id, void *data) override; | 
| 142 |  | 
| 143 |     QIconLoaderEngine(const QIconLoaderEngine &other); | 
| 144 |     QThemeIconInfo m_info; | 
| 145 |     QString m_iconName; | 
| 146 |     uint m_key; | 
| 147 |  | 
| 148 |     friend class QIconLoader; | 
| 149 | }; | 
| 150 |  | 
| 151 | class QIconCacheGtkReader; | 
| 152 |  | 
| 153 | class QIconTheme | 
| 154 | { | 
| 155 | public: | 
| 156 |     QIconTheme(const QString &name); | 
| 157 |     QIconTheme() : m_valid(false) {} | 
| 158 |     QStringList parents() { return m_parents; } | 
| 159 |     QVector<QIconDirInfo> keyList() { return m_keyList; } | 
| 160 |     QStringList contentDirs() { return m_contentDirs; } | 
| 161 |     bool isValid() { return m_valid; } | 
| 162 | private: | 
| 163 |     QStringList m_contentDirs; | 
| 164 |     QVector<QIconDirInfo> m_keyList; | 
| 165 |     QStringList m_parents; | 
| 166 |     bool m_valid; | 
| 167 | public: | 
| 168 |     QVector<QSharedPointer<QIconCacheGtkReader>> m_gtkCaches; | 
| 169 | }; | 
| 170 |  | 
| 171 | class Q_GUI_EXPORT QIconLoader | 
| 172 | { | 
| 173 | public: | 
| 174 |     QIconLoader(); | 
| 175 |     QThemeIconInfo loadIcon(const QString &iconName) const; | 
| 176 |     uint themeKey() const { return m_themeKey; } | 
| 177 |  | 
| 178 |     QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; } | 
| 179 |     void setThemeName(const QString &themeName); | 
| 180 |     QString fallbackThemeName() const; | 
| 181 |     void setFallbackThemeName(const QString &themeName); | 
| 182 |     QIconTheme theme() { return themeList.value(akey: themeName()); } | 
| 183 |     void setThemeSearchPath(const QStringList &searchPaths); | 
| 184 |     QStringList themeSearchPaths() const; | 
| 185 |     void setFallbackSearchPaths(const QStringList &searchPaths); | 
| 186 |     QStringList fallbackSearchPaths() const; | 
| 187 |     QIconDirInfo dirInfo(int dirindex); | 
| 188 |     static QIconLoader *instance(); | 
| 189 |     void updateSystemTheme(); | 
| 190 |     void invalidateKey() { m_themeKey++; } | 
| 191 |     void ensureInitialized(); | 
| 192 |     bool hasUserTheme() const { return !m_userTheme.isEmpty(); } | 
| 193 |  | 
| 194 | private: | 
| 195 |     QThemeIconInfo findIconHelper(const QString &themeName, | 
| 196 |                                   const QString &iconName, | 
| 197 |                                   QStringList &visited) const; | 
| 198 |     QThemeIconInfo lookupFallbackIcon(const QString &iconName) const; | 
| 199 |  | 
| 200 |     uint m_themeKey; | 
| 201 |     bool m_supportsSvg; | 
| 202 |     bool m_initialized; | 
| 203 |  | 
| 204 |     mutable QString m_userTheme; | 
| 205 |     mutable QString m_userFallbackTheme; | 
| 206 |     mutable QString m_systemTheme; | 
| 207 |     mutable QStringList m_iconDirs; | 
| 208 |     mutable QHash <QString, QIconTheme> themeList; | 
| 209 |     mutable QStringList m_fallbackDirs; | 
| 210 | }; | 
| 211 |  | 
| 212 | QT_END_NAMESPACE | 
| 213 |  | 
| 214 | #endif // QT_NO_ICON | 
| 215 |  | 
| 216 | #endif // QICONLOADER_P_H | 
| 217 |  |