image/qiconloader.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 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#ifndef QT_NO_ICON -
42#include <private/qiconloader_p.h> -
43 -
44#include <private/qguiapplication_p.h> -
45#include <private/qicon_p.h> -
46 -
47#include <QtGui/QIconEnginePlugin> -
48#include <QtGui/QPixmapCache> -
49#include <qpa/qplatformtheme.h> -
50#include <QtGui/QIconEngine> -
51#include <QtGui/QPalette> -
52#include <QtCore/QList> -
53#include <QtCore/QHash> -
54#include <QtCore/QDir> -
55#include <QtCore/QSettings> -
56#include <QtGui/QPainter> -
57 -
58#ifdef Q_WS_MAC -
59#include <private/qt_cocoa_helpers_mac_p.h> -
60#endif -
61 -
62#include <private/qhexstring_p.h> -
63 -
64QT_BEGIN_NAMESPACE -
65 -
66Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:6959
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:29
yes
Evaluation Count:6930
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:29
no
Evaluation Count:0
0-6959
67 -
68/* Theme to use in last resort, if the theme does not have the icon, neither the parents */ -
69static QString fallbackTheme() -
70{ -
71 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
partially evaluated: const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
72 const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
executed (the execution status of this line is deduced): const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
-
73 if (themeHint.isValid())
partially evaluated: themeHint.isValid()
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
74 return themeHint.toString();
executed: return themeHint.toString();
Execution Count:9
9
75 }
never executed: }
0
76 return QString();
never executed: return QString();
0
77} -
78 -
79QIconLoader::QIconLoader() : -
80 m_themeKey(1), m_supportsSvg(false), m_initialized(false) -
81{ -
82}
executed: }
Execution Count:29
29
83 -
84// We lazily initialize the loader to make static icons -
85// work. Though we do not officially support this. -
86 -
87static inline QString systemThemeName() -
88{ -
89 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
partially evaluated: const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
90 const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
executed (the execution status of this line is deduced): const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);
-
91 if (themeHint.isValid())
partially evaluated: themeHint.isValid()
TRUEFALSE
yes
Evaluation Count:1
no
Evaluation Count:0
0-1
92 return themeHint.toString();
executed: return themeHint.toString();
Execution Count:1
1
93 }
never executed: }
0
94 return QString();
never executed: return QString();
0
95} -
96 -
97static inline QStringList systemIconSearchPaths() -
98{ -
99 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
never evaluated: const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
0
100 const QVariant themeHint = theme->themeHint(QPlatformTheme::IconThemeSearchPaths);
never executed (the execution status of this line is deduced): const QVariant themeHint = theme->themeHint(QPlatformTheme::IconThemeSearchPaths);
-
101 if (themeHint.isValid())
never evaluated: themeHint.isValid()
0
102 return themeHint.toStringList();
never executed: return themeHint.toStringList();
0
103 }
never executed: }
0
104 return QStringList();
never executed: return QStringList();
0
105} -
106 -
107void QIconLoader::ensureInitialized() -
108{ -
109 if (!m_initialized) {
evaluated: !m_initialized
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:21
1-21
110 m_initialized = true;
executed (the execution status of this line is deduced): m_initialized = true;
-
111 -
112 Q_ASSERT(qApp);
executed (the execution status of this line is deduced): qt_noop();
-
113 -
114 m_systemTheme = systemThemeName();
executed (the execution status of this line is deduced): m_systemTheme = systemThemeName();
-
115 -
116 if (m_systemTheme.isEmpty())
partially evaluated: m_systemTheme.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
117 m_systemTheme = fallbackTheme();
never executed: m_systemTheme = fallbackTheme();
0
118#ifndef QT_NO_LIBRARY -
119 QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterface_iid,
executed (the execution status of this line is deduced): QFactoryLoader iconFactoryLoader("org.qt-project.Qt.QIconEngineFactoryInterface",
-
120 QLatin1String("/iconengines"),
executed (the execution status of this line is deduced): QLatin1String("/iconengines"),
-
121 Qt::CaseInsensitive);
executed (the execution status of this line is deduced): Qt::CaseInsensitive);
-
122 if (iconFactoryLoader.keyMap().key(QLatin1String("svg"), -1) != -1)
partially evaluated: iconFactoryLoader.keyMap().key(QLatin1String("svg"), -1) != -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
123 m_supportsSvg = true;
never executed: m_supportsSvg = true;
0
124#endif //QT_NO_LIBRARY -
125 }
executed: }
Execution Count:1
1
126}
executed: }
Execution Count:22
22
127 -
128QIconLoader *QIconLoader::instance() -
129{ -
130 return iconLoaderInstance();
executed: return iconLoaderInstance();
Execution Count:6884
6884
131} -
132 -
133// Queries the system theme and invalidates existing -
134// icons if the theme has changed. -
135void QIconLoader::updateSystemTheme() -
136{ -
137 // Only change if this is not explicitly set by the user -
138 if (m_userTheme.isEmpty()) {
never evaluated: m_userTheme.isEmpty()
0
139 QString theme = systemThemeName();
never executed (the execution status of this line is deduced): QString theme = systemThemeName();
-
140 if (theme.isEmpty())
never evaluated: theme.isEmpty()
0
141 theme = fallbackTheme();
never executed: theme = fallbackTheme();
0
142 if (theme != m_systemTheme) {
never evaluated: theme != m_systemTheme
0
143 m_systemTheme = theme;
never executed (the execution status of this line is deduced): m_systemTheme = theme;
-
144 invalidateKey();
never executed (the execution status of this line is deduced): invalidateKey();
-
145 }
never executed: }
0
146 }
never executed: }
0
147}
never executed: }
0
148 -
149void QIconLoader::setThemeName(const QString &themeName) -
150{ -
151 m_userTheme = themeName;
executed (the execution status of this line is deduced): m_userTheme = themeName;
-
152 invalidateKey();
executed (the execution status of this line is deduced): invalidateKey();
-
153}
executed: }
Execution Count:3
3
154 -
155void QIconLoader::setThemeSearchPath(const QStringList &searchPaths) -
156{ -
157 m_iconDirs = searchPaths;
executed (the execution status of this line is deduced): m_iconDirs = searchPaths;
-
158 themeList.clear();
executed (the execution status of this line is deduced): themeList.clear();
-
159 invalidateKey();
executed (the execution status of this line is deduced): invalidateKey();
-
160}
executed: }
Execution Count:2
2
161 -
162QStringList QIconLoader::themeSearchPaths() const -
163{ -
164 if (m_iconDirs.isEmpty()) {
partially evaluated: m_iconDirs.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23
0-23
165 m_iconDirs = systemIconSearchPaths();
never executed (the execution status of this line is deduced): m_iconDirs = systemIconSearchPaths();
-
166 // Always add resource directory as search path -
167 m_iconDirs.append(QLatin1String(":/icons"));
never executed (the execution status of this line is deduced): m_iconDirs.append(QLatin1String(":/icons"));
-
168 }
never executed: }
0
169 return m_iconDirs;
executed: return m_iconDirs;
Execution Count:23
23
170} -
171 -
172QIconTheme::QIconTheme(const QString &themeName) -
173 : m_valid(false) -
174{ -
175 QFile themeIndex;
executed (the execution status of this line is deduced): QFile themeIndex;
-
176 -
177 QList <QIconDirInfo> keyList;
executed (the execution status of this line is deduced): QList <QIconDirInfo> keyList;
-
178 QStringList iconDirs = QIcon::themeSearchPaths();
executed (the execution status of this line is deduced): QStringList iconDirs = QIcon::themeSearchPaths();
-
179 for ( int i = 0 ; i < iconDirs.size() ; ++i) {
evaluated: i < iconDirs.size()
TRUEFALSE
yes
Evaluation Count:21
yes
Evaluation Count:18
18-21
180 QDir iconDir(iconDirs[i]);
executed (the execution status of this line is deduced): QDir iconDir(iconDirs[i]);
-
181 QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
executed (the execution status of this line is deduced): QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;
-
182 themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
executed (the execution status of this line is deduced): themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));
-
183 if (themeIndex.exists()) {
evaluated: themeIndex.exists()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:18
3-18
184 m_contentDir = themeDir;
executed (the execution status of this line is deduced): m_contentDir = themeDir;
-
185 m_valid = true;
executed (the execution status of this line is deduced): m_valid = true;
-
186 break;
executed: break;
Execution Count:3
3
187 } -
188 }
executed: }
Execution Count:18
18
189#ifndef QT_NO_SETTINGS -
190 if (themeIndex.exists()) {
evaluated: themeIndex.exists()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:18
3-18
191 const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
executed (the execution status of this line is deduced): const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);
-
192 QStringListIterator keyIterator(indexReader.allKeys());
executed (the execution status of this line is deduced): QStringListIterator keyIterator(indexReader.allKeys());
-
193 while (keyIterator.hasNext()) {
evaluated: keyIterator.hasNext()
TRUEFALSE
yes
Evaluation Count:921
yes
Evaluation Count:3
3-921
194 -
195 const QString key = keyIterator.next();
executed (the execution status of this line is deduced): const QString key = keyIterator.next();
-
196 if (key.endsWith(QLatin1String("/Size"))) {
evaluated: key.endsWith(QLatin1String("/Size"))
TRUEFALSE
yes
Evaluation Count:270
yes
Evaluation Count:651
270-651
197 // Note the QSettings ini-format does not accept -
198 // slashes in key names, hence we have to cheat -
199 if (int size = indexReader.value(key).toInt()) {
partially evaluated: int size = indexReader.value(key).toInt()
TRUEFALSE
yes
Evaluation Count:270
no
Evaluation Count:0
0-270
200 QString directoryKey = key.left(key.size() - 5);
executed (the execution status of this line is deduced): QString directoryKey = key.left(key.size() - 5);
-
201 QIconDirInfo dirInfo(directoryKey);
executed (the execution status of this line is deduced): QIconDirInfo dirInfo(directoryKey);
-
202 dirInfo.size = size;
executed (the execution status of this line is deduced): dirInfo.size = size;
-
203 QString type = indexReader.value(directoryKey +
executed (the execution status of this line is deduced): QString type = indexReader.value(directoryKey +
-
204 QLatin1String("/Type")
executed (the execution status of this line is deduced): QLatin1String("/Type")
-
205 ).toString();
executed (the execution status of this line is deduced): ).toString();
-
206 -
207 if (type == QLatin1String("Fixed"))
evaluated: type == QLatin1String("Fixed")
TRUEFALSE
yes
Evaluation Count:243
yes
Evaluation Count:27
27-243
208 dirInfo.type = QIconDirInfo::Fixed;
executed: dirInfo.type = QIconDirInfo::Fixed;
Execution Count:243
243
209 else if (type == QLatin1String("Scalable"))
partially evaluated: type == QLatin1String("Scalable")
TRUEFALSE
yes
Evaluation Count:27
no
Evaluation Count:0
0-27
210 dirInfo.type = QIconDirInfo::Scalable;
executed: dirInfo.type = QIconDirInfo::Scalable;
Execution Count:27
27
211 else -
212 dirInfo.type = QIconDirInfo::Threshold;
never executed: dirInfo.type = QIconDirInfo::Threshold;
0
213 -
214 dirInfo.threshold = indexReader.value(directoryKey +
executed (the execution status of this line is deduced): dirInfo.threshold = indexReader.value(directoryKey +
-
215 QLatin1String("/Threshold"),
executed (the execution status of this line is deduced): QLatin1String("/Threshold"),
-
216 2).toInt();
executed (the execution status of this line is deduced): 2).toInt();
-
217 -
218 dirInfo.minSize = indexReader.value(directoryKey +
executed (the execution status of this line is deduced): dirInfo.minSize = indexReader.value(directoryKey +
-
219 QLatin1String("/MinSize"),
executed (the execution status of this line is deduced): QLatin1String("/MinSize"),
-
220 size).toInt();
executed (the execution status of this line is deduced): size).toInt();
-
221 -
222 dirInfo.maxSize = indexReader.value(directoryKey +
executed (the execution status of this line is deduced): dirInfo.maxSize = indexReader.value(directoryKey +
-
223 QLatin1String("/MaxSize"),
executed (the execution status of this line is deduced): QLatin1String("/MaxSize"),
-
224 size).toInt();
executed (the execution status of this line is deduced): size).toInt();
-
225 m_keyList.append(dirInfo);
executed (the execution status of this line is deduced): m_keyList.append(dirInfo);
-
226 }
executed: }
Execution Count:270
270
227 }
executed: }
Execution Count:270
270
228 }
executed: }
Execution Count:921
921
229 -
230 // Parent themes provide fallbacks for missing icons -
231 m_parents = indexReader.value(
executed (the execution status of this line is deduced): m_parents = indexReader.value(
-
232 QLatin1String("Icon Theme/Inherits")).toStringList();
executed (the execution status of this line is deduced): QLatin1String("Icon Theme/Inherits")).toStringList();
-
233 -
234 // Ensure a default platform fallback for all themes -
235 if (m_parents.isEmpty()) {
partially evaluated: m_parents.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
236 const QString fallback = fallbackTheme();
never executed (the execution status of this line is deduced): const QString fallback = fallbackTheme();
-
237 if (!fallback.isEmpty())
never evaluated: !fallback.isEmpty()
0
238 m_parents.append(fallback);
never executed: m_parents.append(fallback);
0
239 }
never executed: }
0
240 -
241 // Ensure that all themes fall back to hicolor -
242 if (!m_parents.contains(QLatin1String("hicolor")))
partially evaluated: !m_parents.contains(QLatin1String("hicolor"))
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
243 m_parents.append(QLatin1String("hicolor"));
executed: m_parents.append(QLatin1String("hicolor"));
Execution Count:3
3
244 }
executed: }
Execution Count:3
3
245#endif //QT_NO_SETTINGS -
246}
executed: }
Execution Count:21
21
247 -
248QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName, -
249 const QString &iconName, -
250 QStringList &visited) const -
251{ -
252 QThemeIconEntries entries;
executed (the execution status of this line is deduced): QThemeIconEntries entries;
-
253 Q_ASSERT(!themeName.isEmpty());
executed (the execution status of this line is deduced): qt_noop();
-
254 -
255 QPixmap pixmap;
executed (the execution status of this line is deduced): QPixmap pixmap;
-
256 -
257 // Used to protect against potential recursions -
258 visited << themeName;
executed (the execution status of this line is deduced): visited << themeName;
-
259 -
260 QIconTheme theme = themeList.value(themeName);
executed (the execution status of this line is deduced): QIconTheme theme = themeList.value(themeName);
-
261 if (!theme.isValid()) {
evaluated: !theme.isValid()
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:7
7-12
262 theme = QIconTheme(themeName);
executed (the execution status of this line is deduced): theme = QIconTheme(themeName);
-
263 if (!theme.isValid())
evaluated: !theme.isValid()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:3
3-9
264 theme = QIconTheme(fallbackTheme());
executed: theme = QIconTheme(fallbackTheme());
Execution Count:9
9
265 -
266 themeList.insert(themeName, theme);
executed (the execution status of this line is deduced): themeList.insert(themeName, theme);
-
267 }
executed: }
Execution Count:12
12
268 -
269 QString contentDir = theme.contentDir() + QLatin1Char('/');
executed (the execution status of this line is deduced): QString contentDir = theme.contentDir() + QLatin1Char('/');
-
270 QList<QIconDirInfo> subDirs = theme.keyList();
executed (the execution status of this line is deduced): QList<QIconDirInfo> subDirs = theme.keyList();
-
271 -
272 const QString svgext(QLatin1String(".svg"));
executed (the execution status of this line is deduced): const QString svgext(QLatin1String(".svg"));
-
273 const QString pngext(QLatin1String(".png"));
executed (the execution status of this line is deduced): const QString pngext(QLatin1String(".png"));
-
274 -
275 // Add all relevant files -
276 for (int i = 0; i < subDirs.size() ; ++i) {
evaluated: i < subDirs.size()
TRUEFALSE
yes
Evaluation Count:900
yes
Evaluation Count:19
19-900
277 const QIconDirInfo &dirInfo = subDirs.at(i);
executed (the execution status of this line is deduced): const QIconDirInfo &dirInfo = subDirs.at(i);
-
278 QString subdir = dirInfo.path;
executed (the execution status of this line is deduced): QString subdir = dirInfo.path;
-
279 QDir currentDir(contentDir + subdir);
executed (the execution status of this line is deduced): QDir currentDir(contentDir + subdir);
-
280 if (currentDir.exists(iconName + pngext)) {
evaluated: currentDir.exists(iconName + pngext)
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:888
12-888
281 PixmapEntry *iconEntry = new PixmapEntry;
executed (the execution status of this line is deduced): PixmapEntry *iconEntry = new PixmapEntry;
-
282 iconEntry->dir = dirInfo;
executed (the execution status of this line is deduced): iconEntry->dir = dirInfo;
-
283 iconEntry->filename = currentDir.filePath(iconName + pngext);
executed (the execution status of this line is deduced): iconEntry->filename = currentDir.filePath(iconName + pngext);
-
284 // Notice we ensure that pixmap entries always come before -
285 // scalable to preserve search order afterwards -
286 entries.prepend(iconEntry);
executed (the execution status of this line is deduced): entries.prepend(iconEntry);
-
287 } else if (m_supportsSvg &&
executed: }
Execution Count:12
partially evaluated: m_supportsSvg
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:888
0-888
288 currentDir.exists(iconName + svgext)) {
never evaluated: currentDir.exists(iconName + svgext)
0
289 ScalableEntry *iconEntry = new ScalableEntry;
never executed (the execution status of this line is deduced): ScalableEntry *iconEntry = new ScalableEntry;
-
290 iconEntry->dir = dirInfo;
never executed (the execution status of this line is deduced): iconEntry->dir = dirInfo;
-
291 iconEntry->filename = currentDir.filePath(iconName + svgext);
never executed (the execution status of this line is deduced): iconEntry->filename = currentDir.filePath(iconName + svgext);
-
292 entries.append(iconEntry);
never executed (the execution status of this line is deduced): entries.append(iconEntry);
-
293 }
never executed: }
0
294 } -
295 -
296 if (entries.isEmpty()) {
evaluated: entries.isEmpty()
TRUEFALSE
yes
Evaluation Count:15
yes
Evaluation Count:4
4-15
297 const QStringList parents = theme.parents();
executed (the execution status of this line is deduced): const QStringList parents = theme.parents();
-
298 // Search recursively through inherited themes -
299 for (int i = 0 ; i < parents.size() ; ++i) {
evaluated: i < parents.size()
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:13
13-16
300 -
301 const QString parentTheme = parents.at(i).trimmed();
executed (the execution status of this line is deduced): const QString parentTheme = parents.at(i).trimmed();
-
302 -
303 if (!visited.contains(parentTheme)) // guard against recursion
evaluated: !visited.contains(parentTheme)
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:4
4-12
304 entries = findIconHelper(parentTheme, iconName, visited);
executed: entries = findIconHelper(parentTheme, iconName, visited);
Execution Count:12
12
305 -
306 if (!entries.isEmpty()) // success
evaluated: !entries.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:14
2-14
307 break;
executed: break;
Execution Count:2
2
308 }
executed: }
Execution Count:14
14
309 }
executed: }
Execution Count:15
15
310 return entries;
executed: return entries;
Execution Count:19
19
311} -
312 -
313QThemeIconEntries QIconLoader::loadIcon(const QString &name) const -
314{ -
315 if (!themeName().isEmpty()) {
partially evaluated: !themeName().isEmpty()
TRUEFALSE
yes
Evaluation Count:7
no
Evaluation Count:0
0-7
316 QStringList visited;
executed (the execution status of this line is deduced): QStringList visited;
-
317 return findIconHelper(themeName(), name, visited);
executed: return findIconHelper(themeName(), name, visited);
Execution Count:7
7
318 } -
319 -
320 return QThemeIconEntries();
never executed: return QThemeIconEntries();
0
321} -
322 -
323 -
324// -------- Icon Loader Engine -------- // -
325 -
326 -
327QIconLoaderEngine::QIconLoaderEngine(const QString& iconName) -
328 : m_iconName(iconName), m_key(0) -
329{ -
330}
executed: }
Execution Count:6
6
331 -
332QIconLoaderEngine::~QIconLoaderEngine() -
333{ -
334 while (!m_entries.isEmpty())
evaluated: !m_entries.isEmpty()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:6
6
335 delete m_entries.takeLast();
executed: delete m_entries.takeLast();
Execution Count:6
6
336 Q_ASSERT(m_entries.size() == 0);
executed (the execution status of this line is deduced): qt_noop();
-
337}
executed: }
Execution Count:6
6
338 -
339QIconLoaderEngine::QIconLoaderEngine(const QIconLoaderEngine &other) -
340 : QIconEngine(other), -
341 m_iconName(other.m_iconName), -
342 m_key(0) -
343{ -
344}
never executed: }
0
345 -
346QIconEngine *QIconLoaderEngine::clone() const -
347{ -
348 return new QIconLoaderEngine(*this);
never executed: return new QIconLoaderEngine(*this);
0
349} -
350 -
351bool QIconLoaderEngine::read(QDataStream &in) { -
352 in >> m_iconName;
executed (the execution status of this line is deduced): in >> m_iconName;
-
353 return true;
executed: return true;
Execution Count:1
1
354} -
355 -
356bool QIconLoaderEngine::write(QDataStream &out) const -
357{ -
358 out << m_iconName;
executed (the execution status of this line is deduced): out << m_iconName;
-
359 return true;
executed: return true;
Execution Count:1
1
360} -
361 -
362bool QIconLoaderEngine::hasIcon() const -
363{ -
364 return !(m_entries.isEmpty());
never executed: return !(m_entries.isEmpty());
0
365} -
366 -
367// Lazily load the icon -
368void QIconLoaderEngine::ensureLoaded() -
369{ -
370 -
371 iconLoaderInstance()->ensureInitialized();
executed (the execution status of this line is deduced): iconLoaderInstance()->ensureInitialized();
-
372 -
373 if (!(iconLoaderInstance()->themeKey() == m_key)) {
evaluated: !(iconLoaderInstance()->themeKey() == m_key)
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:15
7-15
374 -
375 while (!m_entries.isEmpty())
evaluated: !m_entries.isEmpty()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:7
6-7
376 delete m_entries.takeLast();
executed: delete m_entries.takeLast();
Execution Count:6
6
377 -
378 Q_ASSERT(m_entries.size() == 0);
executed (the execution status of this line is deduced): qt_noop();
-
379 m_entries = iconLoaderInstance()->loadIcon(m_iconName);
executed (the execution status of this line is deduced): m_entries = iconLoaderInstance()->loadIcon(m_iconName);
-
380 m_key = iconLoaderInstance()->themeKey();
executed (the execution status of this line is deduced): m_key = iconLoaderInstance()->themeKey();
-
381 }
executed: }
Execution Count:7
7
382}
executed: }
Execution Count:22
22
383 -
384void QIconLoaderEngine::paint(QPainter *painter, const QRect &rect, -
385 QIcon::Mode mode, QIcon::State state) -
386{ -
387 QSize pixmapSize = rect.size();
never executed (the execution status of this line is deduced): QSize pixmapSize = rect.size();
-
388#if defined(Q_WS_MAC) -
389 pixmapSize *= qt_mac_get_scalefactor(); -
390#endif -
391 painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
never executed (the execution status of this line is deduced): painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));
-
392}
never executed: }
0
393 -
394/* -
395 * This algorithm is defined by the freedesktop spec: -
396 * http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html -
397 */ -
398static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize) -
399{ -
400 if (dir.type == QIconDirInfo::Fixed) {
partially evaluated: dir.type == QIconDirInfo::Fixed
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
401 return dir.size == iconsize;
executed: return dir.size == iconsize;
Execution Count:9
9
402 -
403 } else if (dir.type == QIconDirInfo::Scalable) {
never evaluated: dir.type == QIconDirInfo::Scalable
0
404 return dir.size <= dir.maxSize &&
never executed: return dir.size <= dir.maxSize && iconsize >= dir.minSize;
0
405 iconsize >= dir.minSize;
never executed: return dir.size <= dir.maxSize && iconsize >= dir.minSize;
0
406 -
407 } else if (dir.type == QIconDirInfo::Threshold) {
never evaluated: dir.type == QIconDirInfo::Threshold
0
408 return iconsize >= dir.size - dir.threshold &&
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
0
409 iconsize <= dir.size + dir.threshold;
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
0
410 } -
411 -
412 Q_ASSERT(1); // Not a valid value
never executed (the execution status of this line is deduced): qt_noop();
-
413 return false;
never executed: return false;
0
414} -
415 -
416/* -
417 * This algorithm is defined by the freedesktop spec: -
418 * http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html -
419 */ -
420static int directorySizeDistance(const QIconDirInfo &dir, int iconsize) -
421{ -
422 if (dir.type == QIconDirInfo::Fixed) {
partially evaluated: dir.type == QIconDirInfo::Fixed
TRUEFALSE
yes
Evaluation Count:6
no
Evaluation Count:0
0-6
423 return qAbs(dir.size - iconsize);
executed: return qAbs(dir.size - iconsize);
Execution Count:6
6
424 -
425 } else if (dir.type == QIconDirInfo::Scalable) {
never evaluated: dir.type == QIconDirInfo::Scalable
0
426 if (iconsize < dir.minSize)
never evaluated: iconsize < dir.minSize
0
427 return dir.minSize - iconsize;
never executed: return dir.minSize - iconsize;
0
428 else if (iconsize > dir.maxSize)
never evaluated: iconsize > dir.maxSize
0
429 return iconsize - dir.maxSize;
never executed: return iconsize - dir.maxSize;
0
430 else -
431 return 0;
never executed: return 0;
0
432 -
433 } else if (dir.type == QIconDirInfo::Threshold) {
never evaluated: dir.type == QIconDirInfo::Threshold
0
434 if (iconsize < dir.size - dir.threshold)
never evaluated: iconsize < dir.size - dir.threshold
0
435 return dir.minSize - iconsize;
never executed: return dir.minSize - iconsize;
0
436 else if (iconsize > dir.size + dir.threshold)
never evaluated: iconsize > dir.size + dir.threshold
0
437 return iconsize - dir.maxSize;
never executed: return iconsize - dir.maxSize;
0
438 else return 0;
never executed: return 0;
0
439 } -
440 -
441 Q_ASSERT(1); // Not a valid value
never executed (the execution status of this line is deduced): qt_noop();
-
442 return INT_MAX;
never executed: return 2147483647;
0
443} -
444 -
445QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QSize &size) -
446{ -
447 int iconsize = qMin(size.width(), size.height());
executed (the execution status of this line is deduced): int iconsize = qMin(size.width(), size.height());
-
448 -
449 // Note that m_entries are sorted so that png-files -
450 // come first -
451 -
452 // Search for exact matches first -
453 for (int i = 0; i < m_entries.count(); ++i) {
evaluated: i < m_entries.count()
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:2
2-9
454 QIconLoaderEngineEntry *entry = m_entries.at(i);
executed (the execution status of this line is deduced): QIconLoaderEngineEntry *entry = m_entries.at(i);
-
455 if (directoryMatchesSize(entry->dir, iconsize)) {
evaluated: directoryMatchesSize(entry->dir, iconsize)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:7
2-7
456 return entry;
executed: return entry;
Execution Count:2
2
457 } -
458 }
executed: }
Execution Count:7
7
459 -
460 // Find the minimum distance icon -
461 int minimalSize = INT_MAX;
executed (the execution status of this line is deduced): int minimalSize = 2147483647;
-
462 QIconLoaderEngineEntry *closestMatch = 0;
executed (the execution status of this line is deduced): QIconLoaderEngineEntry *closestMatch = 0;
-
463 for (int i = 0; i < m_entries.count(); ++i) {
evaluated: i < m_entries.count()
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:2
2-6
464 QIconLoaderEngineEntry *entry = m_entries.at(i);
executed (the execution status of this line is deduced): QIconLoaderEngineEntry *entry = m_entries.at(i);
-
465 int distance = directorySizeDistance(entry->dir, iconsize);
executed (the execution status of this line is deduced): int distance = directorySizeDistance(entry->dir, iconsize);
-
466 if (distance < minimalSize) {
evaluated: distance < minimalSize
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:2
2-4
467 minimalSize = distance;
executed (the execution status of this line is deduced): minimalSize = distance;
-
468 closestMatch = entry;
executed (the execution status of this line is deduced): closestMatch = entry;
-
469 }
executed: }
Execution Count:4
4
470 }
executed: }
Execution Count:6
6
471 return closestMatch;
executed: return closestMatch;
Execution Count:2
2
472} -
473 -
474/* -
475 * Returns the actual icon size. For scalable svg's this is equivalent -
476 * to the requested size. Otherwise the closest match is returned but -
477 * we can never return a bigger size than the requested size. -
478 * -
479 */ -
480QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode, -
481 QIcon::State state) -
482{ -
483 ensureLoaded();
never executed (the execution status of this line is deduced): ensureLoaded();
-
484 -
485 QIconLoaderEngineEntry *entry = entryForSize(size);
never executed (the execution status of this line is deduced): QIconLoaderEngineEntry *entry = entryForSize(size);
-
486 if (entry) {
never evaluated: entry
0
487 const QIconDirInfo &dir = entry->dir;
never executed (the execution status of this line is deduced): const QIconDirInfo &dir = entry->dir;
-
488 if (dir.type == QIconDirInfo::Scalable)
never evaluated: dir.type == QIconDirInfo::Scalable
0
489 return size;
never executed: return size;
0
490 else { -
491 int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
never executed (the execution status of this line is deduced): int result = qMin<int>(dir.size, qMin(size.width(), size.height()));
-
492 return QSize(result, result);
never executed: return QSize(result, result);
0
493 } -
494 } -
495 return QIconEngine::actualSize(size, mode, state);
never executed: return QIconEngine::actualSize(size, mode, state);
0
496} -
497 -
498QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) -
499{ -
500 Q_UNUSED(state);
executed (the execution status of this line is deduced): (void)state;;
-
501 -
502 // Ensure that basePixmap is lazily initialized before generating the -
503 // key, otherwise the cache key is not unique -
504 if (basePixmap.isNull())
evaluated: basePixmap.isNull()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
505 basePixmap.load(filename);
executed: basePixmap.load(filename);
Execution Count:3
3
506 -
507 QSize actualSize = basePixmap.size();
executed (the execution status of this line is deduced): QSize actualSize = basePixmap.size();
-
508 if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
partially evaluated: !actualSize.isNull()
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
evaluated: actualSize.width() > size.width()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
partially evaluated: actualSize.height() > size.height()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-4
509 actualSize.scale(size, Qt::KeepAspectRatio);
executed: actualSize.scale(size, Qt::KeepAspectRatio);
Execution Count:1
1
510 -
511 QString key = QLatin1String("$qt_theme_")
executed (the execution status of this line is deduced): QString key = QLatin1String("$qt_theme_")
-
512 % HexString<qint64>(basePixmap.cacheKey())
executed (the execution status of this line is deduced): % HexString<qint64>(basePixmap.cacheKey())
-
513 % HexString<int>(mode)
executed (the execution status of this line is deduced): % HexString<int>(mode)
-
514 % HexString<qint64>(QGuiApplication::palette().cacheKey())
executed (the execution status of this line is deduced): % HexString<qint64>(QGuiApplication::palette().cacheKey())
-
515 % HexString<int>(actualSize.width())
executed (the execution status of this line is deduced): % HexString<int>(actualSize.width())
-
516 % HexString<int>(actualSize.height());
executed (the execution status of this line is deduced): % HexString<int>(actualSize.height());
-
517 -
518 QPixmap cachedPixmap;
executed (the execution status of this line is deduced): QPixmap cachedPixmap;
-
519 if (QPixmapCache::find(key, &cachedPixmap)) {
evaluated: QPixmapCache::find(key, &cachedPixmap)
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
1-3
520 return cachedPixmap;
executed: return cachedPixmap;
Execution Count:1
1
521 } else { -
522 if (basePixmap.size() != actualSize)
evaluated: basePixmap.size() != actualSize
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
523 basePixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
executed: basePixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
Execution Count:1
1
524 cachedPixmap = basePixmap;
executed (the execution status of this line is deduced): cachedPixmap = basePixmap;
-
525 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
partially evaluated: QGuiApplication *guiApp = qobject_cast<QGuiApplication *>((static_cast<QGuiApplication *>(QCoreApplication::instance())))
TRUEFALSE
yes
Evaluation Count:3
no
Evaluation Count:0
0-3
526 cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, basePixmap);
executed: cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, basePixmap);
Execution Count:3
3
527 QPixmapCache::insert(key, cachedPixmap);
executed (the execution status of this line is deduced): QPixmapCache::insert(key, cachedPixmap);
-
528 }
executed: }
Execution Count:3
3
529 return cachedPixmap;
executed: return cachedPixmap;
Execution Count:3
3
530} -
531 -
532QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) -
533{ -
534 if (svgIcon.isNull())
never evaluated: svgIcon.isNull()
0
535 svgIcon = QIcon(filename);
never executed: svgIcon = QIcon(filename);
0
536 -
537 // Simply reuse svg icon engine -
538 return svgIcon.pixmap(size, mode, state);
never executed: return svgIcon.pixmap(size, mode, state);
0
539} -
540 -
541QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode, -
542 QIcon::State state) -
543{ -
544 ensureLoaded();
executed (the execution status of this line is deduced): ensureLoaded();
-
545 -
546 QIconLoaderEngineEntry *entry = entryForSize(size);
executed (the execution status of this line is deduced): QIconLoaderEngineEntry *entry = entryForSize(size);
-
547 if (entry)
partially evaluated: entry
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
548 return entry->pixmap(size, mode, state);
executed: return entry->pixmap(size, mode, state);
Execution Count:4
4
549 -
550 return QPixmap();
never executed: return QPixmap();
0
551} -
552 -
553QString QIconLoaderEngine::key() const -
554{ -
555 return QLatin1String("QIconLoaderEngine");
executed: return QLatin1String("QIconLoaderEngine");
Execution Count:1
1
556} -
557 -
558void QIconLoaderEngine::virtual_hook(int id, void *data) -
559{ -
560 ensureLoaded();
executed (the execution status of this line is deduced): ensureLoaded();
-
561 -
562 switch (id) { -
563 case QIconEngine::AvailableSizesHook: -
564 { -
565 QIconEngine::AvailableSizesArgument &arg
executed (the execution status of this line is deduced): QIconEngine::AvailableSizesArgument &arg
-
566 = *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);
executed (the execution status of this line is deduced): = *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);
-
567 const QList<QIconDirInfo> directoryKey = iconLoaderInstance()->theme().keyList();
executed (the execution status of this line is deduced): const QList<QIconDirInfo> directoryKey = iconLoaderInstance()->theme().keyList();
-
568 arg.sizes.clear();
executed (the execution status of this line is deduced): arg.sizes.clear();
-
569 -
570 // Gets all sizes from the DirectoryInfo entries -
571 for (int i = 0 ; i < m_entries.size() ; ++i) {
evaluated: i < m_entries.size()
TRUEFALSE
yes
Evaluation Count:36
yes
Evaluation Count:17
17-36
572 int size = m_entries.at(i)->dir.size;
executed (the execution status of this line is deduced): int size = m_entries.at(i)->dir.size;
-
573 arg.sizes.append(QSize(size, size));
executed (the execution status of this line is deduced): arg.sizes.append(QSize(size, size));
-
574 }
executed: }
Execution Count:36
36
575 } -
576 break;
executed: break;
Execution Count:17
17
577 case QIconEngine::IconNameHook: -
578 { -
579 QString &name = *reinterpret_cast<QString*>(data);
executed (the execution status of this line is deduced): QString &name = *reinterpret_cast<QString*>(data);
-
580 name = m_iconName;
executed (the execution status of this line is deduced): name = m_iconName;
-
581 } -
582 break;
executed: break;
Execution Count:1
1
583 default: -
584 QIconEngine::virtual_hook(id, data);
never executed (the execution status of this line is deduced): QIconEngine::virtual_hook(id, data);
-
585 }
never executed: }
0
586}
executed: }
Execution Count:18
18
587 -
588QT_END_NAMESPACE -
589 -
590#endif //QT_NO_ICON -
591 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial