1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QDESKTOPICON_P_H
43#define QDESKTOPICON_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
64QT_BEGIN_NAMESPACE
65
66class QIconLoader;
67
68struct QIconDirInfo
69{
70 enum Type { Fixed, Scalable, Threshold };
71 QIconDirInfo(const QString &_path = QString()) :
72 path(_path),
73 size(0),
74 maxSize(0),
75 minSize(0),
76 threshold(0),
77 type(Threshold) {}
78 QString path;
79 short size;
80 short maxSize;
81 short minSize;
82 short threshold;
83 Type type : 4;
84};
85
86class QIconLoaderEngineEntry
87 {
88public:
89 virtual ~QIconLoaderEngineEntry() {}
90 virtual QPixmap pixmap(const QSize &size,
91 QIcon::Mode mode,
92 QIcon::State state) = 0;
93 QString filename;
94 QIconDirInfo dir;
95 static int count;
96};
97
98struct ScalableEntry : public QIconLoaderEngineEntry
99{
100 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
101 QIcon svgIcon;
102};
103
104struct PixmapEntry : public QIconLoaderEngineEntry
105{
106 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
107 QPixmap basePixmap;
108};
109
110typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries;
111
112class QIconLoaderEngine : public QIconEngineV2
113{
114public:
115 QIconLoaderEngine(const QString& iconName = QString());
116 ~QIconLoaderEngine();
117
118 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state);
119 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
120 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state);
121 QIconEngineV2 *clone() const;
122 bool read(QDataStream &in);
123 bool write(QDataStream &out) const;
124
125private:
126 QString key() const;
127 bool hasIcon() const;
128 void ensureLoaded();
129 void virtual_hook(int id, void *data);
130 QIconLoaderEngineEntry *entryForSize(const QSize &size);
131 QIconLoaderEngine(const QIconLoaderEngine &other);
132 QThemeIconEntries m_entries;
133 QString m_iconName;
134 uint m_key;
135
136 friend class QIconLoader;
137};
138
139class QIconTheme
140{
141public:
142 QIconTheme(const QString &name);
143 QIconTheme() : m_valid(false) {}
144 QStringList parents() { return m_parents; }
145 QList <QIconDirInfo> keyList() { return m_keyList; }
146 QString contentDir() { return m_contentDir; }
147 bool isValid() { return m_valid; }
148
149private:
150 QString m_contentDir;
151 QList <QIconDirInfo> m_keyList;
152 QStringList m_parents;
153 bool m_valid;
154};
155
156class QIconLoader : public QObject
157{
158public:
159 QIconLoader();
160 QThemeIconEntries loadIcon(const QString &iconName) const;
161 uint themeKey() const { return m_themeKey; }
162
163 QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; }
164 void setThemeName(const QString &themeName);
165 QIconTheme theme() { return themeList.value(themeName()); }
166 void setThemeSearchPath(const QStringList &searchPaths);
167 QStringList themeSearchPaths() const;
168 QIconDirInfo dirInfo(int dirindex);
169 static QIconLoader *instance();
170 void updateSystemTheme();
171 void invalidateKey() { m_themeKey++; }
172 void ensureInitialized();
173
174private:
175 QThemeIconEntries findIconHelper(const QString &themeName,
176 const QString &iconName,
177 QStringList &visited) const;
178 uint m_themeKey;
179 bool m_supportsSvg;
180 bool m_initialized;
181
182 mutable QString m_userTheme;
183 mutable QString m_systemTheme;
184 mutable QStringList m_iconDirs;
185 mutable QHash <QString, QIconTheme> themeList;
186};
187
188QT_END_NAMESPACE
189
190#endif // QDESKTOPICON_P_H
191
192#endif //QT_NO_ICON
193