qicon.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/image/qicon.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>-
5** Contact: http://www.qt.io/licensing/-
6**-
7** This file is part of the QtGui module of the Qt Toolkit.-
8**-
9** $QT_BEGIN_LICENSE:LGPL21$-
10** Commercial License Usage-
11** Licensees holding valid commercial Qt licenses may use this file in-
12** accordance with the commercial license agreement provided with the-
13** Software or, alternatively, in accordance with the terms contained in-
14** a written agreement between you and The Qt Company. For licensing terms-
15** and conditions see http://www.qt.io/terms-conditions. For further-
16** information use the contact form at http://www.qt.io/contact-us.-
17**-
18** GNU Lesser General Public License Usage-
19** Alternatively, this file may be used under the terms of the GNU Lesser-
20** General Public License version 2.1 or version 3 as published by the Free-
21** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
22** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
23** following information to ensure the GNU Lesser General Public License-
24** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
25** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
26**-
27** As a special exception, The Qt Company gives you certain additional-
28** rights. These rights are described in The Qt Company LGPL Exception-
29** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
30**-
31** $QT_END_LICENSE$-
32**-
33****************************************************************************/-
34-
35#include "qicon.h"-
36#include "qicon_p.h"-
37#include "qiconengine.h"-
38#include "qiconengineplugin.h"-
39#include "qimagereader.h"-
40#include "private/qfactoryloader_p.h"-
41#include "private/qiconloader_p.h"-
42#include "qpainter.h"-
43#include "qfileinfo.h"-
44#include "qpixmapcache.h"-
45#include "qvariant.h"-
46#include "qcache.h"-
47#include "qdebug.h"-
48#include "qpalette.h"-
49#include "qmath.h"-
50-
51#include "private/qhexstring_p.h"-
52#include "private/qguiapplication_p.h"-
53#include "qpa/qplatformtheme.h"-
54-
55#ifndef QT_NO_ICON-
56QT_BEGIN_NAMESPACE-
57-
58/*!-
59 \enum QIcon::Mode-
60-
61 This enum type describes the mode for which a pixmap is intended-
62 to be used. The currently defined modes are:-
63-
64 \value Normal-
65 Display the pixmap when the user is-
66 not interacting with the icon, but the-
67 functionality represented by the icon is available.-
68 \value Disabled-
69 Display the pixmap when the-
70 functionality represented by the icon is not available.-
71 \value Active-
72 Display the pixmap when the-
73 functionality represented by the icon is available and-
74 the user is interacting with the icon, for example, moving the-
75 mouse over it or clicking it.-
76 \value Selected-
77 Display the pixmap when the item represented by the icon is-
78 selected.-
79*/-
80-
81/*!-
82 \enum QIcon::State-
83-
84 This enum describes the state for which a pixmap is intended to be-
85 used. The \e state can be:-
86-
87 \value Off Display the pixmap when the widget is in an "off" state-
88 \value On Display the pixmap when the widget is in an "on" state-
89*/-
90-
91static QBasicAtomicInt serialNumCounter = Q_BASIC_ATOMIC_INITIALIZER(1);-
92-
93static void qt_cleanup_icon_cache();-
94namespace {-
95 struct IconCache : public QCache<QString, QIcon>-
96 {-
97 IconCache()-
98 {-
99 // ### note: won't readd if QApplication is re-created!-
100 qAddPostRoutine(qt_cleanup_icon_cache);-
101 }
never executed: end of block
0
102 };-
103}-
104-
105Q_GLOBAL_STATIC(IconCache, qtIconCache)
never executed: end of block
never executed: guard.store(QtGlobalStatic::Destroyed);
never executed: return &holder.value;
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
106-
107static void qt_cleanup_icon_cache()-
108{-
109 qtIconCache()->clear();-
110}
never executed: end of block
0
111-
112/*! \internal-
113-
114 Returns the effective device pixel ratio, using-
115 the provided window pointer if possible.-
116-
117 if Qt::AA_UseHighDpiPixmaps is not set this function-
118 returns 1.0 to keep non-hihdpi aware code working.-
119*/-
120static qreal qt_effective_device_pixel_ratio(QWindow *window = 0)-
121{-
122 if (!qApp->testAttribute(Qt::AA_UseHighDpiPixmaps))
!(static_cast<...ighDpiPixmaps)Description
TRUEnever evaluated
FALSEnever evaluated
0
123 return qreal(1.0);
never executed: return qreal(1.0);
0
124-
125 if (window)
windowDescription
TRUEnever evaluated
FALSEnever evaluated
0
126 return window->devicePixelRatio();
never executed: return window->devicePixelRatio();
0
127-
128 return qApp->devicePixelRatio(); // Don't know which window to target.
never executed: return (static_cast<QGuiApplication *>(QCoreApplication::instance()))->devicePixelRatio();
0
129}-
130-
131QIconPrivate::QIconPrivate()-
132 : engine(0), ref(1),-
133 serialNum(serialNumCounter.fetchAndAddRelaxed(1)),-
134 detach_no(0),-
135 is_mask(false)-
136{-
137}
never executed: end of block
0
138-
139/*! \internal-
140 Computes the displayDevicePixelRatio for a pixmap.-
141-
142 If displayDevicePixelRatio is 1.0 the reurned value is 1.0, always.-
143-
144 For a displayDevicePixelRatio of 2.0 the returned value will be between-
145 1.0 and 2.0, depending on requestedSize and actualsize:-
146 * If actualsize < requestedSize : 1.0 (not enough pixels for a normal-dpi pixmap)-
147 * If actualsize == requestedSize * 2.0 : 2.0 (enough pixels for a high-dpi pixmap)-
148 * else : a scaled value between 1.0 and 2.0. (pixel count is between normal-dpi and high-dpi)-
149*/-
150qreal QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize)-
151{-
152 QSize targetSize = requestedSize * displayDevicePixelRatio;-
153 qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) +-
154 qreal(actualSize.height() / qreal(targetSize.height())));-
155 return qMax(qreal(1.0), displayDevicePixelRatio *scale);
never executed: return qMax(qreal(1.0), displayDevicePixelRatio *scale);
0
156}-
157-
158QPixmapIconEngine::QPixmapIconEngine()-
159{-
160}-
161-
162QPixmapIconEngine::QPixmapIconEngine(const QPixmapIconEngine &other)-
163 : QIconEngine(other), pixmaps(other.pixmaps)-
164{-
165}
never executed: end of block
0
166-
167QPixmapIconEngine::~QPixmapIconEngine()-
168{-
169}-
170-
171void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)-
172{-
173 QSize pixmapSize = rect.size() * qt_effective_device_pixel_ratio(0);-
174 QPixmap px = pixmap(pixmapSize, mode, state);-
175 painter->drawPixmap(rect, px);-
176}
never executed: end of block
0
177-
178static
never executed: return s.width() * s.height();
inline int area(const QSize &s) { return s.width() * s.height(); }
never executed: return s.width() * s.height();
0
179-
180// returns the smallest of the two that is still larger than or equal to size.-
181static QPixmapIconEngineEntry *bestSizeMatch( const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)-
182{-
183 int s = area(size);-
184 if (pa->size == QSize() && pa->pixmap.isNull()) {
pa->size == QSize()Description
TRUEnever evaluated
FALSEnever evaluated
pa->pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
185 pa->pixmap = QPixmap(pa->fileName);-
186 pa->size = pa->pixmap.size();-
187 }
never executed: end of block
0
188 int a = area(pa->size);-
189 if (pb->size == QSize() && pb->pixmap.isNull()) {
pb->size == QSize()Description
TRUEnever evaluated
FALSEnever evaluated
pb->pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
190 pb->pixmap = QPixmap(pb->fileName);-
191 pb->size = pb->pixmap.size();-
192 }
never executed: end of block
0
193 int b = area(pb->size);-
194 int res = a;-
195 if (qMin(a,b) >= s)
qMin(a,b) >= sDescription
TRUEnever evaluated
FALSEnever evaluated
0
196 res = qMin(a,b);
never executed: res = qMin(a,b);
0
197 else-
198 res = qMax(a,b);
never executed: res = qMax(a,b);
0
199 if (res == a)
res == aDescription
TRUEnever evaluated
FALSEnever evaluated
0
200 return pa;
never executed: return pa;
0
201 return pb;
never executed: return pb;
0
202}-
203-
204QPixmapIconEngineEntry *QPixmapIconEngine::tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state)-
205{-
206 QPixmapIconEngineEntry *pe = 0;-
207 for (int i = 0; i < pixmaps.count(); ++i)
i < pixmaps.count()Description
TRUEnever evaluated
FALSEnever evaluated
0
208 if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) {
pixmaps.at(i).mode == modeDescription
TRUEnever evaluated
FALSEnever evaluated
pixmaps.at(i).state == stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
209 if (pe)
peDescription
TRUEnever evaluated
FALSEnever evaluated
0
210 pe = bestSizeMatch(size, &pixmaps[i], pe);
never executed: pe = bestSizeMatch(size, &pixmaps[i], pe);
0
211 else-
212 pe = &pixmaps[i];
never executed: pe = &pixmaps[i];
0
213 }-
214 return pe;
never executed: return pe;
0
215}-
216-
217-
218QPixmapIconEngineEntry *QPixmapIconEngine::bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly)-
219{-
220 QPixmapIconEngineEntry *pe = tryMatch(size, mode, state);-
221 while (!pe){
!peDescription
TRUEnever evaluated
FALSEnever evaluated
0
222 QIcon::State oppositeState = (state == QIcon::On) ? QIcon::Off : QIcon::On;
(state == QIcon::On)Description
TRUEnever evaluated
FALSEnever evaluated
0
223 if (mode == QIcon::Disabled || mode == QIcon::Selected) {
mode == QIcon::DisabledDescription
TRUEnever evaluated
FALSEnever evaluated
mode == QIcon::SelectedDescription
TRUEnever evaluated
FALSEnever evaluated
0
224 QIcon::Mode oppositeMode = (mode == QIcon::Disabled) ? QIcon::Selected : QIcon::Disabled;
(mode == QIcon::Disabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
225 if ((pe = tryMatch(size, QIcon::Normal, state)))
(pe = tryMatch...ormal, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
226 break;
never executed: break;
0
227 if ((pe = tryMatch(size, QIcon::Active, state)))
(pe = tryMatch...ctive, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
228 break;
never executed: break;
0
229 if ((pe = tryMatch(size, mode, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
230 break;
never executed: break;
0
231 if ((pe = tryMatch(size, QIcon::Normal, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
232 break;
never executed: break;
0
233 if ((pe = tryMatch(size, QIcon::Active, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
234 break;
never executed: break;
0
235 if ((pe = tryMatch(size, oppositeMode, state)))
(pe = tryMatch...eMode, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
236 break;
never executed: break;
0
237 if ((pe = tryMatch(size, oppositeMode, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
238 break;
never executed: break;
0
239 } else {
never executed: end of block
0
240 QIcon::Mode oppositeMode = (mode == QIcon::Normal) ? QIcon::Active : QIcon::Normal;
(mode == QIcon::Normal)Description
TRUEnever evaluated
FALSEnever evaluated
0
241 if ((pe = tryMatch(size, oppositeMode, state)))
(pe = tryMatch...eMode, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
242 break;
never executed: break;
0
243 if ((pe = tryMatch(size, mode, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
244 break;
never executed: break;
0
245 if ((pe = tryMatch(size, oppositeMode, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
246 break;
never executed: break;
0
247 if ((pe = tryMatch(size, QIcon::Disabled, state)))
(pe = tryMatch...abled, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
248 break;
never executed: break;
0
249 if ((pe = tryMatch(size, QIcon::Selected, state)))
(pe = tryMatch...ected, state))Description
TRUEnever evaluated
FALSEnever evaluated
0
250 break;
never executed: break;
0
251 if ((pe = tryMatch(size, QIcon::Disabled, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
252 break;
never executed: break;
0
253 if ((pe = tryMatch(size, QIcon::Selected, oppositeState)))
(pe = tryMatch...ppositeState))Description
TRUEnever evaluated
FALSEnever evaluated
0
254 break;
never executed: break;
0
255 }
never executed: end of block
0
256-
257 if (!pe)
!peDescription
TRUEnever evaluated
FALSEnever evaluated
0
258 return pe;
never executed: return pe;
0
259 }
never executed: end of block
0
260-
261 if (sizeOnly ? (pe->size.isNull() || !pe->size.isValid()) : pe->pixmap.isNull()) {
sizeOnly ? (pe...ixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
sizeOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
pe->size.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
!pe->size.isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
262 pe->pixmap = QPixmap(pe->fileName);-
263 if (!pe->pixmap.isNull())
!pe->pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
264 pe->size = pe->pixmap.size();
never executed: pe->size = pe->pixmap.size();
0
265 }
never executed: end of block
0
266-
267 return pe;
never executed: return pe;
0
268}-
269-
270QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)-
271{-
272 QPixmap pm;-
273 QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, false);-
274 if (pe)
peDescription
TRUEnever evaluated
FALSEnever evaluated
0
275 pm = pe->pixmap;
never executed: pm = pe->pixmap;
0
276-
277 if (pm.isNull()) {
pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
278 int idx = pixmaps.count();-
279 while (--idx >= 0) {
--idx >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
280 if (pe == &pixmaps[idx]) {
pe == &pixmaps[idx]Description
TRUEnever evaluated
FALSEnever evaluated
0
281 pixmaps.remove(idx);-
282 break;
never executed: break;
0
283 }-
284 }
never executed: end of block
0
285 if (pixmaps.isEmpty())
pixmaps.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
286 return pm;
never executed: return pm;
0
287 else-
288 return pixmap(size, mode, state);
never executed: return pixmap(size, mode, state);
0
289 }-
290-
291 QSize actualSize = pm.size();-
292 if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
!actualSize.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
actualSize.wid...> size.width()Description
TRUEnever evaluated
FALSEnever evaluated
actualSize.hei... size.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
293 actualSize.scale(size, Qt::KeepAspectRatio);
never executed: actualSize.scale(size, Qt::KeepAspectRatio);
0
294-
295 QString key = QLatin1String("qt_")-
296 % HexString<quint64>(pm.cacheKey())-
297 % HexString<uint>(pe ? pe->mode : QIcon::Normal)-
298 % HexString<quint64>(QGuiApplication::palette().cacheKey())-
299 % HexString<uint>(actualSize.width())-
300 % HexString<uint>(actualSize.height());-
301-
302 if (mode == QIcon::Active) {
mode == QIcon::ActiveDescription
TRUEnever evaluated
FALSEnever evaluated
0
303 if (QPixmapCache::find(key % HexString<uint>(mode), pm))
QPixmapCache::...nt>(mode), pm)Description
TRUEnever evaluated
FALSEnever evaluated
0
304 return pm; // horray
never executed: return pm;
0
305 if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)) {
QPixmapCache::...::Normal), pm)Description
TRUEnever evaluated
FALSEnever evaluated
0
306 QPixmap active = pm;-
307 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
QGuiApplicatio...:instance())))Description
TRUEnever evaluated
FALSEnever evaluated
0
308 active = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
never executed: active = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
0
309 if (pm.cacheKey() == active.cacheKey())
pm.cacheKey() ...ive.cacheKey()Description
TRUEnever evaluated
FALSEnever evaluated
0
310 return pm;
never executed: return pm;
0
311 }
never executed: end of block
0
312 }
never executed: end of block
0
313-
314 if (!QPixmapCache::find(key % HexString<uint>(mode), pm)) {
!QPixmapCache:...nt>(mode), pm)Description
TRUEnever evaluated
FALSEnever evaluated
0
315 if (pm.size() != actualSize)
pm.size() != actualSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
316 pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
never executed: pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
0
317 if (pe->mode != mode && mode != QIcon::Normal) {
pe->mode != modeDescription
TRUEnever evaluated
FALSEnever evaluated
mode != QIcon::NormalDescription
TRUEnever evaluated
FALSEnever evaluated
0
318 QPixmap generated = pm;-
319 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
QGuiApplicatio...:instance())))Description
TRUEnever evaluated
FALSEnever evaluated
0
320 generated = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm);
never executed: generated = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm);
0
321 if (!generated.isNull())
!generated.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
322 pm = generated;
never executed: pm = generated;
0
323 }
never executed: end of block
0
324 QPixmapCache::insert(key % HexString<uint>(mode), pm);-
325 }
never executed: end of block
0
326 return pm;
never executed: return pm;
0
327}-
328-
329QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state)-
330{-
331 QSize actualSize;-
332 if (QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, true))
QPixmapIconEng..., state, true)Description
TRUEnever evaluated
FALSEnever evaluated
0
333 actualSize = pe->size;
never executed: actualSize = pe->size;
0
334-
335 if (actualSize.isNull())
actualSize.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
336 return actualSize;
never executed: return actualSize;
0
337-
338 if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height()))
!actualSize.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
actualSize.wid...> size.width()Description
TRUEnever evaluated
FALSEnever evaluated
actualSize.hei... size.height()Description
TRUEnever evaluated
FALSEnever evaluated
0
339 actualSize.scale(size, Qt::KeepAspectRatio);
never executed: actualSize.scale(size, Qt::KeepAspectRatio);
0
340 return actualSize;
never executed: return actualSize;
0
341}-
342-
343void QPixmapIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)-
344{-
345 if (!pixmap.isNull()) {
!pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
346 QPixmapIconEngineEntry *pe = tryMatch(pixmap.size(), mode, state);-
347 if(pe && pe->size == pixmap.size()) {
peDescription
TRUEnever evaluated
FALSEnever evaluated
pe->size == pixmap.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
348 pe->pixmap = pixmap;-
349 pe->fileName.clear();-
350 } else {
never executed: end of block
0
351 pixmaps += QPixmapIconEngineEntry(pixmap, mode, state);-
352 }
never executed: end of block
0
353 }-
354}
never executed: end of block
0
355-
356// Read out original image depth as set by ICOReader-
357static inline int origIcoDepth(const QImage &image)-
358{-
359 const QString s = image.text(QStringLiteral("_q_icoOrigDepth"));
never executed: return qstring_literal_temp;
0
360 return s.isEmpty() ? 32 : s.toInt();
never executed: return s.isEmpty() ? 32 : s.toInt();
s.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
361}-
362-
363static inline int findBySize(const QVector<QImage> &images, const QSize &size)-
364{-
365 for (int i = 0; i < images.size(); ++i) {
i < images.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
366 if (images.at(i).size() == size)
images.at(i).size() == sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
367 return i;
never executed: return i;
0
368 }
never executed: end of block
0
369 return -1;
never executed: return -1;
0
370}-
371-
372// Convenience class providing a bool read() function.-
373namespace {-
374class ImageReader-
375{-
376public:-
377 ImageReader(const QString &fileName) : m_reader(fileName), m_atEnd(false) {}
never executed: end of block
0
378-
379 QByteArray format() const { return m_reader.format(); }
never executed: return m_reader.format();
0
380-
381 bool read(QImage *image)-
382 {-
383 if (m_atEnd)
m_atEndDescription
TRUEnever evaluated
FALSEnever evaluated
0
384 return false;
never executed: return false;
0
385 *image = m_reader.read();-
386 if (!image->size().isValid()) {
!image->size().isValid()Description
TRUEnever evaluated
FALSEnever evaluated
0
387 m_atEnd = true;-
388 return false;
never executed: return false;
0
389 }-
390 m_atEnd = !m_reader.jumpToNextImage();-
391 return true;
never executed: return true;
0
392 }-
393-
394private:-
395 QImageReader m_reader;-
396 bool m_atEnd;-
397};-
398} // namespace-
399-
400void QPixmapIconEngine::addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state)-
401{-
402 if (fileName.isEmpty())
fileName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
403 return;
never executed: return;
0
404 const QString abs = fileName.startsWith(QLatin1Char(':')) ? fileName : QFileInfo(fileName).absoluteFilePath();
fileName.start...tin1Char(':'))Description
TRUEnever evaluated
FALSEnever evaluated
0
405 const bool ignoreSize = !size.isValid();-
406 ImageReader imageReader(abs);-
407 const QByteArray format = imageReader.format();-
408 if (format.isEmpty()) // Device failed to open or unsupported format.
format.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
409 return;
never executed: return;
0
410 QImage image;-
411 if (format != "ico") {
format != "ico"Description
TRUEnever evaluated
FALSEnever evaluated
0
412 if (ignoreSize) { // No size specified: Add all images.
ignoreSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
413 while (imageReader.read(&image))
imageReader.read(&image)Description
TRUEnever evaluated
FALSEnever evaluated
0
414 pixmaps += QPixmapIconEngineEntry(abs, image, mode, state);
never executed: pixmaps += QPixmapIconEngineEntry(abs, image, mode, state);
0
415 } else {
never executed: end of block
0
416 // Try to match size. If that fails, add a placeholder with the filename and empty pixmap for the size.-
417 while (imageReader.read(&image) && image.size() != size) {}
never executed: end of block
imageReader.read(&image)Description
TRUEnever evaluated
FALSEnever evaluated
image.size() != sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
418 pixmaps += image.size() == size ?
image.size() == sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
419 QPixmapIconEngineEntry(abs, image, mode, state) : QPixmapIconEngineEntry(abs, size, mode, state);-
420 }
never executed: end of block
0
421 return;
never executed: return;
0
422 }-
423 // Special case for reading Windows ".ico" files. Historically (QTBUG-39287),-
424 // these files may contain low-resolution images. As this information is lost,-
425 // ICOReader sets the original format as an image text key value. Read all matching-
426 // images into a list trying to find the highest quality per size.-
427 QVector<QImage> icoImages;-
428 while (imageReader.read(&image)) {
imageReader.read(&image)Description
TRUEnever evaluated
FALSEnever evaluated
0
429 if (ignoreSize || image.size() == size) {
ignoreSizeDescription
TRUEnever evaluated
FALSEnever evaluated
image.size() == sizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
430 const int position = findBySize(icoImages, image.size());-
431 if (position >= 0) { // Higher quality available? -> replace.
position >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
432 if (origIcoDepth(image) > origIcoDepth(icoImages.at(position)))
origIcoDepth(i....at(position))Description
TRUEnever evaluated
FALSEnever evaluated
0
433 icoImages[position] = image;
never executed: icoImages[position] = image;
0
434 } else {
never executed: end of block
0
435 icoImages.append(image);-
436 }
never executed: end of block
0
437 }-
438 }
never executed: end of block
0
439 foreach (const QImage &i, icoImages)-
440 pixmaps += QPixmapIconEngineEntry(abs, i, mode, state);
never executed: pixmaps += QPixmapIconEngineEntry(abs, i, mode, state);
0
441 if (icoImages.isEmpty() && !ignoreSize) // Add placeholder with the filename and empty pixmap for the size.
icoImages.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!ignoreSizeDescription
TRUEnever evaluated
FALSEnever evaluated
0
442 pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
never executed: pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
0
443}
never executed: end of block
0
444-
445QString QPixmapIconEngine::key() const-
446{-
447 return QLatin1String("QPixmapIconEngine");
never executed: return QLatin1String("QPixmapIconEngine");
0
448}-
449-
450QIconEngine *QPixmapIconEngine::clone() const-
451{-
452 return new QPixmapIconEngine(*this);
never executed: return new QPixmapIconEngine(*this);
0
453}-
454-
455bool QPixmapIconEngine::read(QDataStream &in)-
456{-
457 int num_entries;-
458 QPixmap pm;-
459 QString fileName;-
460 QSize sz;-
461 uint mode;-
462 uint state;-
463-
464 in >> num_entries;-
465 for (int i=0; i < num_entries; ++i) {
i < num_entriesDescription
TRUEnever evaluated
FALSEnever evaluated
0
466 if (in.atEnd()) {
in.atEnd()Description
TRUEnever evaluated
FALSEnever evaluated
0
467 pixmaps.clear();-
468 return false;
never executed: return false;
0
469 }-
470 in >> pm;-
471 in >> fileName;-
472 in >> sz;-
473 in >> mode;-
474 in >> state;-
475 if (pm.isNull()) {
pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
476 addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));-
477 } else {
never executed: end of block
0
478 QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state));-
479 pe.pixmap = pm;-
480 pixmaps += pe;-
481 }
never executed: end of block
0
482 }-
483 return true;
never executed: return true;
0
484}-
485-
486bool QPixmapIconEngine::write(QDataStream &out) const-
487{-
488 int num_entries = pixmaps.size();-
489 out << num_entries;-
490 for (int i=0; i < num_entries; ++i) {
i < num_entriesDescription
TRUEnever evaluated
FALSEnever evaluated
0
491 if (pixmaps.at(i).pixmap.isNull())
pixmaps.at(i).pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
492 out << QPixmap(pixmaps.at(i).fileName);
never executed: out << QPixmap(pixmaps.at(i).fileName);
0
493 else-
494 out << pixmaps.at(i).pixmap;
never executed: out << pixmaps.at(i).pixmap;
0
495 out << pixmaps.at(i).fileName;-
496 out << pixmaps.at(i).size;-
497 out << (uint) pixmaps.at(i).mode;-
498 out << (uint) pixmaps.at(i).state;-
499 }
never executed: end of block
0
500 return true;
never executed: return true;
0
501}-
502-
503void QPixmapIconEngine::virtual_hook(int id, void *data)-
504{-
505 switch (id) {-
506 case QIconEngine::AvailableSizesHook: {
never executed: case QIconEngine::AvailableSizesHook:
0
507 QIconEngine::AvailableSizesArgument &arg =-
508 *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data);-
509 arg.sizes.clear();-
510 for (int i = 0; i < pixmaps.size(); ++i) {
i < pixmaps.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
511 QPixmapIconEngineEntry &pe = pixmaps[i];-
512 if (pe.size == QSize() && pe.pixmap.isNull()) {
pe.size == QSize()Description
TRUEnever evaluated
FALSEnever evaluated
pe.pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
513 pe.pixmap = QPixmap(pe.fileName);-
514 pe.size = pe.pixmap.size();-
515 }
never executed: end of block
0
516 if (pe.mode == arg.mode && pe.state == arg.state && !pe.size.isEmpty())
pe.mode == arg.modeDescription
TRUEnever evaluated
FALSEnever evaluated
pe.state == arg.stateDescription
TRUEnever evaluated
FALSEnever evaluated
!pe.size.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
517 arg.sizes.push_back(pe.size);
never executed: arg.sizes.push_back(pe.size);
0
518 }
never executed: end of block
0
519 break;
never executed: break;
0
520 }-
521 default:
never executed: default:
0
522 QIconEngine::virtual_hook(id, data);-
523 }
never executed: end of block
0
524}-
525-
526#ifndef QT_NO_LIBRARY-
527Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
never executed: end of block
never executed: guard.store(QtGlobalStatic::Destroyed);
never executed: return &holder.value;
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
0
528 (QIconEngineFactoryInterface_iid, QLatin1String("/iconengines"), Qt::CaseInsensitive))-
529-
530QFactoryLoader *qt_iconEngineFactoryLoader()-
531{-
532 return loader();
never executed: return loader();
0
533}-
534#endif-
535-
536-
537-
538/*!-
539 \class QIcon-
540-
541 \brief The QIcon class provides scalable icons in different modes-
542 and states.-
543-
544 \ingroup painting-
545 \ingroup shared-
546 \inmodule QtGui-
547-
548 A QIcon can generate smaller, larger, active, and disabled pixmaps-
549 from the set of pixmaps it is given. Such pixmaps are used by Qt-
550 widgets to show an icon representing a particular action.-
551-
552 The simplest use of QIcon is to create one from a QPixmap file or-
553 resource, and then use it, allowing Qt to work out all the required-
554 icon styles and sizes. For example:-
555-
556 \snippet code/src_gui_image_qicon.cpp 0-
557-
558 To undo a QIcon, simply set a null icon in its place:-
559-
560 \snippet code/src_gui_image_qicon.cpp 1-
561-
562 Use the QImageReader::supportedImageFormats() and-
563 QImageWriter::supportedImageFormats() functions to retrieve a-
564 complete list of the supported file formats.-
565-
566 When you retrieve a pixmap using pixmap(QSize, Mode, State), and no-
567 pixmap for this given size, mode and state has been added with-
568 addFile() or addPixmap(), then QIcon will generate one on the-
569 fly. This pixmap generation happens in a QIconEngineV2. The default-
570 engine scales pixmaps down if required, but never up, and it uses-
571 the current style to calculate a disabled appearance. By using-
572 custom icon engines, you can customize every aspect of generated-
573 icons. With QIconEnginePluginV2 it is possible to register different-
574 icon engines for different file suffixes, making it possible for-
575 third parties to provide additional icon engines to those included-
576 with Qt.-
577-
578 \note Since Qt 4.2, an icon engine that supports SVG is included.-
579-
580 \section1 Making Classes that Use QIcon-
581-
582 If you write your own widgets that have an option to set a small-
583 pixmap, consider allowing a QIcon to be set for that pixmap. The-
584 Qt class QToolButton is an example of such a widget.-
585-
586 Provide a method to set a QIcon, and when you draw the icon, choose-
587 whichever pixmap is appropriate for the current state of your widget.-
588 For example:-
589 \snippet code/src_gui_image_qicon.cpp 2-
590-
591 You might also make use of the \c Active mode, perhaps making your-
592 widget \c Active when the mouse is over the widget (see \l-
593 QWidget::enterEvent()), while the mouse is pressed pending the-
594 release that will activate the function, or when it is the currently-
595 selected item. If the widget can be toggled, the "On" mode might be-
596 used to draw a different icon.-
597-
598 \image icon.png QIcon-
599-
600 \note QIcon needs a QGuiApplication instance before the icon is created.-
601-
602 \sa {fowler}{GUI Design Handbook: Iconic Label}, {Icons Example}-
603*/-
604-
605-
606/*!-
607 Constructs a null icon.-
608*/-
609QIcon::QIcon() Q_DECL_NOEXCEPT-
610 : d(0)-
611{-
612}
never executed: end of block
0
613-
614/*!-
615 Constructs an icon from a \a pixmap.-
616 */-
617QIcon::QIcon(const QPixmap &pixmap)-
618 :d(0)-
619{-
620 addPixmap(pixmap);-
621}
never executed: end of block
0
622-
623/*!-
624 Constructs a copy of \a other. This is very fast.-
625*/-
626QIcon::QIcon(const QIcon &other)-
627 :d(other.d)-
628{-
629 if (d)
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
630 d->ref.ref();
never executed: d->ref.ref();
0
631}
never executed: end of block
0
632-
633/*!-
634 \fn QIcon::QIcon(QIcon &&other)-
635-
636 Move-constructs a QIcon instance, making it point to the same object-
637 that \a other was pointing to.-
638*/-
639-
640/*!-
641 Constructs an icon from the file with the given \a fileName. The-
642 file will be loaded on demand.-
643-
644 If \a fileName contains a relative path (e.g. the filename only)-
645 the relevant file must be found relative to the runtime working-
646 directory.-
647-
648 The file name can be either refer to an actual file on disk or to-
649 one of the application's embedded resources. See the-
650 \l{resources.html}{Resource System} overview for details on how to-
651 embed images and other resource files in the application's-
652 executable.-
653-
654 Use the QImageReader::supportedImageFormats() and-
655 QImageWriter::supportedImageFormats() functions to retrieve a-
656 complete list of the supported file formats.-
657*/-
658QIcon::QIcon(const QString &fileName)-
659 : d(0)-
660{-
661 addFile(fileName);-
662}
never executed: end of block
0
663-
664-
665/*!-
666 Creates an icon with a specific icon \a engine. The icon takes-
667 ownership of the engine.-
668*/-
669QIcon::QIcon(QIconEngine *engine)-
670 :d(new QIconPrivate)-
671{-
672 d->engine = engine;-
673}
never executed: end of block
0
674-
675/*!-
676 Destroys the icon.-
677*/-
678QIcon::~QIcon()-
679{-
680 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
681 delete d;
never executed: delete d;
0
682}
never executed: end of block
0
683-
684/*!-
685 Assigns the \a other icon to this icon and returns a reference to-
686 this icon.-
687*/-
688QIcon &QIcon::operator=(const QIcon &other)-
689{-
690 if (other.d)
other.dDescription
TRUEnever evaluated
FALSEnever evaluated
0
691 other.d->ref.ref();
never executed: other.d->ref.ref();
0
692 if (d && !d->ref.deref())
dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
693 delete d;
never executed: delete d;
0
694 d = other.d;-
695 return *this;
never executed: return *this;
0
696}-
697-
698/*!-
699 \fn QIcon &QIcon::operator=(QIcon &&other)-
700-
701 Move-assigns \a other to this QIcon instance.-
702-
703 \since 5.2-
704*/-
705-
706/*!-
707 \fn void QIcon::swap(QIcon &other)-
708 \since 4.8-
709-
710 Swaps icon \a other with this icon. This operation is very-
711 fast and never fails.-
712*/-
713-
714/*!-
715 Returns the icon as a QVariant.-
716*/-
717QIcon::operator QVariant() const-
718{-
719 return QVariant(QVariant::Icon, this);
never executed: return QVariant(QVariant::Icon, this);
0
720}-
721-
722/*! \fn int QIcon::serialNumber() const-
723 \obsolete-
724-
725 Returns a number that identifies the contents of this-
726 QIcon object. Distinct QIcon objects can have-
727 the same serial number if they refer to the same contents-
728 (but they don't have to). Also, the serial number of-
729 a QIcon object may change during its lifetime.-
730-
731 Use cacheKey() instead.-
732-
733 A null icon always has a serial number of 0.-
734-
735 Serial numbers are mostly useful in conjunction with caching.-
736-
737 \sa QPixmap::serialNumber()-
738*/-
739-
740/*!-
741 Returns a number that identifies the contents of this QIcon-
742 object. Distinct QIcon objects can have the same key if-
743 they refer to the same contents.-
744 \since 4.3-
745-
746 The cacheKey() will change when the icon is altered via-
747 addPixmap() or addFile().-
748-
749 Cache keys are mostly useful in conjunction with caching.-
750-
751 \sa QPixmap::cacheKey()-
752*/-
753qint64 QIcon::cacheKey() const-
754{-
755 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
756 return 0;
never executed: return 0;
0
757 return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no));
never executed: return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no));
0
758}-
759-
760/*!-
761 Returns a pixmap with the requested \a size, \a mode, and \a-
762 state, generating one if necessary. The pixmap might be smaller than-
763 requested, but never larger.-
764-
765 Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this-
766 function to return pixmaps that are larger than the requested size. Such-
767 images will have a devicePixelRatio larger than 1.-
768-
769 \sa actualSize(), paint()-
770*/-
771QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const-
772{-
773 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
774 return QPixmap();
never executed: return QPixmap();
0
775 return pixmap(0, size, mode, state);
never executed: return pixmap(0, size, mode, state);
0
776}-
777-
778/*!-
779 \fn QPixmap QIcon::pixmap(int w, int h, Mode mode = Normal, State state = Off) const-
780-
781 \overload-
782-
783 Returns a pixmap of size QSize(\a w, \a h). The pixmap might be smaller than-
784 requested, but never larger.-
785-
786 Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this-
787 function to return pixmaps that are larger than the requested size. Such-
788 images will have a devicePixelRatio larger than 1.-
789*/-
790-
791/*!-
792 \fn QPixmap QIcon::pixmap(int extent, Mode mode = Normal, State state = Off) const-
793-
794 \overload-
795-
796 Returns a pixmap of size QSize(\a extent, \a extent). The pixmap might be smaller-
797 than requested, but never larger.-
798-
799 Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this-
800 function to return pixmaps that are larger than the requested size. Such-
801 images will have a devicePixelRatio larger than 1.-
802*/-
803-
804/*! Returns the actual size of the icon for the requested \a size, \a-
805 mode, and \a state. The result might be smaller than requested, but-
806 never larger. The returned size is in device-independent pixels (This-
807 is relevant for high-dpi pixmaps.)-
808-
809 \sa pixmap(), paint()-
810*/-
811QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const-
812{-
813 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
814 return QSize();
never executed: return QSize();
0
815 return actualSize(0, size, mode, state);
never executed: return actualSize(0, size, mode, state);
0
816}-
817-
818/*!-
819 \since 5.1-
820-
821 Returns a pixmap with the requested \a window \a size, \a mode, and \a-
822 state, generating one if necessary.-
823-
824 The pixmap can be smaller than the requested size. If \a window is on-
825 a high-dpi display the pixmap can be larger. In that case it will have-
826 a devicePixelRatio larger than 1.-
827-
828 \sa actualSize(), paint()-
829*/-
830QPixmap QIcon::pixmap(QWindow *window, const QSize &size, Mode mode, State state) const-
831{-
832 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
833 return QPixmap();
never executed: return QPixmap();
0
834-
835 qreal devicePixelRatio = qt_effective_device_pixel_ratio(window);-
836-
837 // Handle the simple normal-dpi case:-
838 if (!(devicePixelRatio > 1.0)) {
!(devicePixelRatio > 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
839 QPixmap pixmap = d->engine->pixmap(size, mode, state);-
840 pixmap.setDevicePixelRatio(1.0);-
841 return pixmap;
never executed: return pixmap;
0
842 }-
843-
844 // Try get a pixmap that is big enough to be displayed at device pixel resolution.-
845 QPixmap pixmap = d->engine->pixmap(size * devicePixelRatio, mode, state);-
846 pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size()));-
847 return pixmap;
never executed: return pixmap;
0
848}-
849-
850/*!-
851 \since 5.1-
852-
853 Returns the actual size of the icon for the requested \a window \a size, \a-
854 mode, and \a state.-
855-
856 The pixmap can be smaller than the requested size. The returned size-
857 is in device-independent pixels (This is relevant for high-dpi pixmaps.)-
858-
859 \sa actualSize(), pixmap(), paint()-
860*/-
861QSize QIcon::actualSize(QWindow *window, const QSize &size, Mode mode, State state) const-
862{-
863 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
864 return QSize();
never executed: return QSize();
0
865-
866 qreal devicePixelRatio = qt_effective_device_pixel_ratio(window);-
867-
868 // Handle the simple normal-dpi case:-
869 if (!(devicePixelRatio > 1.0))
!(devicePixelRatio > 1.0)Description
TRUEnever evaluated
FALSEnever evaluated
0
870 return d->engine->actualSize(size, mode, state);
never executed: return d->engine->actualSize(size, mode, state);
0
871-
872 QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state);-
873 return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
never executed: return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
0
874}-
875-
876/*!-
877 Uses the \a painter to paint the icon with specified \a alignment,-
878 required \a mode, and \a state into the rectangle \a rect.-
879-
880 \sa actualSize(), pixmap()-
881*/-
882void QIcon::paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment, Mode mode, State state) const-
883{-
884 if (!d || !painter)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!painterDescription
TRUEnever evaluated
FALSEnever evaluated
0
885 return;
never executed: return;
0
886-
887 // Copy of QStyle::alignedRect-
888 const QSize size = d->engine->actualSize(rect.size(), mode, state);-
889 alignment = QGuiApplicationPrivate::visualAlignment(painter->layoutDirection(), alignment);-
890 int x = rect.x();-
891 int y = rect.y();-
892 int w = size.width();-
893 int h = size.height();-
894 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
(alignment & Q...::AlignVCenterDescription
TRUEnever evaluated
FALSEnever evaluated
0
895 y += rect.size().height()/2 - h/2;
never executed: y += rect.size().height()/2 - h/2;
0
896 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
(alignment & Q...t::AlignBottomDescription
TRUEnever evaluated
FALSEnever evaluated
0
897 y += rect.size().height() - h;
never executed: y += rect.size().height() - h;
0
898 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
(alignment & Q...Qt::AlignRightDescription
TRUEnever evaluated
FALSEnever evaluated
0
899 x += rect.size().width() - w;
never executed: x += rect.size().width() - w;
0
900 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
(alignment & Q...::AlignHCenterDescription
TRUEnever evaluated
FALSEnever evaluated
0
901 x += rect.size().width()/2 - w/2;
never executed: x += rect.size().width()/2 - w/2;
0
902 QRect alignedRect(x, y, w, h);-
903-
904 d->engine->paint(painter, alignedRect, mode, state);-
905}
never executed: end of block
0
906-
907/*!-
908 \fn void QIcon::paint(QPainter *painter, int x, int y, int w, int h, Qt::Alignment alignment,-
909 Mode mode, State state) const-
910-
911 \overload-
912-
913 Paints the icon into the rectangle QRect(\a x, \a y, \a w, \a h).-
914*/-
915-
916/*!-
917 Returns \c true if the icon is empty; otherwise returns \c false.-
918-
919 An icon is empty if it has neither a pixmap nor a filename.-
920-
921 Note: Even a non-null icon might not be able to create valid-
922 pixmaps, eg. if the file does not exist or cannot be read.-
923*/-
924bool QIcon::isNull() const-
925{-
926 return !d;
never executed: return !d;
0
927}-
928-
929/*!\internal-
930 */-
931bool QIcon::isDetached() const-
932{-
933 return !d || d->ref.load() == 1;
never executed: return !d || d->ref.load() == 1;
!dDescription
TRUEnever evaluated
FALSEnever evaluated
d->ref.load() == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
934}-
935-
936/*! \internal-
937 */-
938void QIcon::detach()-
939{-
940 if (d) {
dDescription
TRUEnever evaluated
FALSEnever evaluated
0
941 if (d->ref.load() != 1) {
d->ref.load() != 1Description
TRUEnever evaluated
FALSEnever evaluated
0
942 QIconPrivate *x = new QIconPrivate;-
943 x->engine = d->engine->clone();-
944 if (!d->ref.deref())
!d->ref.deref()Description
TRUEnever evaluated
FALSEnever evaluated
0
945 delete d;
never executed: delete d;
0
946 d = x;-
947 }
never executed: end of block
0
948 ++d->detach_no;-
949 }
never executed: end of block
0
950}
never executed: end of block
0
951-
952/*!-
953 Adds \a pixmap to the icon, as a specialization for \a mode and-
954 \a state.-
955-
956 Custom icon engines are free to ignore additionally added-
957 pixmaps.-
958-
959 \sa addFile()-
960*/-
961void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state)-
962{-
963 if (pixmap.isNull())
pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
964 return;
never executed: return;
0
965 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
966 d = new QIconPrivate;-
967 d->engine = new QPixmapIconEngine;-
968 } else {
never executed: end of block
0
969 detach();-
970 }
never executed: end of block
0
971 d->engine->addPixmap(pixmap, mode, state);-
972}
never executed: end of block
0
973-
974-
975/*! Adds an image from the file with the given \a fileName to the-
976 icon, as a specialization for \a size, \a mode and \a state. The-
977 file will be loaded on demand. Note: custom icon engines are free-
978 to ignore additionally added pixmaps.-
979-
980 If \a fileName contains a relative path (e.g. the filename only)-
981 the relevant file must be found relative to the runtime working-
982 directory.-
983-
984 The file name can be either refer to an actual file on disk or to-
985 one of the application's embedded resources. See the-
986 \l{resources.html}{Resource System} overview for details on how to-
987 embed images and other resource files in the application's-
988 executable.-
989-
990 Use the QImageReader::supportedImageFormats() and-
991 QImageWriter::supportedImageFormats() functions to retrieve a-
992 complete list of the supported file formats.-
993-
994 If a high resolution version of the image exists (identified by-
995 the suffix \c @2x on the base name), it is automatically loaded-
996 and added with the \e{device pixel ratio} set to a value of 2.-
997 This can be disabled by setting the environment variable-
998 \c QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING (see QImageReader).-
999-
1000 \note When you add a non-empty filename to a QIcon, the icon becomes-
1001 non-null, even if the file doesn't exist or points to a corrupt file.-
1002-
1003 \sa addPixmap(), QPixmap::devicePixelRatio()-
1004 */-
1005void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state)-
1006{-
1007 if (fileName.isEmpty())
fileName.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1008 return;
never executed: return;
0
1009 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1010#ifndef QT_NO_LIBRARY-
1011 QFileInfo info(fileName);-
1012 QString suffix = info.suffix();-
1013 if (!suffix.isEmpty()) {
!suffix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1014 // first try version 2 engines..-
1015 const int index = loader()->indexOf(suffix);-
1016 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1017 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))) {
QIconEnginePlu...stance(index))Description
TRUEnever evaluated
FALSEnever evaluated
0
1018 if (QIconEngine *engine = factory->create(fileName)) {
QIconEngine *e...eate(fileName)Description
TRUEnever evaluated
FALSEnever evaluated
0
1019 d = new QIconPrivate;-
1020 d->engine = engine;-
1021 }
never executed: end of block
0
1022 }
never executed: end of block
0
1023 }
never executed: end of block
0
1024 }
never executed: end of block
0
1025#endif-
1026 // ...then fall back to the default engine-
1027 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1028 d = new QIconPrivate;-
1029 d->engine = new QPixmapIconEngine;-
1030 }
never executed: end of block
0
1031 } else {
never executed: end of block
0
1032 detach();-
1033 }
never executed: end of block
0
1034-
1035 d->engine->addFile(fileName, size, mode, state);-
1036-
1037 // Check if a "@Nx" file exists and add it.-
1038 QString atNxFileName = qt_findAtNxFile(fileName, qApp->devicePixelRatio());-
1039 if (atNxFileName != fileName)
atNxFileName != fileNameDescription
TRUEnever evaluated
FALSEnever evaluated
0
1040 d->engine->addFile(atNxFileName, size, mode, state);
never executed: d->engine->addFile(atNxFileName, size, mode, state);
0
1041}
never executed: end of block
0
1042-
1043/*!-
1044 \since 4.5-
1045-
1046 Returns a list of available icon sizes for the specified \a mode and-
1047 \a state.-
1048*/-
1049QList<QSize> QIcon::availableSizes(Mode mode, State state) const-
1050{-
1051 if (!d || !d->engine)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->engineDescription
TRUEnever evaluated
FALSEnever evaluated
0
1052 return QList<QSize>();
never executed: return QList<QSize>();
0
1053 return d->engine->availableSizes(mode, state);
never executed: return d->engine->availableSizes(mode, state);
0
1054}-
1055-
1056/*!-
1057 \since 4.7-
1058-
1059 Returns the name used to create the icon, if available.-
1060-
1061 Depending on the way the icon was created, it may have an associated-
1062 name. This is the case for icons created with fromTheme() or icons-
1063 using a QIconEngine which supports the QIconEngineV2::IconNameHook.-
1064-
1065 \sa fromTheme(), QIconEngine-
1066*/-
1067QString QIcon::name() const-
1068{-
1069 if (!d || !d->engine)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
!d->engineDescription
TRUEnever evaluated
FALSEnever evaluated
0
1070 return QString();
never executed: return QString();
0
1071 return d->engine->iconName();
never executed: return d->engine->iconName();
0
1072}-
1073-
1074/*!-
1075 \since 4.6-
1076-
1077 Sets the search paths for icon themes to \a paths.-
1078 \sa themeSearchPaths(), fromTheme(), setThemeName()-
1079*/-
1080void QIcon::setThemeSearchPaths(const QStringList &paths)-
1081{-
1082 QIconLoader::instance()->setThemeSearchPath(paths);-
1083}
never executed: end of block
0
1084-
1085/*!-
1086 \since 4.6-
1087-
1088 Returns the search paths for icon themes.-
1089-
1090 The default value will depend on the platform:-
1091-
1092 On X11, the search path will use the XDG_DATA_DIRS environment-
1093 variable if available.-
1094-
1095 By default all platforms will have the resource directory-
1096 \c{:\icons} as a fallback. You can use "rcc -project" to generate a-
1097 resource file from your icon theme.-
1098-
1099 \sa setThemeSearchPaths(), fromTheme(), setThemeName()-
1100*/-
1101QStringList QIcon::themeSearchPaths()-
1102{-
1103 return QIconLoader::instance()->themeSearchPaths();
never executed: return QIconLoader::instance()->themeSearchPaths();
0
1104}-
1105-
1106/*!-
1107 \since 4.6-
1108-
1109 Sets the current icon theme to \a name.-
1110-
1111 The \a name should correspond to a directory name in the-
1112 themeSearchPath() containing an index.theme-
1113 file describing it's contents.-
1114-
1115 \sa themeSearchPaths(), themeName()-
1116*/-
1117void QIcon::setThemeName(const QString &name)-
1118{-
1119 QIconLoader::instance()->setThemeName(name);-
1120}
never executed: end of block
0
1121-
1122/*!-
1123 \since 4.6-
1124-
1125 Returns the name of the current icon theme.-
1126-
1127 On X11, the current icon theme depends on your desktop-
1128 settings. On other platforms it is not set by default.-
1129-
1130 \sa setThemeName(), themeSearchPaths(), fromTheme(),-
1131 hasThemeIcon()-
1132*/-
1133QString QIcon::themeName()-
1134{-
1135 return QIconLoader::instance()->themeName();
never executed: return QIconLoader::instance()->themeName();
0
1136}-
1137-
1138/*!-
1139 \since 4.6-
1140-
1141 Returns the QIcon corresponding to \a name in the current-
1142 icon theme. If no such icon is found in the current theme-
1143 \a fallback is returned instead.-
1144-
1145 The latest version of the freedesktop icon specification and naming-
1146 specification can be obtained here:-
1147-
1148 \list-
1149 \li \l{http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html}-
1150 \li \l{http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html}-
1151 \endlist-
1152-
1153 To fetch an icon from the current icon theme:-
1154-
1155 \snippet code/src_gui_image_qicon.cpp 3-
1156-
1157 Or if you want to provide a guaranteed fallback for platforms that-
1158 do not support theme icons, you can use the second argument:-
1159-
1160 \snippet code/src_gui_image_qicon.cpp 4-
1161-
1162 \note By default, only X11 will support themed icons. In order to-
1163 use themed icons on Mac and Windows, you will have to bundle a-
1164 compliant theme in one of your themeSearchPaths() and set the-
1165 appropriate themeName().-
1166-
1167 \sa themeName(), setThemeName(), themeSearchPaths()-
1168*/-
1169QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)-
1170{-
1171 QIcon icon;-
1172-
1173 if (qtIconCache()->contains(name)) {
qtIconCache()->contains(name)Description
TRUEnever evaluated
FALSEnever evaluated
0
1174 icon = *qtIconCache()->object(name);-
1175 } else {
never executed: end of block
0
1176 QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme();-
1177 bool hasUserTheme = QIconLoader::instance()->hasUserTheme();-
1178 QIconEngine * const engine = (platformTheme && !hasUserTheme) ? platformTheme->createIconEngine(name)
platformThemeDescription
TRUEnever evaluated
FALSEnever evaluated
!hasUserThemeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1179 : new QIconLoaderEngine(name);-
1180 QIcon *cachedIcon = new QIcon(engine);-
1181 icon = *cachedIcon;-
1182 qtIconCache()->insert(name, cachedIcon);-
1183 }
never executed: end of block
0
1184-
1185 if (qApp && icon.availableSizes().isEmpty())
(static_cast<Q...::instance()))Description
TRUEnever evaluated
FALSEnever evaluated
icon.available...es().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1186 return fallback;
never executed: return fallback;
0
1187-
1188 return icon;
never executed: return icon;
0
1189}-
1190-
1191/*!-
1192 \since 4.6-
1193-
1194 Returns \c true if there is an icon available for \a name in the-
1195 current icon theme, otherwise returns \c false.-
1196-
1197 \sa themeSearchPaths(), fromTheme(), setThemeName()-
1198*/-
1199bool QIcon::hasThemeIcon(const QString &name)-
1200{-
1201 QIcon icon = fromTheme(name);-
1202-
1203 return icon.name() == name;
never executed: return icon.name() == name;
0
1204}-
1205-
1206/*!-
1207 \since 5.6-
1208-
1209 Indicate that this icon is a mask image, and hence can potentially-
1210 be modified based on where it's displayed.-
1211 \sa isMask()-
1212*/-
1213void QIcon::setIsMask(bool isMask)-
1214{-
1215 if (!d) {
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1216 d = new QIconPrivate;-
1217 d->engine = new QPixmapIconEngine;-
1218 } else {
never executed: end of block
0
1219 detach();-
1220 }
never executed: end of block
0
1221 d->is_mask = isMask;-
1222}
never executed: end of block
0
1223-
1224/*!-
1225 \since 5.6-
1226-
1227 Returns \c true if this icon has been marked as a mask image.-
1228 Certain platforms render mask icons differently (for example,-
1229 menu icons on \macos).-
1230-
1231 \sa setIsMask()-
1232*/-
1233bool QIcon::isMask() const-
1234{-
1235 if (!d)
!dDescription
TRUEnever evaluated
FALSEnever evaluated
0
1236 return false;
never executed: return false;
0
1237 return d->is_mask;
never executed: return d->is_mask;
0
1238}-
1239-
1240/*****************************************************************************-
1241 QIcon stream functions-
1242 *****************************************************************************/-
1243#if !defined(QT_NO_DATASTREAM)-
1244/*!-
1245 \fn QDataStream &operator<<(QDataStream &stream, const QIcon &icon)-
1246 \relates QIcon-
1247 \since 4.2-
1248-
1249 Writes the given \a icon to the given \a stream as a PNG-
1250 image. If the icon contains more than one image, all images will-
1251 be written to the stream. Note that writing the stream to a file-
1252 will not produce a valid image file.-
1253*/-
1254-
1255QDataStream &operator<<(QDataStream &s, const QIcon &icon)-
1256{-
1257 if (s.version() >= QDataStream::Qt_4_3) {
s.version() >=...Stream::Qt_4_3Description
TRUEnever evaluated
FALSEnever evaluated
0
1258 if (icon.isNull()) {
icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1259 s << QString();-
1260 } else {
never executed: end of block
0
1261 s << icon.d->engine->key();-
1262 icon.d->engine->write(s);-
1263 }
never executed: end of block
0
1264 } else if (s.version() == QDataStream::Qt_4_2) {
s.version() ==...Stream::Qt_4_2Description
TRUEnever evaluated
FALSEnever evaluated
0
1265 if (icon.isNull()) {
icon.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1266 s << 0;-
1267 } else {
never executed: end of block
0
1268 QPixmapIconEngine *engine = static_cast<QPixmapIconEngine *>(icon.d->engine);-
1269 int num_entries = engine->pixmaps.size();-
1270 s << num_entries;-
1271 for (int i=0; i < num_entries; ++i) {
i < num_entriesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1272 s << engine->pixmaps.at(i).pixmap;-
1273 s << engine->pixmaps.at(i).fileName;-
1274 s << engine->pixmaps.at(i).size;-
1275 s << (uint) engine->pixmaps.at(i).mode;-
1276 s << (uint) engine->pixmaps.at(i).state;-
1277 }
never executed: end of block
0
1278 }
never executed: end of block
0
1279 } else {-
1280 s << QPixmap(icon.pixmap(22,22));-
1281 }
never executed: end of block
0
1282 return s;
never executed: return s;
0
1283}-
1284-
1285/*!-
1286 \fn QDataStream &operator>>(QDataStream &stream, QIcon &icon)-
1287 \relates QIcon-
1288 \since 4.2-
1289-
1290 Reads an image, or a set of images, from the given \a stream into-
1291 the given \a icon.-
1292*/-
1293-
1294QDataStream &operator>>(QDataStream &s, QIcon &icon)-
1295{-
1296 if (s.version() >= QDataStream::Qt_4_3) {
s.version() >=...Stream::Qt_4_3Description
TRUEnever evaluated
FALSEnever evaluated
0
1297 icon = QIcon();-
1298 QString key;-
1299 s >> key;-
1300 if (key == QLatin1String("QPixmapIconEngine")) {
key == QLatin1...apIconEngine")Description
TRUEnever evaluated
FALSEnever evaluated
0
1301 icon.d = new QIconPrivate;-
1302 QIconEngine *engine = new QPixmapIconEngine;-
1303 icon.d->engine = engine;-
1304 engine->read(s);-
1305 } else if (key == QLatin1String("QIconLoaderEngine")) {
never executed: end of block
key == QLatin1...LoaderEngine")Description
TRUEnever evaluated
FALSEnever evaluated
0
1306 icon.d = new QIconPrivate;-
1307 QIconEngine *engine = new QIconLoaderEngine();-
1308 icon.d->engine = engine;-
1309 engine->read(s);-
1310#ifndef QT_NO_LIBRARY-
1311 } else {
never executed: end of block
0
1312 const int index = loader()->indexOf(key);-
1313 if (index != -1) {
index != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1314 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))) {
QIconEnginePlu...stance(index))Description
TRUEnever evaluated
FALSEnever evaluated
0
1315 if (QIconEngine *engine= factory->create()) {
QIconEngine *e...tory->create()Description
TRUEnever evaluated
FALSEnever evaluated
0
1316 icon.d = new QIconPrivate;-
1317 icon.d->engine = engine;-
1318 engine->read(s);-
1319 } // factory
never executed: end of block
0
1320 } // instance
never executed: end of block
0
1321 } // index
never executed: end of block
0
1322#endif-
1323 }
never executed: end of block
0
1324 } else if (s.version() == QDataStream::Qt_4_2) {
s.version() ==...Stream::Qt_4_2Description
TRUEnever evaluated
FALSEnever evaluated
0
1325 icon = QIcon();-
1326 int num_entries;-
1327 QPixmap pm;-
1328 QString fileName;-
1329 QSize sz;-
1330 uint mode;-
1331 uint state;-
1332-
1333 s >> num_entries;-
1334 for (int i=0; i < num_entries; ++i) {
i < num_entriesDescription
TRUEnever evaluated
FALSEnever evaluated
0
1335 s >> pm;-
1336 s >> fileName;-
1337 s >> sz;-
1338 s >> mode;-
1339 s >> state;-
1340 if (pm.isNull())
pm.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1341 icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
never executed: icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
0
1342 else-
1343 icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
never executed: icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
0
1344 }-
1345 } else {
never executed: end of block
0
1346 QPixmap pm;-
1347 s >> pm;-
1348 icon.addPixmap(pm);-
1349 }
never executed: end of block
0
1350 return s;
never executed: return s;
0
1351}-
1352-
1353#endif //QT_NO_DATASTREAM-
1354-
1355#ifndef QT_NO_DEBUG_STREAM-
1356QDebug operator<<(QDebug dbg, const QIcon &i)-
1357{-
1358 QDebugStateSaver saver(dbg);-
1359 dbg.resetFormat();-
1360 dbg.nospace();-
1361 dbg << "QIcon(";-
1362 if (i.isNull()) {
i.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1363 dbg << "null";-
1364 } else {
never executed: end of block
0
1365 if (!i.name().isEmpty())
!i.name().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1366 dbg << i.name() << ',';
never executed: dbg << i.name() << ',';
0
1367 dbg << "availableSizes[normal,Off]=" << i.availableSizes()-
1368 << ",cacheKey=" << showbase << hex << i.cacheKey() << dec << noshowbase;-
1369 }
never executed: end of block
0
1370 dbg << ')';-
1371 return dbg;
never executed: return dbg;
0
1372}-
1373#endif-
1374-
1375/*!-
1376 \fn DataPtr &QIcon::data_ptr()-
1377 \internal-
1378*/-
1379-
1380/*!-
1381 \typedef QIcon::DataPtr-
1382 \internal-
1383*/-
1384-
1385/*!-
1386 \internal-
1387 \since 5.6-
1388 Attempts to find a suitable @Nx file for the given \a targetDevicePixelRatio-
1389 Returns the the \a baseFileName if no such file was found.-
1390-
1391 Given base foo.png and a target dpr of 2.5, this function will look for-
1392 foo@3x.png, then foo@2x, then fall back to foo.png if not found.-
1393-
1394 \a sourceDevicePixelRatio will be set to the value of N if the argument is-
1395 a non-null pointer-
1396*/-
1397QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio,-
1398 qreal *sourceDevicePixelRatio)-
1399{-
1400 if (targetDevicePixelRatio <= 1.0)
targetDevicePixelRatio <= 1.0Description
TRUEnever evaluated
FALSEnever evaluated
0
1401 return baseFileName;
never executed: return baseFileName;
0
1402-
1403 static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");-
1404 if (disableNxImageLoading)
disableNxImageLoadingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1405 return baseFileName;
never executed: return baseFileName;
0
1406-
1407 int dotIndex = baseFileName.lastIndexOf(QLatin1Char('.'));-
1408 if (dotIndex == -1) /* no dot */
dotIndex == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1409 dotIndex = baseFileName.size(); /* append */
never executed: dotIndex = baseFileName.size();
0
1410-
1411 QString atNxfileName = baseFileName;-
1412 atNxfileName.insert(dotIndex, QLatin1String("@2x"));-
1413 // Check for @Nx, ..., @3x, @2x file versions,-
1414 for (int n = qMin(qCeil(targetDevicePixelRatio), 9); n > 1; --n) {
n > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1415 atNxfileName[dotIndex + 1] = QLatin1Char('0' + n);-
1416 if (QFile::exists(atNxfileName)) {
QFile::exists(atNxfileName)Description
TRUEnever evaluated
FALSEnever evaluated
0
1417 if (sourceDevicePixelRatio)
sourceDevicePixelRatioDescription
TRUEnever evaluated
FALSEnever evaluated
0
1418 *sourceDevicePixelRatio = n;
never executed: *sourceDevicePixelRatio = n;
0
1419 return atNxfileName;
never executed: return atNxfileName;
0
1420 }-
1421 }
never executed: end of block
0
1422-
1423 return baseFileName;
never executed: return baseFileName;
0
1424}-
1425-
1426QT_END_NAMESPACE-
1427#endif //QT_NO_ICON-
Source codeSwitch to Preprocessed file

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