qiconloader.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qiconloader.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7namespace { namespace Q_QGS_iconLoaderInstance { typedef QIconLoader Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QIconLoader, Q_QGS_iconLoaderInstance::innerFunction, Q_QGS_iconLoaderInstance::guard> iconLoaderInstance;
0
8-
9-
10static QString fallbackTheme()-
11{-
12 if (const
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
13 const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconFallbackThemeName);-
14 if (themeHint.isValid()
themeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
15 return
never executed: return themeHint.toString();
themeHint.toString();
never executed: return themeHint.toString();
0
16 }
never executed: end of block
0
17 return
never executed: return QString();
QString();
never executed: return QString();
0
18}-
19-
20QIconLoader::QIconLoader() :-
21 m_themeKey(1), m_supportsSvg(false), m_initialized(false)-
22{-
23}
never executed: end of block
0
24-
25static inline QString systemThemeName()-
26{-
27 if (const
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
28 const QVariant themeHint = theme->themeHint(QPlatformTheme::SystemIconThemeName);-
29 if (themeHint.isValid()
themeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
30 return
never executed: return themeHint.toString();
themeHint.toString();
never executed: return themeHint.toString();
0
31 }
never executed: end of block
0
32 return
never executed: return QString();
QString();
never executed: return QString();
0
33}-
34-
35static inline QStringList systemIconSearchPaths()-
36{-
37 if (const
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()
const QPlatfor...latformTheme()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
38 const QVariant themeHint = theme->themeHint(QPlatformTheme::IconThemeSearchPaths);-
39 if (themeHint.isValid()
themeHint.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
40 return
never executed: return themeHint.toStringList();
themeHint.toStringList();
never executed: return themeHint.toStringList();
0
41 }
never executed: end of block
0
42 return
never executed: return QStringList();
QStringList();
never executed: return QStringList();
0
43}-
44-
45extern QFactoryLoader *qt_iconEngineFactoryLoader();-
46-
47void QIconLoader::ensureInitialized()-
48{-
49 if (!m_initialized
!m_initializedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
50 m_initialized = true;-
51-
52 ((!((static_cast<QGuiApplication *>(QCoreApplication::instance())))) ? qt_assert("qApp",__FILE__,104) : qt_noop());-
53-
54 m_systemTheme = systemThemeName();-
55-
56 if (m_systemTheme.isEmpty()
m_systemTheme.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
57 m_systemTheme = fallbackTheme();
never executed: m_systemTheme = fallbackTheme();
0
58 if (qt_iconEngineFactoryLoader()->keyMap().key(QLatin1String("svg"), -1) != -1
qt_iconEngineF...g"), -1) != -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
59 m_supportsSvg = true;
never executed: m_supportsSvg = true;
0
60 }
never executed: end of block
0
61}
never executed: end of block
0
62-
63QIconLoader *QIconLoader::instance()-
64{-
65 iconLoaderInstance()->ensureInitialized();-
66 return
never executed: return iconLoaderInstance();
iconLoaderInstance();
never executed: return iconLoaderInstance();
0
67}-
68-
69-
70-
71void QIconLoader::updateSystemTheme()-
72{-
73-
74 if (m_userTheme.isEmpty()
m_userTheme.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
75 QString theme = systemThemeName();-
76 if (theme.isEmpty()
theme.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
77 theme = fallbackTheme();
never executed: theme = fallbackTheme();
0
78 if (theme != m_systemTheme
theme != m_systemThemeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
79 m_systemTheme = theme;-
80 invalidateKey();-
81 }
never executed: end of block
0
82 }
never executed: end of block
0
83}
never executed: end of block
0
84-
85void QIconLoader::setThemeName(const QString &themeName)-
86{-
87 m_userTheme = themeName;-
88 invalidateKey();-
89}
never executed: end of block
0
90-
91void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)-
92{-
93 m_iconDirs = searchPaths;-
94 themeList.clear();-
95 invalidateKey();-
96}
never executed: end of block
0
97-
98QStringList QIconLoader::themeSearchPaths() const-
99{-
100 if (m_iconDirs.isEmpty()
m_iconDirs.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
101 m_iconDirs = systemIconSearchPaths();-
102-
103 m_iconDirs.append(QLatin1String(":/icons"));-
104 }
never executed: end of block
0
105 return
never executed: return m_iconDirs;
m_iconDirs;
never executed: return m_iconDirs;
0
106}-
107class QIconCacheGtkReader-
108{-
109public:-
110 explicit QIconCacheGtkReader(const QString &themeDir);-
111 QVector<const char *> lookup(const QString &);-
112 bool isValid() const { return
never executed: return m_isValid;
m_isValid;
never executed: return m_isValid;
}
0
113private:-
114 QFile m_file;-
115 const unsigned char *m_data;-
116 quint64 m_size;-
117 bool m_isValid;-
118-
119 quint16 read16(uint offset)-
120 {-
121 if (offset > m_size - 2
offset > m_size - 2Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(offset & 0x1)Description
TRUEnever evaluated
FALSEnever evaluated
offset & 0x1)
(offset & 0x1)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
122 m_isValid = false;-
123 return
never executed: return 0;
0;
never executed: return 0;
0
124 }-
125 return
never executed: return m_data[offset+1] | m_data[offset] << 8;
m_data[offset+1] | m_data[offset] << 8;
never executed: return m_data[offset+1] | m_data[offset] << 8;
0
126 }-
127 quint32 read32(uint offset)-
128 {-
129 if (offset > m_size - 4
offset > m_size - 4Description
TRUEnever evaluated
FALSEnever evaluated
|| (
(offset & 0x3)Description
TRUEnever evaluated
FALSEnever evaluated
offset & 0x3)
(offset & 0x3)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
130 m_isValid = false;-
131 return
never executed: return 0;
0;
never executed: return 0;
0
132 }-
133 return
never executed: return m_data[offset+3] | m_data[offset+2] << 8 | m_data[offset+1] << 16 | m_data[offset] << 24;
m_data[offset+3] | m_data[offset+2] << 8
never executed: return m_data[offset+3] | m_data[offset+2] << 8 | m_data[offset+1] << 16 | m_data[offset] << 24;
0
134 | m_data[offset+1] << 16 | m_data[offset] << 24;
never executed: return m_data[offset+3] | m_data[offset+2] << 8 | m_data[offset+1] << 16 | m_data[offset] << 24;
0
135 }-
136};-
137-
138-
139QIconCacheGtkReader::QIconCacheGtkReader(const QString &dirName)-
140 : m_isValid(false)-
141{-
142 QFileInfo info(dirName + QLatin1Literal("/icon-theme.cache"));-
143 if (!info.exists()
!info.exists()Description
TRUEnever evaluated
FALSEnever evaluated
|| info.lastModified() < QFileInfo(dirName).lastModified()
info.lastModif...lastModified()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
144 return;
never executed: return;
0
145 m_file.setFileName(info.absoluteFilePath());-
146 if (!m_file.open(QFile::ReadOnly)
!m_file.open(QFile::ReadOnly)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
147 return;
never executed: return;
0
148 m_size = m_file.size();-
149 m_data = m_file.map(0, m_size);-
150 if (!m_data
!m_dataDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
151 return;
never executed: return;
0
152 if (read16(0) != 1
read16(0) != 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
153 return;
never executed: return;
0
154-
155 m_isValid = true;-
156-
157-
158 auto lastModified = info.lastModified();-
159 quint32 dirListOffset = read32(8);-
160 quint32 dirListLen = read32(dirListOffset);-
161 for (uint i = 0; i < dirListLen
i < dirListLenDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
162 quint32 offset = read32(dirListOffset + 4 + 4 * i);-
163 if (!m_isValid
!m_isValidDescription
TRUEnever evaluated
FALSEnever evaluated
|| offset >= m_size
offset >= m_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
|| lastModified < QFileInfo(dirName + QLatin1Char('/')
lastModified <...lastModified()Description
TRUEnever evaluated
FALSEnever evaluated
0
164 + QString::fromUtf8(reinterpret_cast<const char*>(m_data + offset))).lastModified()
lastModified <...lastModified()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
165 m_isValid = false;-
166 return;
never executed: return;
0
167 }-
168 }
never executed: end of block
0
169}
never executed: end of block
0
170-
171static quint32 icon_name_hash(const char *p)-
172{-
173 quint32 h = static_cast<signed char>(*p);-
174 for (p += 1; *
*p != '\0'Description
TRUEnever evaluated
FALSEnever evaluated
p != '\0'
*p != '\0'Description
TRUEnever evaluated
FALSEnever evaluated
; p++)
0
175 h = (h << 5) - h + *p;
never executed: h = (h << 5) - h + *p;
0
176 return
never executed: return h;
h;
never executed: return h;
0
177}-
178-
179-
180-
181-
182-
183-
184QVector<const char *> QIconCacheGtkReader::lookup(const QString &name)-
185{-
186 QVector<const char *> ret;-
187 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
188 return
never executed: return ret;
ret;
never executed: return ret;
0
189-
190 QByteArray nameUtf8 = name.toUtf8();-
191 quint32 hash = icon_name_hash(nameUtf8);-
192-
193 quint32 hashOffset = read32(4);-
194 quint32 hashBucketCount = read32(hashOffset);-
195-
196 if (!isValid()
!isValid()Description
TRUEnever evaluated
FALSEnever evaluated
|| hashBucketCount == 0
hashBucketCount == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
197 m_isValid = false;-
198 return
never executed: return ret;
ret;
never executed: return ret;
0
199 }-
200-
201 quint32 bucketIndex = hash % hashBucketCount;-
202 quint32 bucketOffset = read32(hashOffset + 4 + bucketIndex * 4);-
203 while (bucketOffset > 0
bucketOffset > 0Description
TRUEnever evaluated
FALSEnever evaluated
&& bucketOffset <= m_size - 12
bucketOffset <= m_size - 12Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
204 quint32 nameOff = read32(bucketOffset + 4);-
205 if (nameOff < m_size
nameOff < m_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
&& strcmp(reinterpret_cast<const char*>(m_data + nameOff), nameUtf8) == 0
strcmp(reinter...nameUtf8) == 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
206 quint32 dirListOffset = read32(8);-
207 quint32 dirListLen = read32(dirListOffset);-
208-
209 quint32 listOffset = read32(bucketOffset+8);-
210 quint32 listLen = read32(listOffset);-
211-
212 if (!m_isValid
!m_isValidDescription
TRUEnever evaluated
FALSEnever evaluated
|| listOffset + 4 + 8 * listLen > m_size
listOffset + 4...stLen > m_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
213 m_isValid = false;-
214 return
never executed: return ret;
ret;
never executed: return ret;
0
215 }-
216-
217 ret.reserve(listLen);-
218 for (uint j = 0; j < listLen
j < listLenDescription
TRUEnever evaluated
FALSEnever evaluated
&& m_isValid
m_isValidDescription
TRUEnever evaluated
FALSEnever evaluated
; ++j) {
0
219 quint32 dirIndex = read16(listOffset + 4 + 8 * j);-
220 quint32 o = read32(dirListOffset + 4 + dirIndex*4);-
221 if (!m_isValid
!m_isValidDescription
TRUEnever evaluated
FALSEnever evaluated
|| dirIndex >= dirListLen
dirIndex >= dirListLenDescription
TRUEnever evaluated
FALSEnever evaluated
|| o >= m_size
o >= m_sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
222 m_isValid = false;-
223 return
never executed: return ret;
ret;
never executed: return ret;
0
224 }-
225 ret.append(reinterpret_cast<const char*>(m_data) + o);-
226 }
never executed: end of block
0
227 return
never executed: return ret;
ret;
never executed: return ret;
0
228 }-
229 bucketOffset = read32(bucketOffset);-
230 }
never executed: end of block
0
231 return
never executed: return ret;
ret;
never executed: return ret;
0
232}-
233-
234QIconTheme::QIconTheme(const QString &themeName)-
235 : m_valid(false)-
236{-
237 QFile themeIndex;-
238-
239 const QStringList iconDirs = QIcon::themeSearchPaths();-
240 for ( int i = 0 ; i < iconDirs.size()
i < iconDirs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
241 QDir iconDir(iconDirs[i]);-
242 QString themeDir = iconDir.path() + QLatin1Char('/') + themeName;-
243 QFileInfo themeDirInfo(themeDir);-
244-
245 if (themeDirInfo.isDir()
themeDirInfo.isDir()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
246 m_contentDirs << themeDir;-
247 m_gtkCaches << QSharedPointer<QIconCacheGtkReader>::create(themeDir);-
248 }
never executed: end of block
0
249-
250 if (!m_valid
!m_validDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
251 themeIndex.setFileName(themeDir + QLatin1String("/index.theme"));-
252 if (themeIndex.exists()
themeIndex.exists()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
253 m_valid = true;
never executed: m_valid = true;
0
254 }
never executed: end of block
0
255 }
never executed: end of block
0
256-
257 if (themeIndex.exists()
themeIndex.exists()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
258 const QSettings indexReader(themeIndex.fileName(), QSettings::IniFormat);-
259 QStringListIterator keyIterator(indexReader.allKeys());-
260 while (keyIterator.hasNext()
keyIterator.hasNext()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
261-
262 const QString key = keyIterator.next();-
263 if (key.endsWith(QLatin1String("/Size"))
key.endsWith(Q...ring("/Size"))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
264-
265-
266 if (int size = indexReader.value(key).toInt()
int size = ind...e(key).toInt()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
267 QString directoryKey = key.left(key.size() - 5);-
268 QIconDirInfo dirInfo(directoryKey);-
269 dirInfo.size = size;-
270 QString type = indexReader.value(directoryKey +-
271 QLatin1String("/Type")-
272 ).toString();-
273-
274 if (type == QLatin1String("Fixed")
type == QLatin1String("Fixed")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
275 dirInfo.type = QIconDirInfo::Fixed;
never executed: dirInfo.type = QIconDirInfo::Fixed;
0
276 else if (type == QLatin1String("Scalable")
type == QLatin...ng("Scalable")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
277 dirInfo.type = QIconDirInfo::Scalable;
never executed: dirInfo.type = QIconDirInfo::Scalable;
0
278 else-
279 dirInfo.type = QIconDirInfo::Threshold;
never executed: dirInfo.type = QIconDirInfo::Threshold;
0
280-
281 dirInfo.threshold = indexReader.value(directoryKey +-
282 QLatin1String("/Threshold"),-
283 2).toInt();-
284-
285 dirInfo.minSize = indexReader.value(directoryKey +-
286 QLatin1String("/MinSize"),-
287 size).toInt();-
288-
289 dirInfo.maxSize = indexReader.value(directoryKey +-
290 QLatin1String("/MaxSize"),-
291 size).toInt();-
292 m_keyList.append(dirInfo);-
293 }
never executed: end of block
0
294 }
never executed: end of block
0
295 }
never executed: end of block
0
296-
297-
298 m_parents = indexReader.value(-
299 QLatin1String("Icon Theme/Inherits")).toStringList();-
300 m_parents.removeAll(QString());-
301-
302-
303 if (m_parents.isEmpty()
m_parents.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
304 const QString fallback = fallbackTheme();-
305 if (!fallback.isEmpty()
!fallback.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
306 m_parents.append(fallback);
never executed: m_parents.append(fallback);
0
307 }
never executed: end of block
0
308-
309-
310 if (!m_parents.contains(QLatin1String("hicolor"))
!m_parents.con...ng("hicolor"))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
311 m_parents.append(QLatin1String("hicolor"));
never executed: m_parents.append(QLatin1String("hicolor"));
0
312 }
never executed: end of block
0
313-
314}
never executed: end of block
0
315-
316QThemeIconInfo QIconLoader::findIconHelper(const QString &themeName,-
317 const QString &iconName,-
318 QStringList &visited) const-
319{-
320 QThemeIconInfo info;-
321 ((!(!themeName.isEmpty())) ? qt_assert("!themeName.isEmpty()",__FILE__,381) : qt_noop());-
322-
323-
324 visited << themeName;-
325-
326 QIconTheme theme = themeList.value(themeName);-
327 if (!theme.isValid()
!theme.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
328 theme = QIconTheme(themeName);-
329 if (!theme.isValid()
!theme.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
330 theme = QIconTheme(fallbackTheme());
never executed: theme = QIconTheme(fallbackTheme());
0
331-
332 themeList.insert(themeName, theme);-
333 }
never executed: end of block
0
334-
335 const QStringList contentDirs = theme.contentDirs();-
336-
337 QString iconNameFallback = iconName;-
338-
339-
340 while (info.entries.isEmpty()
info.entries.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
341 const QString svgIconName = iconNameFallback + QLatin1String(".svg");-
342 const QString pngIconName = iconNameFallback + QLatin1String(".png");-
343-
344-
345 for (int i = 0; i < contentDirs.size()
i < contentDirs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
346 QVector<QIconDirInfo> subDirs = theme.keyList();-
347-
348-
349-
350 auto cache = theme.m_gtkCaches.at(i);-
351 if (cache->isValid()
cache->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
352 const auto result = cache->lookup(iconNameFallback);-
353 if (cache->isValid()
cache->isValid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
354 const QVector<QIconDirInfo> subDirsCopy = subDirs;-
355 subDirs.clear();-
356 subDirs.reserve(result.count());-
357 for (const char *s : result) {-
358 QString path = QString::fromUtf8(s);-
359 auto it = std::find_if(subDirsCopy.cbegin(), subDirsCopy.cend(),-
360 [&](const QIconDirInfo &info) {-
361 return
never executed: return info.path == path;
info.path == path;
never executed: return info.path == path;
} );
0
362 if (it != subDirsCopy.cend()
it != subDirsCopy.cend()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
363 subDirs.append(*it);-
364 }
never executed: end of block
0
365 }
never executed: end of block
0
366 }
never executed: end of block
0
367 }
never executed: end of block
0
368-
369 QString contentDir = contentDirs.at(i) + QLatin1Char('/');-
370 for (int j = 0; j < subDirs.size()
j < subDirs.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++j) {
0
371 const QIconDirInfo &dirInfo = subDirs.at(j);-
372 QString subdir = dirInfo.path;-
373 QDir currentDir(contentDir + subdir);-
374 if (currentDir.exists(pngIconName)
currentDir.exists(pngIconName)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
375 PixmapEntry *iconEntry = new PixmapEntry;-
376 iconEntry->dir = dirInfo;-
377 iconEntry->filename = currentDir.filePath(pngIconName);-
378-
379-
380 info.entries.prepend(iconEntry);-
381 }
never executed: end of block
else if (m_supportsSvg
m_supportsSvgDescription
TRUEnever evaluated
FALSEnever evaluated
&&
0
382 currentDir.exists(svgIconName)
currentDir.exists(svgIconName)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
383 ScalableEntry *iconEntry = new ScalableEntry;-
384 iconEntry->dir = dirInfo;-
385 iconEntry->filename = currentDir.filePath(svgIconName);-
386 info.entries.append(iconEntry);-
387 }
never executed: end of block
0
388 }
never executed: end of block
0
389 }
never executed: end of block
0
390-
391 if (!info.entries.isEmpty()
!info.entries.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
392 info.iconName = iconNameFallback;-
393 break;
never executed: break;
0
394 }-
395-
396-
397 const int indexOfDash = iconNameFallback.lastIndexOf(QLatin1Char('-'));-
398 if (indexOfDash == -1
indexOfDash == -1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
399 break;
never executed: break;
0
400-
401 iconNameFallback.truncate(indexOfDash);-
402 }
never executed: end of block
0
403-
404 if (info.entries.isEmpty()
info.entries.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
405 const QStringList parents = theme.parents();-
406-
407 for (int i = 0 ; i < parents.size()
i < parents.size()Description
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
408-
409 const QString parentTheme = parents.at(i).trimmed();-
410-
411 if (!visited.contains(parentTheme)
!visited.contains(parentTheme)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
412 info = findIconHelper(parentTheme, iconName, visited);
never executed: info = findIconHelper(parentTheme, iconName, visited);
0
413-
414 if (!info.entries.isEmpty()
!info.entries.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
415 break;
never executed: break;
0
416 }
never executed: end of block
0
417 }
never executed: end of block
0
418 return
never executed: return info;
info;
never executed: return info;
0
419}-
420-
421QThemeIconInfo QIconLoader::loadIcon(const QString &name) const-
422{-
423 if (!themeName().isEmpty()
!themeName().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
424 QStringList visited;-
425 return
never executed: return findIconHelper(themeName(), name, visited);
findIconHelper(themeName(), name, visited);
never executed: return findIconHelper(themeName(), name, visited);
0
426 }-
427-
428 return
never executed: return QThemeIconInfo();
QThemeIconInfo();
never executed: return QThemeIconInfo();
0
429}-
430-
431-
432-
433-
434-
435QIconLoaderEngine::QIconLoaderEngine(const QString& iconName)-
436 : m_iconName(iconName), m_key(0)-
437{-
438}
never executed: end of block
0
439-
440QIconLoaderEngine::~QIconLoaderEngine()-
441{-
442 qDeleteAll(m_info.entries);-
443}
never executed: end of block
0
444-
445QIconLoaderEngine::QIconLoaderEngine(const QIconLoaderEngine &other)-
446 : QIconEngine(other),-
447 m_iconName(other.m_iconName),-
448 m_key(0)-
449{-
450}
never executed: end of block
0
451-
452QIconEngine *QIconLoaderEngine::clone() const-
453{-
454 return
never executed: return new QIconLoaderEngine(*this);
new QIconLoaderEngine(*this);
never executed: return new QIconLoaderEngine(*this);
0
455}-
456-
457bool QIconLoaderEngine::read(QDataStream &in) {-
458 in >> m_iconName;-
459 return
never executed: return true;
true;
never executed: return true;
0
460}-
461-
462bool QIconLoaderEngine::write(QDataStream &out) const-
463{-
464 out << m_iconName;-
465 return
never executed: return true;
true;
never executed: return true;
0
466}-
467-
468bool QIconLoaderEngine::hasIcon() const-
469{-
470 return
never executed: return !(m_info.entries.isEmpty());
!(m_info.entries.isEmpty());
never executed: return !(m_info.entries.isEmpty());
0
471}-
472-
473-
474void QIconLoaderEngine::ensureLoaded()-
475{-
476 if (!(QIconLoader::instance()->themeKey() == m_key)
!(QIconLoader:...ey() == m_key)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
477 qDeleteAll(m_info.entries);-
478 m_info.entries.clear();-
479 m_info.iconName.clear();-
480-
481 ((!(m_info.entries.size() == 0)) ? qt_assert("m_info.entries.size() == 0",__FILE__,541) : qt_noop());-
482 m_info = QIconLoader::instance()->loadIcon(m_iconName);-
483 m_key = QIconLoader::instance()->themeKey();-
484 }
never executed: end of block
0
485}
never executed: end of block
0
486-
487void QIconLoaderEngine::paint(QPainter *painter, const QRect &rect,-
488 QIcon::Mode mode, QIcon::State state)-
489{-
490 QSize pixmapSize = rect.size();-
491 painter->drawPixmap(rect, pixmap(pixmapSize, mode, state));-
492}
never executed: end of block
0
493-
494-
495-
496-
497-
498static bool directoryMatchesSize(const QIconDirInfo &dir, int iconsize)-
499{-
500 if (dir.type == QIconDirInfo::Fixed
dir.type == QI...DirInfo::FixedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
501 return
never executed: return dir.size == iconsize;
dir.size == iconsize;
never executed: return dir.size == iconsize;
0
502-
503 } else if (dir.type == QIconDirInfo::Scalable
dir.type == QI...Info::ScalableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
504 return
never executed: return iconsize <= dir.maxSize && iconsize >= dir.minSize;
iconsize <= dir.maxSize &&
never executed: return iconsize <= dir.maxSize && iconsize >= dir.minSize;
0
505 iconsize >= dir.minSize;
never executed: return iconsize <= dir.maxSize && iconsize >= dir.minSize;
0
506-
507 } else if (dir.type == QIconDirInfo::Threshold
dir.type == QI...nfo::ThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
508 return
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
iconsize >= dir.size - dir.threshold &&
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
0
509 iconsize <= dir.size + dir.threshold;
never executed: return iconsize >= dir.size - dir.threshold && iconsize <= dir.size + dir.threshold;
0
510 }-
511-
512 ((!(1)) ? qt_assert("1",__FILE__,572) : qt_noop());-
513 return
never executed: return false;
false;
never executed: return false;
0
514}-
515-
516-
517-
518-
519-
520static int directorySizeDistance(const QIconDirInfo &dir, int iconsize)-
521{-
522 if (dir.type == QIconDirInfo::Fixed
dir.type == QI...DirInfo::FixedDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
523 return
never executed: return qAbs(dir.size - iconsize);
qAbs(dir.size - iconsize);
never executed: return qAbs(dir.size - iconsize);
0
524-
525 } else if (dir.type == QIconDirInfo::Scalable
dir.type == QI...Info::ScalableDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
526 if (iconsize < dir.minSize
iconsize < dir.minSizeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
527 return
never executed: return dir.minSize - iconsize;
dir.minSize - iconsize;
never executed: return dir.minSize - iconsize;
0
528 else if (iconsize > dir.maxSize
iconsize > dir.maxSizeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
529 return
never executed: return iconsize - dir.maxSize;
iconsize - dir.maxSize;
never executed: return iconsize - dir.maxSize;
0
530 else-
531 return
never executed: return 0;
0;
never executed: return 0;
0
532-
533 } else if (dir.type == QIconDirInfo::Threshold
dir.type == QI...nfo::ThresholdDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
534 if (iconsize < dir.size - dir.threshold
iconsize < dir... dir.thresholdDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
535 return
never executed: return dir.minSize - iconsize;
dir.minSize - iconsize;
never executed: return dir.minSize - iconsize;
0
536 else if (iconsize > dir.size + dir.threshold
iconsize > dir... dir.thresholdDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
537 return
never executed: return iconsize - dir.maxSize;
iconsize - dir.maxSize;
never executed: return iconsize - dir.maxSize;
0
538 else return
never executed: return 0;
0;
never executed: return 0;
0
539 }-
540-
541 ((!(1)) ? qt_assert("1",__FILE__,601) : qt_noop());-
542 return
never executed: return 2147483647;
2147483647;
never executed: return 2147483647;
0
543}-
544-
545QIconLoaderEngineEntry *QIconLoaderEngine::entryForSize(const QSize &size)-
546{-
547 int iconsize = qMin(size.width(), size.height());-
548-
549-
550-
551-
552 const int numEntries = m_info.entries.size();-
553-
554-
555 for (int i = 0; i < numEntries
i < numEntriesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
556 QIconLoaderEngineEntry *entry = m_info.entries.at(i);-
557 if (directoryMatchesSize(entry->dir, iconsize)
directoryMatch...dir, iconsize)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
558 return
never executed: return entry;
entry;
never executed: return entry;
0
559 }-
560 }
never executed: end of block
0
561-
562-
563 int minimalSize = 2147483647;-
564 QIconLoaderEngineEntry *closestMatch = 0;-
565 for (int i = 0; i < numEntries
i < numEntriesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
566 QIconLoaderEngineEntry *entry = m_info.entries.at(i);-
567 int distance = directorySizeDistance(entry->dir, iconsize);-
568 if (distance < minimalSize
distance < minimalSizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
569 minimalSize = distance;-
570 closestMatch = entry;-
571 }
never executed: end of block
0
572 }
never executed: end of block
0
573 return
never executed: return closestMatch;
closestMatch;
never executed: return closestMatch;
0
574}-
575-
576-
577-
578-
579-
580-
581-
582QSize QIconLoaderEngine::actualSize(const QSize &size, QIcon::Mode mode,-
583 QIcon::State state)-
584{-
585 ensureLoaded();-
586-
587 QIconLoaderEngineEntry *entry = entryForSize(size);-
588 if (entry
entryDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
589 const QIconDirInfo &dir = entry->dir;-
590 if (dir.type == QIconDirInfo::Scalable
dir.type == QI...Info::ScalableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
591 return
never executed: return size;
size;
never executed: return size;
0
592 else {-
593 int result = qMin<int>(dir.size, qMin(size.width(), size.height()));-
594 return
never executed: return QSize(result, result);
QSize(result, result);
never executed: return QSize(result, result);
0
595 }-
596 }-
597 return
never executed: return QIconEngine::actualSize(size, mode, state);
QIconEngine::actualSize(size, mode, state);
never executed: return QIconEngine::actualSize(size, mode, state);
0
598}-
599-
600QPixmap PixmapEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)-
601{-
602 (void)state;;-
603-
604-
605-
606 if (basePixmap.isNull()
basePixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
607 basePixmap.load(filename);
never executed: basePixmap.load(filename);
0
608-
609 QSize actualSize = basePixmap.size();-
610 if (!actualSize.isNull()
!actualSize.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
&& (actualSize.width() > size.width()
actualSize.wid...> size.width()Description
TRUEnever evaluated
FALSEnever evaluated
|| actualSize.height() > size.height()
actualSize.hei... size.height()Description
TRUEnever evaluated
FALSEnever evaluated
))
0
611 actualSize.scale(size, Qt::KeepAspectRatio);
never executed: actualSize.scale(size, Qt::KeepAspectRatio);
0
612-
613 QString key = QLatin1String("$qt_theme_")-
614 % HexString<qint64>(basePixmap.cacheKey())-
615 % HexString<int>(mode)-
616 % HexString<qint64>(QGuiApplication::palette().cacheKey())-
617 % HexString<int>(actualSize.width())-
618 % HexString<int>(actualSize.height());-
619-
620 QPixmap cachedPixmap;-
621 if (QPixmapCache::find(key, &cachedPixmap)
QPixmapCache::...&cachedPixmap)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
622 return
never executed: return cachedPixmap;
cachedPixmap;
never executed: return cachedPixmap;
0
623 } else {-
624 if (basePixmap.size() != actualSize
basePixmap.siz... != actualSizeDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
625 cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
never executed: cachedPixmap = basePixmap.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
0
626 else-
627 cachedPixmap = basePixmap;
never executed: cachedPixmap = basePixmap;
0
628 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>((static_cast<QGuiApplication *>(QCoreApplication::instance())))
QGuiApplicatio...:instance())))Description
TRUEnever evaluated
FALSEnever evaluated
)
0
629 cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, cachedPixmap);
never executed: cachedPixmap = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, cachedPixmap);
0
630 QPixmapCache::insert(key, cachedPixmap);-
631 }
never executed: end of block
0
632 return
never executed: return cachedPixmap;
cachedPixmap;
never executed: return cachedPixmap;
0
633}-
634-
635QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)-
636{-
637 if (svgIcon.isNull()
svgIcon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
638 svgIcon = QIcon(filename);
never executed: svgIcon = QIcon(filename);
0
639-
640-
641 return
never executed: return svgIcon.pixmap(size, mode, state);
svgIcon.pixmap(size, mode, state);
never executed: return svgIcon.pixmap(size, mode, state);
0
642}-
643-
644QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode,-
645 QIcon::State state)-
646{-
647 ensureLoaded();-
648-
649 QIconLoaderEngineEntry *entry = entryForSize(size);-
650 if (entry
entryDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
651 return
never executed: return entry->pixmap(size, mode, state);
entry->pixmap(size, mode, state);
never executed: return entry->pixmap(size, mode, state);
0
652-
653 return
never executed: return QPixmap();
QPixmap();
never executed: return QPixmap();
0
654}-
655-
656QString QIconLoaderEngine::key() const-
657{-
658 return
never executed: return QLatin1String("QIconLoaderEngine");
QLatin1String("QIconLoaderEngine");
never executed: return QLatin1String("QIconLoaderEngine");
0
659}-
660-
661void QIconLoaderEngine::virtual_hook(int id, void *data)-
662{-
663 ensureLoaded();-
664-
665 switch (id) {-
666 case
never executed: case QIconEngine::AvailableSizesHook:
QIconEngine::AvailableSizesHook:
never executed: case QIconEngine::AvailableSizesHook:
0
667 {-
668 QIconEngine::AvailableSizesArgument &arg-
669 = *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);-
670 const int N = m_info.entries.size();-
671 QList<QSize> sizes;-
672 sizes.reserve(N);-
673-
674-
675 for (int i = 0; i < N
i < NDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
676 int size = m_info.entries.at(i)->dir.size;-
677 sizes.append(QSize(size, size));-
678 }
never executed: end of block
0
679 arg.sizes.swap(sizes);-
680 }-
681 break;
never executed: break;
0
682 case
never executed: case QIconEngine::IconNameHook:
QIconEngine::IconNameHook:
never executed: case QIconEngine::IconNameHook:
0
683 {-
684 QString &name = *reinterpret_cast<QString*>(data);-
685 name = m_info.iconName;-
686 }-
687 break;
never executed: break;
0
688 case
never executed: case QIconEngine::IsNullHook:
QIconEngine::IsNullHook:
never executed: case QIconEngine::IsNullHook:
0
689 {-
690 *reinterpret_cast<bool*>(data) = m_info.entries.isEmpty();-
691 }-
692 break;
never executed: break;
0
693 default
never executed: default:
:
never executed: default:
0
694 QIconEngine::virtual_hook(id, data);-
695 }
never executed: end of block
0
696}-
697-
698-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9