|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QDESKTOPICON_P_H |
|
43 #define QDESKTOPICON_P_H |
|
44 |
|
45 // |
|
46 // W A R N I N G |
|
47 // ------------- |
|
48 // |
|
49 // This file is not part of the Qt API. It exists purely as an |
|
50 // implementation detail. This header file may change from version to |
|
51 // version without notice, or even be removed. |
|
52 // |
|
53 // We mean it. |
|
54 // |
|
55 |
|
56 #include <QtGui/QIcon> |
|
57 #include <QtGui/QIconEngine> |
|
58 #include <QtGui/QPixmapCache> |
|
59 #include <private/qicon_p.h> |
|
60 #include <private/qfactoryloader_p.h> |
|
61 #include <QtCore/QHash> |
|
62 |
|
63 QT_BEGIN_NAMESPACE |
|
64 |
|
65 class QIconLoader; |
|
66 |
|
67 struct QIconDirInfo |
|
68 { |
|
69 enum Type { Fixed, Scalable, Threshold }; |
|
70 QIconDirInfo(const QString &_path = QString()) : |
|
71 path(_path), |
|
72 size(0), |
|
73 maxSize(0), |
|
74 minSize(0), |
|
75 threshold(0), |
|
76 type(Threshold) {} |
|
77 QString path; |
|
78 short size; |
|
79 short maxSize; |
|
80 short minSize; |
|
81 short threshold; |
|
82 Type type : 4; |
|
83 }; |
|
84 |
|
85 class QIconLoaderEngineEntry |
|
86 { |
|
87 public: |
|
88 virtual ~QIconLoaderEngineEntry() {} |
|
89 virtual QPixmap pixmap(const QSize &size, |
|
90 QIcon::Mode mode, |
|
91 QIcon::State state) = 0; |
|
92 QString filename; |
|
93 QIconDirInfo dir; |
|
94 static int count; |
|
95 }; |
|
96 |
|
97 struct ScalableEntry : public QIconLoaderEngineEntry |
|
98 { |
|
99 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state); |
|
100 QIcon svgIcon; |
|
101 }; |
|
102 |
|
103 struct PixmapEntry : public QIconLoaderEngineEntry |
|
104 { |
|
105 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state); |
|
106 QPixmap basePixmap; |
|
107 }; |
|
108 |
|
109 typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries; |
|
110 |
|
111 class QIconLoaderEngine : public QIconEngineV2 |
|
112 { |
|
113 public: |
|
114 QIconLoaderEngine(const QString& iconName = QString()); |
|
115 ~QIconLoaderEngine(); |
|
116 |
|
117 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state); |
|
118 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state); |
|
119 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state); |
|
120 QIconEngineV2 *clone() const; |
|
121 bool read(QDataStream &in); |
|
122 bool write(QDataStream &out) const; |
|
123 |
|
124 private: |
|
125 QString key() const; |
|
126 bool hasIcon() const; |
|
127 void ensureLoaded(); |
|
128 void virtual_hook(int id, void *data); |
|
129 QIconLoaderEngineEntry *entryForSize(const QSize &size); |
|
130 QIconLoaderEngine(const QIconLoaderEngine &other); |
|
131 QThemeIconEntries m_entries; |
|
132 QString m_iconName; |
|
133 uint m_key; |
|
134 |
|
135 friend class QIconLoader; |
|
136 }; |
|
137 |
|
138 class QIconTheme |
|
139 { |
|
140 public: |
|
141 QIconTheme(const QString &name); |
|
142 QIconTheme() : m_valid(false) {} |
|
143 QStringList parents() { return m_parents; } |
|
144 QList <QIconDirInfo> keyList() { return m_keyList; } |
|
145 QString contentDir() { return m_contentDir; } |
|
146 bool isValid() { return m_valid; } |
|
147 |
|
148 private: |
|
149 QString m_contentDir; |
|
150 QList <QIconDirInfo> m_keyList; |
|
151 QStringList m_parents; |
|
152 bool m_valid; |
|
153 }; |
|
154 |
|
155 class QIconLoader : public QObject |
|
156 { |
|
157 public: |
|
158 QIconLoader(); |
|
159 QThemeIconEntries loadIcon(const QString &iconName) const; |
|
160 uint themeKey() const { return m_themeKey; } |
|
161 |
|
162 QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; } |
|
163 void setThemeName(const QString &themeName); |
|
164 QIconTheme theme() { return themeList.value(themeName()); } |
|
165 void setThemeSearchPath(const QStringList &searchPaths); |
|
166 QStringList themeSearchPaths() const; |
|
167 QIconDirInfo dirInfo(int dirindex); |
|
168 static QIconLoader *instance(); |
|
169 void updateSystemTheme(); |
|
170 void invalidateKey() { m_themeKey++; } |
|
171 |
|
172 private: |
|
173 QThemeIconEntries findIconHelper(const QString &themeName, |
|
174 const QString &iconName, |
|
175 QStringList &visited) const; |
|
176 uint m_themeKey; |
|
177 bool m_supportsSvg; |
|
178 |
|
179 mutable QString m_userTheme; |
|
180 mutable QString m_systemTheme; |
|
181 mutable QStringList m_iconDirs; |
|
182 mutable QHash <QString, QIconTheme> themeList; |
|
183 }; |
|
184 |
|
185 QT_END_NAMESPACE |
|
186 |
|
187 #endif // QDESKTOPICON_P_H |