Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/image/qicon.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | static QBasicAtomicInt serialNumCounter = { 1 }; | - | ||||||||||||||||||
6 | - | |||||||||||||||||||
7 | static void qt_cleanup_icon_cache(); | - | ||||||||||||||||||
8 | namespace { | - | ||||||||||||||||||
9 | struct IconCache : public QCache<QString, QIcon> | - | ||||||||||||||||||
10 | { | - | ||||||||||||||||||
11 | IconCache() | - | ||||||||||||||||||
12 | { | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | qAddPostRoutine(qt_cleanup_icon_cache); | - | ||||||||||||||||||
15 | } | - | ||||||||||||||||||
16 | }; | - | ||||||||||||||||||
17 | } | - | ||||||||||||||||||
18 | - | |||||||||||||||||||
19 | namespace { namespace Q_QGS_qtIconCache { typedef IconCache Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<IconCache, Q_QGS_qtIconCache::innerFunction, Q_QGS_qtIconCache::guard> qtIconCache; | - | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | static void qt_cleanup_icon_cache() | - | ||||||||||||||||||
22 | { | - | ||||||||||||||||||
23 | qtIconCache()->clear(); | - | ||||||||||||||||||
24 | } | - | ||||||||||||||||||
25 | static qreal qt_effective_device_pixel_ratio(QWindow *window = 0) | - | ||||||||||||||||||
26 | { | - | ||||||||||||||||||
27 | if (!(static_cast<QGuiApplication *>(QCoreApplication::instance()))->testAttribute(Qt::AA_UseHighDpiPixmaps)) | - | ||||||||||||||||||
28 | return qreal(1.0); | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | if (window) | - | ||||||||||||||||||
31 | return window->devicePixelRatio(); | - | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | return (static_cast<QGuiApplication *>(QCoreApplication::instance()))->devicePixelRatio(); | - | ||||||||||||||||||
34 | } | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | QIconPrivate::QIconPrivate() | - | ||||||||||||||||||
37 | : engine(0), ref(1), | - | ||||||||||||||||||
38 | serialNum(serialNumCounter.fetchAndAddRelaxed(1)), | - | ||||||||||||||||||
39 | detach_no(0), | - | ||||||||||||||||||
40 | is_mask(false) | - | ||||||||||||||||||
41 | { | - | ||||||||||||||||||
42 | } | - | ||||||||||||||||||
43 | qreal QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize) | - | ||||||||||||||||||
44 | { | - | ||||||||||||||||||
45 | QSize targetSize = requestedSize * displayDevicePixelRatio; | - | ||||||||||||||||||
46 | qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) + | - | ||||||||||||||||||
47 | qreal(actualSize.height() / qreal(targetSize.height()))); | - | ||||||||||||||||||
48 | return qMax(qreal(1.0), displayDevicePixelRatio *scale); | - | ||||||||||||||||||
49 | } | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | QPixmapIconEngine::QPixmapIconEngine() | - | ||||||||||||||||||
52 | { | - | ||||||||||||||||||
53 | } | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | QPixmapIconEngine::QPixmapIconEngine(const QPixmapIconEngine &other) | - | ||||||||||||||||||
56 | : QIconEngine(other), pixmaps(other.pixmaps) | - | ||||||||||||||||||
57 | { | - | ||||||||||||||||||
58 | } | - | ||||||||||||||||||
59 | - | |||||||||||||||||||
60 | QPixmapIconEngine::~QPixmapIconEngine() | - | ||||||||||||||||||
61 | { | - | ||||||||||||||||||
62 | } | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | QSize pixmapSize = rect.size() * qt_effective_device_pixel_ratio(0); | - | ||||||||||||||||||
67 | QPixmap px = pixmap(pixmapSize, mode, state); | - | ||||||||||||||||||
68 | painter->drawPixmap(rect, px); | - | ||||||||||||||||||
69 | } | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | static inline int area(const QSize &s) { return s.width() * s.height(); } | - | ||||||||||||||||||
72 | - | |||||||||||||||||||
73 | - | |||||||||||||||||||
74 | static QPixmapIconEngineEntry *bestSizeMatch( const QSize &size, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb) | - | ||||||||||||||||||
75 | { | - | ||||||||||||||||||
76 | int s = area(size); | - | ||||||||||||||||||
77 | if (pa->size == QSize() && pa->pixmap.isNull()) { | - | ||||||||||||||||||
78 | pa->pixmap = QPixmap(pa->fileName); | - | ||||||||||||||||||
79 | pa->size = pa->pixmap.size(); | - | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | int a = area(pa->size); | - | ||||||||||||||||||
82 | if (pb->size == QSize() && pb->pixmap.isNull()) { | - | ||||||||||||||||||
83 | pb->pixmap = QPixmap(pb->fileName); | - | ||||||||||||||||||
84 | pb->size = pb->pixmap.size(); | - | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | int b = area(pb->size); | - | ||||||||||||||||||
87 | int res = a; | - | ||||||||||||||||||
88 | if (qMin(a,b) >= s) | - | ||||||||||||||||||
89 | res = qMin(a,b); | - | ||||||||||||||||||
90 | else | - | ||||||||||||||||||
91 | res = qMax(a,b); | - | ||||||||||||||||||
92 | if (res == a) | - | ||||||||||||||||||
93 | return pa; | - | ||||||||||||||||||
94 | return pb; | - | ||||||||||||||||||
95 | } | - | ||||||||||||||||||
96 | - | |||||||||||||||||||
97 | QPixmapIconEngineEntry *QPixmapIconEngine::tryMatch(const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
98 | { | - | ||||||||||||||||||
99 | QPixmapIconEngineEntry *pe = 0; | - | ||||||||||||||||||
100 | for (int i = 0; i < pixmaps.count(); ++i) | - | ||||||||||||||||||
101 | if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) { | - | ||||||||||||||||||
102 | if (pe) | - | ||||||||||||||||||
103 | pe = bestSizeMatch(size, &pixmaps[i], pe); | - | ||||||||||||||||||
104 | else | - | ||||||||||||||||||
105 | pe = &pixmaps[i]; | - | ||||||||||||||||||
106 | } | - | ||||||||||||||||||
107 | return pe; | - | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | - | |||||||||||||||||||
111 | QPixmapIconEngineEntry *QPixmapIconEngine::bestMatch(const QSize &size, QIcon::Mode mode, QIcon::State state, bool sizeOnly) | - | ||||||||||||||||||
112 | { | - | ||||||||||||||||||
113 | QPixmapIconEngineEntry *pe = tryMatch(size, mode, state); | - | ||||||||||||||||||
114 | while (!pe){ | - | ||||||||||||||||||
115 | QIcon::State oppositeState = (state == QIcon::On) ? QIcon::Off : QIcon::On; | - | ||||||||||||||||||
116 | if (mode == QIcon::Disabled || mode == QIcon::Selected) { | - | ||||||||||||||||||
117 | QIcon::Mode oppositeMode = (mode == QIcon::Disabled) ? QIcon::Selected : QIcon::Disabled; | - | ||||||||||||||||||
118 | if ((pe = tryMatch(size, QIcon::Normal, state))) | - | ||||||||||||||||||
119 | break; | - | ||||||||||||||||||
120 | if ((pe = tryMatch(size, QIcon::Active, state))) | - | ||||||||||||||||||
121 | break; | - | ||||||||||||||||||
122 | if ((pe = tryMatch(size, mode, oppositeState))) | - | ||||||||||||||||||
123 | break; | - | ||||||||||||||||||
124 | if ((pe = tryMatch(size, QIcon::Normal, oppositeState))) | - | ||||||||||||||||||
125 | break; | - | ||||||||||||||||||
126 | if ((pe = tryMatch(size, QIcon::Active, oppositeState))) | - | ||||||||||||||||||
127 | break; | - | ||||||||||||||||||
128 | if ((pe = tryMatch(size, oppositeMode, state))) | - | ||||||||||||||||||
129 | break; | - | ||||||||||||||||||
130 | if ((pe = tryMatch(size, oppositeMode, oppositeState))) | - | ||||||||||||||||||
131 | break; | - | ||||||||||||||||||
132 | } else { | - | ||||||||||||||||||
133 | QIcon::Mode oppositeMode = (mode == QIcon::Normal) ? QIcon::Active : QIcon::Normal; | - | ||||||||||||||||||
134 | if ((pe = tryMatch(size, oppositeMode, state))) | - | ||||||||||||||||||
135 | break; | - | ||||||||||||||||||
136 | if ((pe = tryMatch(size, mode, oppositeState))) | - | ||||||||||||||||||
137 | break; | - | ||||||||||||||||||
138 | if ((pe = tryMatch(size, oppositeMode, oppositeState))) | - | ||||||||||||||||||
139 | break; | - | ||||||||||||||||||
140 | if ((pe = tryMatch(size, QIcon::Disabled, state))) | - | ||||||||||||||||||
141 | break; | - | ||||||||||||||||||
142 | if ((pe = tryMatch(size, QIcon::Selected, state))) | - | ||||||||||||||||||
143 | break; | - | ||||||||||||||||||
144 | if ((pe = tryMatch(size, QIcon::Disabled, oppositeState))) | - | ||||||||||||||||||
145 | break; | - | ||||||||||||||||||
146 | if ((pe = tryMatch(size, QIcon::Selected, oppositeState))) | - | ||||||||||||||||||
147 | break; | - | ||||||||||||||||||
148 | } | - | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | if (!pe) | - | ||||||||||||||||||
151 | return pe; | - | ||||||||||||||||||
152 | } | - | ||||||||||||||||||
153 | - | |||||||||||||||||||
154 | if (sizeOnly ? (pe->size.isNull() || !pe->size.isValid()) : pe->pixmap.isNull()) { | - | ||||||||||||||||||
155 | pe->pixmap = QPixmap(pe->fileName); | - | ||||||||||||||||||
156 | if (!pe->pixmap.isNull()) | - | ||||||||||||||||||
157 | pe->size = pe->pixmap.size(); | - | ||||||||||||||||||
158 | } | - | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | return pe; | - | ||||||||||||||||||
161 | } | - | ||||||||||||||||||
162 | - | |||||||||||||||||||
163 | QPixmap QPixmapIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
164 | { | - | ||||||||||||||||||
165 | QPixmap pm; | - | ||||||||||||||||||
166 | QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, false); | - | ||||||||||||||||||
167 | if (pe
| 0 | ||||||||||||||||||
168 | pm = pe->pixmap; never executed: pm = pe->pixmap; | 0 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | if (pm.isNull()
| 0 | ||||||||||||||||||
171 | int idx = pixmaps.count(); | - | ||||||||||||||||||
172 | while (--
| 0 | ||||||||||||||||||
173 | if (pe == &pixmaps[.at(idx]))
| 0 | ||||||||||||||||||
174 | pixmaps.remove(idx); | - | ||||||||||||||||||
175 | break; never executed: break; | 0 | ||||||||||||||||||
176 | } | - | ||||||||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||||||||
178 | if (pixmaps.isEmpty()
| 0 | ||||||||||||||||||
179 | return never executed: pm;return pm; never executed: return pm; | 0 | ||||||||||||||||||
180 | else | - | ||||||||||||||||||
181 | return never executed: pixmap(size, mode, state);return pixmap(size, mode, state); never executed: return pixmap(size, mode, state); | 0 | ||||||||||||||||||
182 | } | - | ||||||||||||||||||
183 | - | |||||||||||||||||||
184 | QSize actualSize = pm.size(); | - | ||||||||||||||||||
185 | if (!actualSize.isNull()
| 0 | ||||||||||||||||||
186 | actualSize.scale(size, Qt::KeepAspectRatio); never executed: actualSize.scale(size, Qt::KeepAspectRatio); | 0 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | QString key = QLatin1String("qt_") | - | ||||||||||||||||||
189 | % HexString<quint64>(pm.cacheKey()) | - | ||||||||||||||||||
190 | % HexString<uint>(pe ? pe->mode : QIcon::Normal) | - | ||||||||||||||||||
191 | % HexString<quint64>(QGuiApplication::palette().cacheKey()) | - | ||||||||||||||||||
192 | % HexString<uint>(actualSize.width()) | - | ||||||||||||||||||
193 | % HexString<uint>(actualSize.height()); | - | ||||||||||||||||||
194 | - | |||||||||||||||||||
195 | if (mode == QIcon::Active
| 0 | ||||||||||||||||||
196 | if (QPixmapCache::find(key % HexString<uint>(mode), pm)
| 0 | ||||||||||||||||||
197 | return never executed: pm;return pm; never executed: return pm; | 0 | ||||||||||||||||||
198 | if (QPixmapCache::find(key % HexString<uint>(QIcon::Normal), pm)
| 0 | ||||||||||||||||||
199 | QPixmap active = pm; | - | ||||||||||||||||||
200 | if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>((static_cast<QGuiApplication *>(QCoreApplication::instance())))
| 0 | ||||||||||||||||||
201 | 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 | ||||||||||||||||||
202 | if (pm.cacheKey() == active.cacheKey()
| 0 | ||||||||||||||||||
203 | return never executed: pm;return pm; never executed: return pm; | 0 | ||||||||||||||||||
204 | } never executed: end of block | 0 | ||||||||||||||||||
205 | } never executed: end of block | 0 | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | if (!QPixmapCache::find(key % HexString<uint>(mode), pm)
| 0 | ||||||||||||||||||
208 | if (pm.size() != actualSize
| 0 | ||||||||||||||||||
209 | pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); never executed: pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); | 0 | ||||||||||||||||||
210 | if (pe->mode != mode
| 0 | ||||||||||||||||||
211 | QPixmap generated = pm; | - | ||||||||||||||||||
212 | if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>((static_cast<QGuiApplication *>(QCoreApplication::instance())))
| 0 | ||||||||||||||||||
213 | generated = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm); never executed: generated = static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm); | 0 | ||||||||||||||||||
214 | if (!generated.isNull()
| 0 | ||||||||||||||||||
215 | pm = generated; never executed: pm = generated; | 0 | ||||||||||||||||||
216 | } never executed: end of block | 0 | ||||||||||||||||||
217 | QPixmapCache::insert(key % HexString<uint>(mode), pm); | - | ||||||||||||||||||
218 | } never executed: end of block | 0 | ||||||||||||||||||
219 | return never executed: pm;return pm; never executed: return pm; | 0 | ||||||||||||||||||
220 | } | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | QSize QPixmapIconEngine::actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
223 | { | - | ||||||||||||||||||
224 | QSize actualSize; | - | ||||||||||||||||||
225 | if (QPixmapIconEngineEntry *pe = bestMatch(size, mode, state, true)) | - | ||||||||||||||||||
226 | actualSize = pe->size; | - | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | if (actualSize.isNull()) | - | ||||||||||||||||||
229 | return actualSize; | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | if (!actualSize.isNull() && (actualSize.width() > size.width() || actualSize.height() > size.height())) | - | ||||||||||||||||||
232 | actualSize.scale(size, Qt::KeepAspectRatio); | - | ||||||||||||||||||
233 | return actualSize; | - | ||||||||||||||||||
234 | } | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | void QPixmapIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
237 | { | - | ||||||||||||||||||
238 | if (!pixmap.isNull()) { | - | ||||||||||||||||||
239 | QPixmapIconEngineEntry *pe = tryMatch(pixmap.size(), mode, state); | - | ||||||||||||||||||
240 | if(pe && pe->size == pixmap.size()) { | - | ||||||||||||||||||
241 | pe->pixmap = pixmap; | - | ||||||||||||||||||
242 | pe->fileName.clear(); | - | ||||||||||||||||||
243 | } else { | - | ||||||||||||||||||
244 | pixmaps += QPixmapIconEngineEntry(pixmap, mode, state); | - | ||||||||||||||||||
245 | } | - | ||||||||||||||||||
246 | } | - | ||||||||||||||||||
247 | } | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | - | |||||||||||||||||||
250 | static inline int origIcoDepth(const QImage &image) | - | ||||||||||||||||||
251 | { | - | ||||||||||||||||||
252 | const QString s = image.text(([]() -> QString { enum { Size = sizeof(u"" "_q_icoOrigDepth")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "_q_icoOrigDepth" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }())); | - | ||||||||||||||||||
253 | return s.isEmpty() ? 32 : s.toInt(); | - | ||||||||||||||||||
254 | } | - | ||||||||||||||||||
255 | - | |||||||||||||||||||
256 | static inline int findBySize(const QVector<QImage> &images, const QSize &size) | - | ||||||||||||||||||
257 | { | - | ||||||||||||||||||
258 | for (int i = 0; i < images.size(); ++i) { | - | ||||||||||||||||||
259 | if (images.at(i).size() == size) | - | ||||||||||||||||||
260 | return i; | - | ||||||||||||||||||
261 | } | - | ||||||||||||||||||
262 | return -1; | - | ||||||||||||||||||
263 | } | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | - | |||||||||||||||||||
266 | namespace { | - | ||||||||||||||||||
267 | class ImageReader | - | ||||||||||||||||||
268 | { | - | ||||||||||||||||||
269 | public: | - | ||||||||||||||||||
270 | ImageReader(const QString &fileName) : m_reader(fileName), m_atEnd(false) {} | - | ||||||||||||||||||
271 | - | |||||||||||||||||||
272 | QByteArray format() const { return m_reader.format(); } | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | bool read(QImage *image) | - | ||||||||||||||||||
275 | { | - | ||||||||||||||||||
276 | if (m_atEnd) | - | ||||||||||||||||||
277 | return false; | - | ||||||||||||||||||
278 | *image = m_reader.read(); | - | ||||||||||||||||||
279 | if (!image->size().isValid()) { | - | ||||||||||||||||||
280 | m_atEnd = true; | - | ||||||||||||||||||
281 | return false; | - | ||||||||||||||||||
282 | } | - | ||||||||||||||||||
283 | m_atEnd = !m_reader.jumpToNextImage(); | - | ||||||||||||||||||
284 | return true; | - | ||||||||||||||||||
285 | } | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | private: | - | ||||||||||||||||||
288 | QImageReader m_reader; | - | ||||||||||||||||||
289 | bool m_atEnd; | - | ||||||||||||||||||
290 | }; | - | ||||||||||||||||||
291 | } | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | void QPixmapIconEngine::addFile(const QString &fileName, const QSize &size, QIcon::Mode mode, QIcon::State state) | - | ||||||||||||||||||
294 | { | - | ||||||||||||||||||
295 | if (fileName.isEmpty()
| 0 | ||||||||||||||||||
296 | return; never executed: return; | 0 | ||||||||||||||||||
297 | const QString abs = fileName.startsWith(QLatin1Char(':'))
| 0 | ||||||||||||||||||
298 | const bool ignoreSize = !size.isValid(); | - | ||||||||||||||||||
299 | ImageReader imageReader(abs); | - | ||||||||||||||||||
300 | const QByteArray format = imageReader.format(); | - | ||||||||||||||||||
301 | if (format.isEmpty()
| 0 | ||||||||||||||||||
302 | return; never executed: return; | 0 | ||||||||||||||||||
303 | QImage image; | - | ||||||||||||||||||
304 | if (format != "ico"
| 0 | ||||||||||||||||||
305 | if (ignoreSize
| 0 | ||||||||||||||||||
306 | while (imageReader.read(&image)
| 0 | ||||||||||||||||||
307 | pixmaps += QPixmapIconEngineEntry(abs, image, mode, state); never executed: pixmaps += QPixmapIconEngineEntry(abs, image, mode, state); | 0 | ||||||||||||||||||
308 | } never executed: else {end of block | 0 | ||||||||||||||||||
309 | - | |||||||||||||||||||
310 | while (imageReader.read(&image)
never executed: end of block | 0 | ||||||||||||||||||
311 | pixmaps += image.size() == size
| 0 | ||||||||||||||||||
312 | QPixmapIconEngineEntry(abs, image, mode, state) : QPixmapIconEngineEntry(abs, size, mode, state); | - | ||||||||||||||||||
313 | } never executed: end of block | 0 | ||||||||||||||||||
314 | return; never executed: return; | 0 | ||||||||||||||||||
315 | } | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | - | |||||||||||||||||||
318 | - | |||||||||||||||||||
319 | - | |||||||||||||||||||
320 | QVector<QImage> icoImages; | - | ||||||||||||||||||
321 | while (imageReader.read(&image)
| 0 | ||||||||||||||||||
322 | if (ignoreSize
| 0 | ||||||||||||||||||
323 | const int position = findBySize(icoImages, image.size()); | - | ||||||||||||||||||
324 | if (position >= 0
| 0 | ||||||||||||||||||
325 | if (origIcoDepth(image) > origIcoDepth(icoImages.at(position))
| 0 | ||||||||||||||||||
326 | icoImages[position] = image; never executed: icoImages[position] = image; | 0 | ||||||||||||||||||
327 | } never executed: else {end of block | 0 | ||||||||||||||||||
328 | icoImages.append(image); | - | ||||||||||||||||||
329 | } never executed: end of block | 0 | ||||||||||||||||||
330 | } | - | ||||||||||||||||||
331 | } never executed: end of block | 0 | ||||||||||||||||||
332 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(icoImages)>::type> _container_((icoImages)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1)for (const QImage &i = *_container_.i; _container_.control; _container_.control = 0): qAsConst(icoImages)) | - | ||||||||||||||||||
333 | pixmaps += QPixmapIconEngineEntry(abs, i, mode, state); never executed: pixmaps += QPixmapIconEngineEntry(abs, i, mode, state); | 0 | ||||||||||||||||||
334 | if (icoImages.isEmpty()
| 0 | ||||||||||||||||||
335 | pixmaps += QPixmapIconEngineEntry(abs, size, mode, state); never executed: pixmaps += QPixmapIconEngineEntry(abs, size, mode, state); | 0 | ||||||||||||||||||
336 | } never executed: end of block | 0 | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | QString QPixmapIconEngine::key() const | - | ||||||||||||||||||
339 | { | - | ||||||||||||||||||
340 | return QLatin1String("QPixmapIconEngine"); | - | ||||||||||||||||||
341 | } | - | ||||||||||||||||||
342 | - | |||||||||||||||||||
343 | QIconEngine *QPixmapIconEngine::clone() const | - | ||||||||||||||||||
344 | { | - | ||||||||||||||||||
345 | return new QPixmapIconEngine(*this); | - | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | bool QPixmapIconEngine::read(QDataStream &in) | - | ||||||||||||||||||
349 | { | - | ||||||||||||||||||
350 | int num_entries; | - | ||||||||||||||||||
351 | QPixmap pm; | - | ||||||||||||||||||
352 | QString fileName; | - | ||||||||||||||||||
353 | QSize sz; | - | ||||||||||||||||||
354 | uint mode; | - | ||||||||||||||||||
355 | uint state; | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | in >> num_entries; | - | ||||||||||||||||||
358 | for (int i=0; i < num_entries; ++i) { | - | ||||||||||||||||||
359 | if (in.atEnd()) { | - | ||||||||||||||||||
360 | pixmaps.clear(); | - | ||||||||||||||||||
361 | return false; | - | ||||||||||||||||||
362 | } | - | ||||||||||||||||||
363 | in >> pm; | - | ||||||||||||||||||
364 | in >> fileName; | - | ||||||||||||||||||
365 | in >> sz; | - | ||||||||||||||||||
366 | in >> mode; | - | ||||||||||||||||||
367 | in >> state; | - | ||||||||||||||||||
368 | if (pm.isNull()) { | - | ||||||||||||||||||
369 | addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); | - | ||||||||||||||||||
370 | } else { | - | ||||||||||||||||||
371 | QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); | - | ||||||||||||||||||
372 | pe.pixmap = pm; | - | ||||||||||||||||||
373 | pixmaps += pe; | - | ||||||||||||||||||
374 | } | - | ||||||||||||||||||
375 | } | - | ||||||||||||||||||
376 | return true; | - | ||||||||||||||||||
377 | } | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | bool QPixmapIconEngine::write(QDataStream &out) const | - | ||||||||||||||||||
380 | { | - | ||||||||||||||||||
381 | int num_entries = pixmaps.size(); | - | ||||||||||||||||||
382 | out << num_entries; | - | ||||||||||||||||||
383 | for (int i=0; i < num_entries; ++i) { | - | ||||||||||||||||||
384 | if (pixmaps.at(i).pixmap.isNull()) | - | ||||||||||||||||||
385 | out << QPixmap(pixmaps.at(i).fileName); | - | ||||||||||||||||||
386 | else | - | ||||||||||||||||||
387 | out << pixmaps.at(i).pixmap; | - | ||||||||||||||||||
388 | out << pixmaps.at(i).fileName; | - | ||||||||||||||||||
389 | out << pixmaps.at(i).size; | - | ||||||||||||||||||
390 | out << (uint) pixmaps.at(i).mode; | - | ||||||||||||||||||
391 | out << (uint) pixmaps.at(i).state; | - | ||||||||||||||||||
392 | } | - | ||||||||||||||||||
393 | return true; | - | ||||||||||||||||||
394 | } | - | ||||||||||||||||||
395 | - | |||||||||||||||||||
396 | void QPixmapIconEngine::virtual_hook(int id, void *data) | - | ||||||||||||||||||
397 | { | - | ||||||||||||||||||
398 | switch (id) { | - | ||||||||||||||||||
399 | case QIconEngine::AvailableSizesHook: { | - | ||||||||||||||||||
400 | QIconEngine::AvailableSizesArgument &arg = | - | ||||||||||||||||||
401 | *reinterpret_cast<QIconEngine::AvailableSizesArgument*>(data); | - | ||||||||||||||||||
402 | arg.sizes.clear(); | - | ||||||||||||||||||
403 | for (int i = 0; i < pixmaps.size(); ++i) { | - | ||||||||||||||||||
404 | QPixmapIconEngineEntry &pe = pixmaps[i]; | - | ||||||||||||||||||
405 | if (pe.size == QSize() && pe.pixmap.isNull()) { | - | ||||||||||||||||||
406 | pe.pixmap = QPixmap(pe.fileName); | - | ||||||||||||||||||
407 | pe.size = pe.pixmap.size(); | - | ||||||||||||||||||
408 | } | - | ||||||||||||||||||
409 | if (pe.mode == arg.mode && pe.state == arg.state && !pe.size.isEmpty()) | - | ||||||||||||||||||
410 | arg.sizes.push_back(pe.size); | - | ||||||||||||||||||
411 | } | - | ||||||||||||||||||
412 | break; | - | ||||||||||||||||||
413 | } | - | ||||||||||||||||||
414 | default: | - | ||||||||||||||||||
415 | QIconEngine::virtual_hook(id, data); | - | ||||||||||||||||||
416 | } | - | ||||||||||||||||||
417 | } | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | namespace { namespace Q_QGS_loader { typedef QFactoryLoader Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ("org.qt-project.Qt.QIconEngineFactoryInterface", QLatin1String("/iconengines"), Qt::CaseInsensitive))) : value ("org.qt-project.Qt.QIconEngineFactoryInterface", QLatin1String("/iconengines"), Qt::CaseInsensitive) { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QFactoryLoader, Q_QGS_loader::innerFunction, Q_QGS_loader::guard> loader; | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | - | |||||||||||||||||||
422 | QFactoryLoader *qt_iconEngineFactoryLoader() | - | ||||||||||||||||||
423 | { | - | ||||||||||||||||||
424 | return loader(); | - | ||||||||||||||||||
425 | } | - | ||||||||||||||||||
426 | QIcon::QIcon() noexcept | - | ||||||||||||||||||
427 | : d(0) | - | ||||||||||||||||||
428 | { | - | ||||||||||||||||||
429 | } never executed: end of block | 0 | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | - | |||||||||||||||||||
432 | - | |||||||||||||||||||
433 | - | |||||||||||||||||||
434 | QIcon::QIcon(const QPixmap &pixmap) | - | ||||||||||||||||||
435 | :d(0) | - | ||||||||||||||||||
436 | { | - | ||||||||||||||||||
437 | addPixmap(pixmap); | - | ||||||||||||||||||
438 | } | - | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | - | |||||||||||||||||||
441 | - | |||||||||||||||||||
442 | - | |||||||||||||||||||
443 | QIcon::QIcon(const QIcon &other) | - | ||||||||||||||||||
444 | :d(other.d) | - | ||||||||||||||||||
445 | { | - | ||||||||||||||||||
446 | if (d) | - | ||||||||||||||||||
447 | d->ref.ref(); | - | ||||||||||||||||||
448 | } | - | ||||||||||||||||||
449 | QIcon::QIcon(const QString &fileName) | - | ||||||||||||||||||
450 | : d(0) | - | ||||||||||||||||||
451 | { | - | ||||||||||||||||||
452 | addFile(fileName); | - | ||||||||||||||||||
453 | } | - | ||||||||||||||||||
454 | - | |||||||||||||||||||
455 | - | |||||||||||||||||||
456 | - | |||||||||||||||||||
457 | - | |||||||||||||||||||
458 | - | |||||||||||||||||||
459 | - | |||||||||||||||||||
460 | QIcon::QIcon(QIconEngine *engine) | - | ||||||||||||||||||
461 | :d(new QIconPrivate) | - | ||||||||||||||||||
462 | { | - | ||||||||||||||||||
463 | d->engine = engine; | - | ||||||||||||||||||
464 | } | - | ||||||||||||||||||
465 | - | |||||||||||||||||||
466 | - | |||||||||||||||||||
467 | - | |||||||||||||||||||
468 | - | |||||||||||||||||||
469 | QIcon::~QIcon() | - | ||||||||||||||||||
470 | { | - | ||||||||||||||||||
471 | if (d && !d->ref.deref()) | - | ||||||||||||||||||
472 | delete d; | - | ||||||||||||||||||
473 | } | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | - | |||||||||||||||||||
476 | - | |||||||||||||||||||
477 | - | |||||||||||||||||||
478 | - | |||||||||||||||||||
479 | QIcon &QIcon::operator=(const QIcon &other) | - | ||||||||||||||||||
480 | { | - | ||||||||||||||||||
481 | if (other.d) | - | ||||||||||||||||||
482 | other.d->ref.ref(); | - | ||||||||||||||||||
483 | if (d && !d->ref.deref()) | - | ||||||||||||||||||
484 | delete d; | - | ||||||||||||||||||
485 | d = other.d; | - | ||||||||||||||||||
486 | return *this; | - | ||||||||||||||||||
487 | } | - | ||||||||||||||||||
488 | QIcon::operator QVariant() const | - | ||||||||||||||||||
489 | { | - | ||||||||||||||||||
490 | return QVariant(QVariant::Icon, this); | - | ||||||||||||||||||
491 | } | - | ||||||||||||||||||
492 | qint64 QIcon::cacheKey() const | - | ||||||||||||||||||
493 | { | - | ||||||||||||||||||
494 | if (!d) | - | ||||||||||||||||||
495 | return 0; | - | ||||||||||||||||||
496 | return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no)); | - | ||||||||||||||||||
497 | } | - | ||||||||||||||||||
498 | QPixmap QIcon::pixmap(const QSize &size, Mode mode, State state) const | - | ||||||||||||||||||
499 | { | - | ||||||||||||||||||
500 | if (!d) | - | ||||||||||||||||||
501 | return QPixmap(); | - | ||||||||||||||||||
502 | return pixmap(0, size, mode, state); | - | ||||||||||||||||||
503 | } | - | ||||||||||||||||||
504 | QSize QIcon::actualSize(const QSize &size, Mode mode, State state) const | - | ||||||||||||||||||
505 | { | - | ||||||||||||||||||
506 | if (!d) | - | ||||||||||||||||||
507 | return QSize(); | - | ||||||||||||||||||
508 | return actualSize(0, size, mode, state); | - | ||||||||||||||||||
509 | } | - | ||||||||||||||||||
510 | QPixmap QIcon::pixmap(QWindow *window, const QSize &size, Mode mode, State state) const | - | ||||||||||||||||||
511 | { | - | ||||||||||||||||||
512 | if (!d) | - | ||||||||||||||||||
513 | return QPixmap(); | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | qreal devicePixelRatio = qt_effective_device_pixel_ratio(window); | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | - | |||||||||||||||||||
518 | if (!(devicePixelRatio > 1.0)) { | - | ||||||||||||||||||
519 | QPixmap pixmap = d->engine->pixmap(size, mode, state); | - | ||||||||||||||||||
520 | pixmap.setDevicePixelRatio(1.0); | - | ||||||||||||||||||
521 | return pixmap; | - | ||||||||||||||||||
522 | } | - | ||||||||||||||||||
523 | - | |||||||||||||||||||
524 | - | |||||||||||||||||||
525 | QPixmap pixmap = d->engine->pixmap(size * devicePixelRatio, mode, state); | - | ||||||||||||||||||
526 | pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size())); | - | ||||||||||||||||||
527 | return pixmap; | - | ||||||||||||||||||
528 | } | - | ||||||||||||||||||
529 | QSize QIcon::actualSize(QWindow *window, const QSize &size, Mode mode, State state) const | - | ||||||||||||||||||
530 | { | - | ||||||||||||||||||
531 | if (!d) | - | ||||||||||||||||||
532 | return QSize(); | - | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | qreal devicePixelRatio = qt_effective_device_pixel_ratio(window); | - | ||||||||||||||||||
535 | - | |||||||||||||||||||
536 | - | |||||||||||||||||||
537 | if (!(devicePixelRatio > 1.0)) | - | ||||||||||||||||||
538 | return d->engine->actualSize(size, mode, state); | - | ||||||||||||||||||
539 | - | |||||||||||||||||||
540 | QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state); | - | ||||||||||||||||||
541 | return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize); | - | ||||||||||||||||||
542 | } | - | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | - | |||||||||||||||||||
545 | - | |||||||||||||||||||
546 | - | |||||||||||||||||||
547 | - | |||||||||||||||||||
548 | - | |||||||||||||||||||
549 | - | |||||||||||||||||||
550 | void QIcon::paint(QPainter *painter, const QRect &rect, Qt::Alignment alignment, Mode mode, State state) const | - | ||||||||||||||||||
551 | { | - | ||||||||||||||||||
552 | if (!d || !painter) | - | ||||||||||||||||||
553 | return; | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | - | |||||||||||||||||||
556 | const QSize size = d->engine->actualSize(rect.size(), mode, state); | - | ||||||||||||||||||
557 | alignment = QGuiApplicationPrivate::visualAlignment(painter->layoutDirection(), alignment); | - | ||||||||||||||||||
558 | int x = rect.x(); | - | ||||||||||||||||||
559 | int y = rect.y(); | - | ||||||||||||||||||
560 | int w = size.width(); | - | ||||||||||||||||||
561 | int h = size.height(); | - | ||||||||||||||||||
562 | if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) | - | ||||||||||||||||||
563 | y += rect.size().height()/2 - h/2; | - | ||||||||||||||||||
564 | else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom) | - | ||||||||||||||||||
565 | y += rect.size().height() - h; | - | ||||||||||||||||||
566 | if ((alignment & Qt::AlignRight) == Qt::AlignRight) | - | ||||||||||||||||||
567 | x += rect.size().width() - w; | - | ||||||||||||||||||
568 | else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter) | - | ||||||||||||||||||
569 | x += rect.size().width()/2 - w/2; | - | ||||||||||||||||||
570 | QRect alignedRect(x, y, w, h); | - | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | d->engine->paint(painter, alignedRect, mode, state); | - | ||||||||||||||||||
573 | } | - | ||||||||||||||||||
574 | bool QIcon::isNull() const | - | ||||||||||||||||||
575 | { | - | ||||||||||||||||||
576 | return never executed: !d ;|| d->engine->isNull();return !d || d->engine->isNull(); never executed: return !d || d->engine->isNull(); | 0 | ||||||||||||||||||
577 | } | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | - | |||||||||||||||||||
580 | - | |||||||||||||||||||
581 | bool QIcon::isDetached() const | - | ||||||||||||||||||
582 | { | - | ||||||||||||||||||
583 | return !d || d->ref.load() == 1; | - | ||||||||||||||||||
584 | } | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | - | |||||||||||||||||||
587 | - | |||||||||||||||||||
588 | void QIcon::detach() | - | ||||||||||||||||||
589 | { | - | ||||||||||||||||||
590 | if (d
| 0 | ||||||||||||||||||
591 | if (d->engine->isNull()
| 0 | ||||||||||||||||||
592 | if (!d->ref.deref()
| 0 | ||||||||||||||||||
593 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
594 | d = 0; | - | ||||||||||||||||||
595 | return; never executed: return; | 0 | ||||||||||||||||||
596 | } else if (d->ref.load() != 1
| 0 | ||||||||||||||||||
597 | QIconPrivate *x = new QIconPrivate; | - | ||||||||||||||||||
598 | x->engine = d->engine->clone(); | - | ||||||||||||||||||
599 | if (!d->ref.deref()
| 0 | ||||||||||||||||||
600 | delete d; never executed: delete d; | 0 | ||||||||||||||||||
601 | d = x; | - | ||||||||||||||||||
602 | } never executed: end of block | 0 | ||||||||||||||||||
603 | ++d->detach_no; | - | ||||||||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||||||||
605 | } never executed: end of block | 0 | ||||||||||||||||||
606 | void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state) | - | ||||||||||||||||||
607 | { | - | ||||||||||||||||||
608 | if (pixmap.isNull()
| 0 | ||||||||||||||||||
609 | return; never executed: return; | 0 | ||||||||||||||||||
610 | detach(); | - | ||||||||||||||||||
611 | if (!d
| 0 | ||||||||||||||||||
612 | d = new QIconPrivate; | - | ||||||||||||||||||
613 | d->engine = new QPixmapIconEngine; | - | ||||||||||||||||||
614 | } else { | 0 | ||||||||||||||||||
detach();} never executed: end of block | ||||||||||||||||||||
615 | d->engine->addPixmap(pixmap, mode, state); | - | ||||||||||||||||||
616 | } never executed: end of block | 0 | ||||||||||||||||||
617 | - | |||||||||||||||||||
void QIcon::addFilestatic QIconEngine *iconEngineFromSuffix(const QString &fileName, const QSize &size, Mode mode, State state) | ||||||||||||||||||||
{ | ||||||||||||||||||||
if (fileName.isEmpty()) | ||||||||||||||||||||
return; | ||||||||||||||||||||
if (!dQString &suffix) | ||||||||||||||||||||
619 | { | - | ||||||||||||||||||
620 | QFileInfo info(fileName); | 0 | ||||||||||||||||||
QString suffix = info.suffix();if (!suffix.isEmpty()
| ||||||||||||||||||||
621 | const int index = loader()->indexOf(suffix); | - | ||||||||||||||||||
622 | if (index != -1
| 0 | ||||||||||||||||||
623 | if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))
| 0 | ||||||||||||||||||
624 | if (QIconEngine *engine =return never executed: return factory->create(fileName); never executed: factory->create(fileName)) {return factory->create(fileName); never executed: return factory->create(fileName); | 0 | ||||||||||||||||||
d = new QIconPrivate; never executed: return factory->create(fileName); | ||||||||||||||||||||
d->engine = engine; never executed: return factory->create(fileName); never executed: );return factory->create(fileName); never executed: return factory->create(fileName); | ||||||||||||||||||||
625 | } | - | ||||||||||||||||||
626 | } never executed: end of block | 0 | ||||||||||||||||||
627 | } never executed: end of block | 0 | ||||||||||||||||||
628 | return never executed: return nullptr; never executed: nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||||||||
629 | } | - | ||||||||||||||||||
630 | void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State state) | - | ||||||||||||||||||
631 | { | - | ||||||||||||||||||
632 | if (fileName.isEmpty()
| 0 | ||||||||||||||||||
633 | return; never executed: return; | 0 | ||||||||||||||||||
634 | detach(); | - | ||||||||||||||||||
635 | if (!d
| 0 | ||||||||||||||||||
636 | - | |||||||||||||||||||
637 | QFileInfo info(fileName); | - | ||||||||||||||||||
638 | QIconEngine *engine = iconEngineFromSuffix(fileName, info.suffix()); | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | if (!engine
| 0 | ||||||||||||||||||
641 | engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix()); never executed: engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix()); | 0 | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | d = new QIconPrivate; | - | ||||||||||||||||||
644 | d->engine = engine
| 0 | ||||||||||||||||||
645 | } | 0 | ||||||||||||||||||
} else { | ||||||||||||||||||||
detach();} never executed: end of block | ||||||||||||||||||||
646 | - | |||||||||||||||||||
647 | d->engine->addFile(fileName, size, mode, state); | - | ||||||||||||||||||
648 | - | |||||||||||||||||||
649 | - | |||||||||||||||||||
650 | QString atNxFileName = qt_findAtNxFile(fileName, (static_cast<QGuiApplication *>(QCoreApplication::instance()))->devicePixelRatio()); | - | ||||||||||||||||||
651 | if (atNxFileName != fileName
| 0 | ||||||||||||||||||
652 | d->engine->addFile(atNxFileName, size, mode, state); never executed: d->engine->addFile(atNxFileName, size, mode, state); | 0 | ||||||||||||||||||
653 | } never executed: end of block | 0 | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | - | |||||||||||||||||||
656 | - | |||||||||||||||||||
657 | - | |||||||||||||||||||
658 | - | |||||||||||||||||||
659 | - | |||||||||||||||||||
660 | - | |||||||||||||||||||
661 | QList<QSize> QIcon::availableSizes(Mode mode, State state) const | - | ||||||||||||||||||
662 | { | - | ||||||||||||||||||
663 | if (!d || !d->engine) | - | ||||||||||||||||||
664 | return QList<QSize>(); | - | ||||||||||||||||||
665 | return d->engine->availableSizes(mode, state); | - | ||||||||||||||||||
666 | } | - | ||||||||||||||||||
667 | QString QIcon::name() const | - | ||||||||||||||||||
668 | { | - | ||||||||||||||||||
669 | if (!d || !d->engine) | - | ||||||||||||||||||
670 | return QString(); | - | ||||||||||||||||||
671 | return d->engine->iconName(); | - | ||||||||||||||||||
672 | } | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | - | |||||||||||||||||||
675 | - | |||||||||||||||||||
676 | - | |||||||||||||||||||
677 | - | |||||||||||||||||||
678 | - | |||||||||||||||||||
679 | - | |||||||||||||||||||
680 | void QIcon::setThemeSearchPaths(const QStringList &paths) | - | ||||||||||||||||||
681 | { | - | ||||||||||||||||||
682 | QIconLoader::instance()->setThemeSearchPath(paths); | - | ||||||||||||||||||
683 | } | - | ||||||||||||||||||
684 | QStringList QIcon::themeSearchPaths() | - | ||||||||||||||||||
685 | { | - | ||||||||||||||||||
686 | return QIconLoader::instance()->themeSearchPaths(); | - | ||||||||||||||||||
687 | } | - | ||||||||||||||||||
688 | void QIcon::setThemeName(const QString &name) | - | ||||||||||||||||||
689 | { | - | ||||||||||||||||||
690 | QIconLoader::instance()->setThemeName(name); | - | ||||||||||||||||||
691 | } | - | ||||||||||||||||||
692 | QString QIcon::themeName() | - | ||||||||||||||||||
693 | { | - | ||||||||||||||||||
694 | return QIconLoader::instance()->themeName(); | - | ||||||||||||||||||
695 | } | - | ||||||||||||||||||
696 | QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) | - | ||||||||||||||||||
697 | { | - | ||||||||||||||||||
698 | QIcon icon; | - | ||||||||||||||||||
699 | - | |||||||||||||||||||
700 | if (qtIconCache()->contains(name)
| 0 | ||||||||||||||||||
701 | icon = *qtIconCache()->object(name); | - | ||||||||||||||||||
702 | } never executed: else if (QDir::isAbsolutePath(name)end of block
| 0 | ||||||||||||||||||
703 | return never executed: QIconreturn QIcon(name); never executed: return QIcon(name); never executed: (name);return QIcon(name); never executed: return QIcon(name); | 0 | ||||||||||||||||||
704 | } else { | - | ||||||||||||||||||
705 | QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); | - | ||||||||||||||||||
706 | bool hasUserTheme = QIconLoader::instance()->hasUserTheme(); | - | ||||||||||||||||||
707 | QIconEngine * const engine = (platformTheme
| 0 | ||||||||||||||||||
708 | : new QIconLoaderEngine(name); | - | ||||||||||||||||||
709 | QIcon *cachedIcon = new QIcon(engine); | - | ||||||||||||||||||
710 | icon = *cachedIcon; | - | ||||||||||||||||||
711 | qtIconCache()->insert(name, cachedIcon); | - | ||||||||||||||||||
712 | } never executed: end of block | 0 | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | if ((static_cast<QGuiApplication *>(QCoreApplicationreturn never executed: return icon; never executed: icon;return icon; never executed: return icon; | 0 | ||||||||||||||||||
715 | } | - | ||||||||||||||||||
716 | QIcon QIcon::instance())) &&fromTheme(const QString &name, const QIcon &fallback) | - | ||||||||||||||||||
717 | { | - | ||||||||||||||||||
718 | QIcon icon = fromTheme(name); | - | ||||||||||||||||||
719 | - | |||||||||||||||||||
720 | if (icon.isNull()
| 0 | ||||||||||||||||||
721 | return never executed: fallback;return fallback; never executed: return fallback; | 0 | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | return never executed: icon;return icon; never executed: return icon; | 0 | ||||||||||||||||||
724 | } | - | ||||||||||||||||||
725 | bool QIcon::hasThemeIcon(const QString &name) | - | ||||||||||||||||||
726 | { | - | ||||||||||||||||||
727 | QIcon icon = fromTheme(name); | - | ||||||||||||||||||
728 | - | |||||||||||||||||||
729 | return icon.name() == name; | - | ||||||||||||||||||
730 | } | - | ||||||||||||||||||
731 | void QIcon::setIsMask(bool isMask) | - | ||||||||||||||||||
732 | { | - | ||||||||||||||||||
733 | if (!d) { | - | ||||||||||||||||||
734 | d = new QIconPrivate; | - | ||||||||||||||||||
735 | d->engine = new QPixmapIconEngine; | - | ||||||||||||||||||
736 | } else { | - | ||||||||||||||||||
737 | detach(); | - | ||||||||||||||||||
738 | } | - | ||||||||||||||||||
739 | d->is_mask = isMask; | - | ||||||||||||||||||
740 | } | - | ||||||||||||||||||
741 | bool QIcon::isMask() const | - | ||||||||||||||||||
742 | { | - | ||||||||||||||||||
743 | if (!d) | - | ||||||||||||||||||
744 | return false; | - | ||||||||||||||||||
745 | return d->is_mask; | - | ||||||||||||||||||
746 | } | - | ||||||||||||||||||
747 | QDataStream &operator<<(QDataStream &s, const QIcon &icon) | - | ||||||||||||||||||
748 | { | - | ||||||||||||||||||
749 | if (s.version() >= QDataStream::Qt_4_3) { | - | ||||||||||||||||||
750 | if (icon.isNull()) { | - | ||||||||||||||||||
751 | s << QString(); | - | ||||||||||||||||||
752 | } else { | - | ||||||||||||||||||
753 | s << icon.d->engine->key(); | - | ||||||||||||||||||
754 | icon.d->engine->write(s); | - | ||||||||||||||||||
755 | } | - | ||||||||||||||||||
756 | } else if (s.version() == QDataStream::Qt_4_2) { | - | ||||||||||||||||||
757 | if (icon.isNull()) { | - | ||||||||||||||||||
758 | s << 0; | - | ||||||||||||||||||
759 | } else { | - | ||||||||||||||||||
760 | QPixmapIconEngine *engine = static_cast<QPixmapIconEngine *>(icon.d->engine); | - | ||||||||||||||||||
761 | int num_entries = engine->pixmaps.size(); | - | ||||||||||||||||||
762 | s << num_entries; | - | ||||||||||||||||||
763 | for (int i=0; i < num_entries; ++i) { | - | ||||||||||||||||||
764 | s << engine->pixmaps.at(i).pixmap; | - | ||||||||||||||||||
765 | s << engine->pixmaps.at(i).fileName; | - | ||||||||||||||||||
766 | s << engine->pixmaps.at(i).size; | - | ||||||||||||||||||
767 | s << (uint) engine->pixmaps.at(i).mode; | - | ||||||||||||||||||
768 | s << (uint) engine->pixmaps.at(i).state; | - | ||||||||||||||||||
769 | } | - | ||||||||||||||||||
770 | } | - | ||||||||||||||||||
771 | } else { | - | ||||||||||||||||||
772 | s << QPixmap(icon.pixmap(22,22)); | - | ||||||||||||||||||
773 | } | - | ||||||||||||||||||
774 | return s; | - | ||||||||||||||||||
775 | } | - | ||||||||||||||||||
776 | QDataStream &operator>>(QDataStream &s, QIcon &icon) | - | ||||||||||||||||||
777 | { | - | ||||||||||||||||||
778 | if (s.version() >= QDataStream::Qt_4_3
| 0 | ||||||||||||||||||
779 | icon = QIcon(); | - | ||||||||||||||||||
780 | QString key; | - | ||||||||||||||||||
781 | s >> key; | - | ||||||||||||||||||
782 | if (key == QLatin1String("QPixmapIconEngine")
| 0 | ||||||||||||||||||
783 | icon.d = new QIconPrivate; | - | ||||||||||||||||||
784 | QIconEngine *engine = new QPixmapIconEngine; | - | ||||||||||||||||||
785 | icon.d->engine = engine; | - | ||||||||||||||||||
786 | engine->read(s); | - | ||||||||||||||||||
787 | } never executed: else if (key == QLatin1String("QIconLoaderEngine")end of block
| 0 | ||||||||||||||||||
788 | icon.d = new QIconPrivate; | - | ||||||||||||||||||
789 | QIconEngine *engine = new QIconLoaderEngine(); | - | ||||||||||||||||||
790 | icon.d->engine = engine; | - | ||||||||||||||||||
791 | engine->read(s); | - | ||||||||||||||||||
792 | } never executed: else {end of block | 0 | ||||||||||||||||||
793 | const int index = loader()->indexOf(key); | - | ||||||||||||||||||
794 | if (index != -1
| 0 | ||||||||||||||||||
795 | if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))
| 0 | ||||||||||||||||||
796 | if (QIconEngine *engine= factory->create()
| 0 | ||||||||||||||||||
797 | icon.d = new QIconPrivate; | - | ||||||||||||||||||
798 | icon.d->engine = engine; | - | ||||||||||||||||||
799 | engine->read(s); | - | ||||||||||||||||||
800 | } never executed: end of block | 0 | ||||||||||||||||||
801 | } never executed: end of block | 0 | ||||||||||||||||||
802 | } never executed: end of block | 0 | ||||||||||||||||||
803 | } never executed: end of block | 0 | ||||||||||||||||||
804 | } else if (s.version() == QDataStream::Qt_4_2
| 0 | ||||||||||||||||||
805 | icon = QIcon(); | - | ||||||||||||||||||
806 | int num_entries; | - | ||||||||||||||||||
807 | QPixmap pm; | - | ||||||||||||||||||
808 | QString fileName; | - | ||||||||||||||||||
809 | QSize sz; | - | ||||||||||||||||||
810 | uint mode; | - | ||||||||||||||||||
811 | uint state; | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | s >> num_entries; | - | ||||||||||||||||||
814 | for (int i=0; i < num_entries
| 0 | ||||||||||||||||||
815 | s >> pm; | - | ||||||||||||||||||
816 | s >> fileName; | - | ||||||||||||||||||
817 | s >> sz; | - | ||||||||||||||||||
818 | s >> mode; | - | ||||||||||||||||||
819 | s >> state; | - | ||||||||||||||||||
820 | if (pm.isNull()
| 0 | ||||||||||||||||||
821 | icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); never executed: icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state)); | 0 | ||||||||||||||||||
822 | else | - | ||||||||||||||||||
823 | icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state)); never executed: icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state)); | 0 | ||||||||||||||||||
824 | } | - | ||||||||||||||||||
825 | } never executed: else {end of block | 0 | ||||||||||||||||||
826 | QPixmap pm; | - | ||||||||||||||||||
827 | s >> pm; | - | ||||||||||||||||||
828 | icon.addPixmap(pm); | - | ||||||||||||||||||
829 | } never executed: end of block | 0 | ||||||||||||||||||
830 | return never executed: s;return s; never executed: return s; | 0 | ||||||||||||||||||
831 | } | - | ||||||||||||||||||
832 | - | |||||||||||||||||||
833 | - | |||||||||||||||||||
834 | - | |||||||||||||||||||
835 | - | |||||||||||||||||||
836 | QDebug operator<<(QDebug dbg, const QIcon &i) | - | ||||||||||||||||||
837 | { | - | ||||||||||||||||||
838 | QDebugStateSaver saver(dbg); | - | ||||||||||||||||||
839 | dbg.resetFormat(); | - | ||||||||||||||||||
840 | dbg.nospace(); | - | ||||||||||||||||||
841 | dbg << "QIcon("; | - | ||||||||||||||||||
842 | if (i.isNull()) { | - | ||||||||||||||||||
843 | dbg << "null"; | - | ||||||||||||||||||
844 | } else { | - | ||||||||||||||||||
845 | if (!i.name().isEmpty()) | - | ||||||||||||||||||
846 | dbg << i.name() << ','; | - | ||||||||||||||||||
847 | dbg << "availableSizes[normal,Off]=" << i.availableSizes() | - | ||||||||||||||||||
848 | << ",cacheKey=" << showbase << hex << i.cacheKey() << dec << noshowbase; | - | ||||||||||||||||||
849 | } | - | ||||||||||||||||||
850 | dbg << ')'; | - | ||||||||||||||||||
851 | return dbg; | - | ||||||||||||||||||
852 | } | - | ||||||||||||||||||
853 | QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, | - | ||||||||||||||||||
854 | qreal *sourceDevicePixelRatio) | - | ||||||||||||||||||
855 | { | - | ||||||||||||||||||
856 | if (targetDevicePixelRatio <= 1.0) | - | ||||||||||||||||||
857 | return baseFileName; | - | ||||||||||||||||||
858 | - | |||||||||||||||||||
859 | static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING"); | - | ||||||||||||||||||
860 | if (disableNxImageLoading) | - | ||||||||||||||||||
861 | return baseFileName; | - | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | int dotIndex = baseFileName.lastIndexOf(QLatin1Char('.')); | - | ||||||||||||||||||
864 | if (dotIndex == -1) | - | ||||||||||||||||||
865 | dotIndex = baseFileName.size(); | - | ||||||||||||||||||
866 | - | |||||||||||||||||||
867 | QString atNxfileName = baseFileName; | - | ||||||||||||||||||
868 | atNxfileName.insert(dotIndex, QLatin1String("@2x")); | - | ||||||||||||||||||
869 | - | |||||||||||||||||||
870 | for (int n = qMin(qCeil(targetDevicePixelRatio), 9); n > 1; --n) { | - | ||||||||||||||||||
871 | atNxfileName[dotIndex + 1] = QLatin1Char('0' + n); | - | ||||||||||||||||||
872 | if (QFile::exists(atNxfileName)) { | - | ||||||||||||||||||
873 | if (sourceDevicePixelRatio) | - | ||||||||||||||||||
874 | *sourceDevicePixelRatio = n; | - | ||||||||||||||||||
875 | return atNxfileName; | - | ||||||||||||||||||
876 | } | - | ||||||||||||||||||
877 | } | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | return baseFileName; | - | ||||||||||||||||||
880 | } | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |