11#include "private/qfactoryloader_p.h"
12#include "private/qiconloader_p.h"
15#if QT_CONFIG(mimetype)
16#include <qmimedatabase.h>
27#include "private/qhexstring_p.h"
28#include "private/qguiapplication_p.h"
29#include "private/qoffsetstringarray_p.h"
30#include "qpa/qplatformtheme.h"
35using namespace Qt::StringLiterals;
41 ImageReader(
const QString &fileName, QSize size)
45 if (m_reader.supportsOption(QImageIOHandler::ScaledSize))
46 m_reader.setScaledSize(size);
49 QByteArray format()
const {
return m_reader.format(); }
50 bool supportsReadSize()
const {
return m_reader.supportsOption(QImageIOHandler::Size); }
51 QSize size()
const {
return m_reader.size(); }
52 bool jumpToNextImage() {
return m_reader.jumpToNextImage(); }
53 void jumpToImage(
int index) { m_reader.jumpToImage(index); }
55 bool read(QImage *image)
59 *image = m_reader.read();
60 if (!image->size().isValid()) {
64 m_atEnd = !m_reader.jumpToNextImage();
69 QImageReader m_reader;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
98
99
100
101
102
103
104
105
109 Q_CONSTINIT
static QBasicAtomicInt serial = Q_BASIC_ATOMIC_INITIALIZER(0);
110 return 1 + serial.fetchAndAddRelaxed(1);
115 struct IconCache :
public QCache<QString, QIcon>
125Q_GLOBAL_STATIC(IconCache, qtIconCache)
129 qtIconCache()->clear();
146
147
148
149
150
151
152
153
154
155
156qreal
QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio,
const QSize &requestedSize,
const QSize &actualSize)
158 QSize targetSize = requestedSize * displayDevicePixelRatio;
159 if ((actualSize.width() == targetSize.width() && actualSize.height() <= targetSize.height()) ||
160 (actualSize.width() <= targetSize.width() && actualSize.height() == targetSize.height())) {
162 return displayDevicePixelRatio;
164 qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) +
165 qreal(actualSize.height()) / qreal(targetSize.height()));
166 qreal dpr = qMax(qreal(1.0), displayDevicePixelRatio * scale);
167 return qRound(dpr * 100) / 100.0;
170QPixmapIconEngine::QPixmapIconEngine()
174QPixmapIconEngine::QPixmapIconEngine(
const QPixmapIconEngine &other)
175 : QIconEngine(other), pixmaps(other.pixmaps)
179QPixmapIconEngine::~QPixmapIconEngine()
183void QPixmapIconEngine::paint(QPainter *painter,
const QRect &rect, QIcon::Mode mode, QIcon::State state)
185 auto paintDevice = painter->device();
186 qreal dpr = paintDevice ? paintDevice->devicePixelRatio() : qApp->devicePixelRatio();
187 QPixmap px = scaledPixmap(rect.size(), mode, state, dpr);
188 painter->drawPixmap(rect, px);
191static inline qint64 area(
const QSize &s) {
return qint64(s.width()) * s.height(); }
201 const auto scaleA = pa->pixmap.devicePixelRatio();
202 const auto scaleB = pb->pixmap.devicePixelRatio();
204 if (scaleA != scaleB) {
209 qreal ascore = scaleA - scale;
210 qreal bscore = scaleB - scale;
213 if ((ascore < 0) != (bscore < 0))
214 return bscore < 0 ? pa : pb;
216 return (qAbs(ascore) < qAbs(bscore)) ? pa : pb;
219 qint64 s = area(size * scale);
220 if (pa->size == QSize() && pa->pixmap.isNull()) {
221 pa->pixmap = QPixmap(pa->fileName);
222 pa->size = pa->pixmap.size();
224 qint64 a = area(pa->size);
225 if (pb->size == QSize() && pb->pixmap.isNull()) {
226 pb->pixmap = QPixmap(pb->fileName);
227 pb->size = pb->pixmap.size();
229 qint64 b = area(pb->size);
240QPixmapIconEngineEntry *QPixmapIconEngine::tryMatch(
const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state)
242 QPixmapIconEngineEntry *pe =
nullptr;
243 for (
auto &entry : pixmaps) {
244 if (entry.mode == mode && entry.state == state) {
246 pe = bestSizeScaleMatch(size, scale, &entry, pe);
255QPixmapIconEngineEntry *QPixmapIconEngine::bestMatch(
const QSize &size, qreal scale, QIcon::Mode mode, QIcon::State state)
257 QPixmapIconEngineEntry *pe = tryMatch(size, scale, mode, state);
259 QIcon::State oppositeState = (state == QIcon::On) ? QIcon::Off : QIcon::On;
260 if (mode == QIcon::Disabled || mode == QIcon::Selected) {
261 QIcon::Mode oppositeMode = (mode == QIcon::Disabled) ? QIcon::Selected : QIcon::Disabled;
262 if ((pe = tryMatch(size, scale, QIcon::Normal, state)))
264 if ((pe = tryMatch(size, scale, QIcon::Active, state)))
266 if ((pe = tryMatch(size, scale, mode, oppositeState)))
268 if ((pe = tryMatch(size, scale, QIcon::Normal, oppositeState)))
270 if ((pe = tryMatch(size, scale, QIcon::Active, oppositeState)))
272 if ((pe = tryMatch(size, scale, oppositeMode, state)))
274 if ((pe = tryMatch(size, scale, oppositeMode, oppositeState)))
277 QIcon::Mode oppositeMode = (mode == QIcon::Normal) ? QIcon::Active : QIcon::Normal;
278 if ((pe = tryMatch(size, scale, oppositeMode, state)))
280 if ((pe = tryMatch(size, scale, mode, oppositeState)))
282 if ((pe = tryMatch(size, scale, oppositeMode, oppositeState)))
284 if ((pe = tryMatch(size, scale, QIcon::Disabled, state)))
286 if ((pe = tryMatch(size, scale, QIcon::Selected, state)))
288 if ((pe = tryMatch(size, scale, QIcon::Disabled, oppositeState)))
290 if ((pe = tryMatch(size, scale, QIcon::Selected, oppositeState)))
298 if (pe->pixmap.isNull()) {
300 QImage image, prevImage;
301 const QSize realSize = size * scale;
302 ImageReader imageReader(pe->fileName, realSize);
303 bool fittingImageFound =
false;
304 if (imageReader.supportsReadSize()) {
307 fittingImageFound = imageReader.size() == realSize;
308 }
while (!fittingImageFound && imageReader.jumpToNextImage());
310 if (!fittingImageFound) {
311 imageReader.jumpToImage(0);
312 while (imageReader.read(&image) && image.size() != realSize)
317 imageReader.read(&image);
319 if (!image.isNull()) {
320 pe->pixmap.convertFromImage(image);
321 if (!pe->pixmap.isNull()) {
322 pe->size = pe->pixmap.size();
323 pe->pixmap.setDevicePixelRatio(scale);
326 if (!pe->size.isValid()) {
327 removePixmapEntry(pe);
335QPixmap QPixmapIconEngine::pixmap(
const QSize &size, QIcon::Mode mode, QIcon::State state)
337 return scaledPixmap(size, mode, state, 1.0);
340QPixmap QPixmapIconEngine::scaledPixmap(
const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)
343 QPixmapIconEngineEntry *pe = bestMatch(size, scale, mode, state);
350 removePixmapEntry(pe);
351 if (pixmaps.isEmpty())
353 return scaledPixmap(size, mode, state, scale);
356 const auto actualSize = adjustSize(size * scale, pm.size());
357 const auto calculatedDpr = QIconPrivate::pixmapDevicePixelRatio(scale, size, actualSize);
358 QString key =
"qt_"_L1
359 % HexString<quint64>(pm.cacheKey())
360 % HexString<quint8>(pe->mode)
361 % HexString<quint64>(QGuiApplication::palette().cacheKey())
362 % HexString<uint>(actualSize.width())
363 % HexString<uint>(actualSize.height())
364 % HexString<quint16>(qRound(calculatedDpr * 1000));
366 if (mode == QIcon::Active) {
367 if (QPixmapCache::find(key % HexString<quint8>(mode), &pm))
369 if (QPixmapCache::find(key % HexString<quint8>(QIcon::Normal), &pm)) {
371 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
372 active =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
373 if (pm.cacheKey() == active.cacheKey())
378 if (!QPixmapCache::find(key % HexString<quint8>(mode), &pm)) {
379 if (pm.size() != actualSize)
380 pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
381 if (pe->mode != mode && mode != QIcon::Normal) {
382 QPixmap generated = pm;
383 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
384 generated =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm);
385 if (!generated.isNull())
388 pm.setDevicePixelRatio(calculatedDpr);
389 QPixmapCache::insert(key % HexString<quint8>(mode), pm);
394QSize QPixmapIconEngine::actualSize(
const QSize &size, QIcon::Mode mode, QIcon::State state)
403 if (QPixmapIconEngineEntry *pe = bestMatch(size, scale, mode, state))
404 actualSize = pe->size;
406 return adjustSize(size, actualSize);
409QList<QSize> QPixmapIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state)
412 for (QPixmapIconEngineEntry &pe : pixmaps) {
413 if (pe.mode != mode || pe.state != state)
415 if (pe.size.isEmpty() && pe.pixmap.isNull()) {
416 pe.pixmap = QPixmap(pe.fileName);
417 pe.size = pe.pixmap.size();
419 if (!pe.size.isEmpty() && !sizes.contains(pe.size))
420 sizes.push_back(pe.size);
425void QPixmapIconEngine::addPixmap(
const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
427 if (!pixmap.isNull()) {
428 QPixmapIconEngineEntry *pe = tryMatch(pixmap.size() / pixmap.devicePixelRatio(),
429 pixmap.devicePixelRatio(), mode, state);
430 if (pe && pe->size == pixmap.size() && pe->pixmap.devicePixelRatio() == pixmap.devicePixelRatio()) {
432 pe->fileName.clear();
434 pixmaps += QPixmapIconEngineEntry(pixmap, mode, state);
442 const QString s = image.text(QStringLiteral(
"_q_icoOrigDepth"));
443 return s.isEmpty() ? 32 : s.toInt();
446static inline int findBySize(
const QList<QImage> &images,
const QSize &size)
448 for (qsizetype i = 0; i < images.size(); ++i) {
449 if (images.at(i).size() == size)
455void QPixmapIconEngine::addFile(
const QString &fileName,
const QSize &size, QIcon::Mode mode, QIcon::State state)
457 if (fileName.isEmpty())
459 const QString abs = fileName.startsWith(u':') ? fileName : QFileInfo(fileName).absoluteFilePath();
460 const bool ignoreSize = !size.isValid();
461 ImageReader imageReader(abs, size);
462 const QByteArray format = imageReader.format();
463 if (format.isEmpty())
466 if (format !=
"ico") {
468 if (imageReader.supportsReadSize()) {
470 pixmaps += QPixmapIconEngineEntry(abs, imageReader.size(), mode, state);
471 }
while (imageReader.jumpToNextImage());
473 while (imageReader.read(&image))
474 pixmaps += QPixmapIconEngineEntry(abs, image, mode, state);
477 pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
485 QList<QImage> icoImages;
486 while (imageReader.read(&image)) {
487 if (ignoreSize || image.size() == size) {
488 const int position = findBySize(icoImages, image.size());
490 if (origIcoDepth(image) > origIcoDepth(icoImages.at(position)))
491 icoImages[position] = image;
493 icoImages.append(image);
497 for (
const QImage &i : std::as_const(icoImages))
498 pixmaps += QPixmapIconEngineEntry(abs, i, mode, state);
499 if (icoImages.isEmpty() && !ignoreSize)
500 pixmaps += QPixmapIconEngineEntry(abs, size, mode, state);
503bool QPixmapIconEngine::isNull()
505 return pixmaps.isEmpty();
508QString QPixmapIconEngine::key()
const
510 return "QPixmapIconEngine"_L1;
513QIconEngine *QPixmapIconEngine::clone()
const
515 return new QPixmapIconEngine(*
this);
518bool QPixmapIconEngine::read(QDataStream &in)
528 for (
int i=0; i < num_entries; ++i) {
539 addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
541 QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
549bool QPixmapIconEngine::write(QDataStream &out)
const
551 int num_entries = pixmaps.size();
553 for (
int i=0; i < num_entries; ++i) {
554 if (pixmaps.at(i).pixmap.isNull())
555 out << QPixmap(pixmaps.at(i).fileName);
557 out << pixmaps.at(i).pixmap;
558 out << pixmaps.at(i).fileName;
559 out << pixmaps.at(i).size;
560 out << (uint) pixmaps.at(i).mode;
561 out << (uint) pixmaps.at(i).state;
569QFactoryLoader *qt_iconEngineFactoryLoader()
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
756
757
758QIcon::QIcon()
noexcept
764
765
766QIcon::QIcon(
const QPixmap &pixmap)
773
774
775QIcon::QIcon(
const QIcon &other)
783
784
785
786
787
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807QIcon::QIcon(
const QString &fileName)
815
816
817
818QIcon::QIcon(QIconEngine *engine)
819 :d(
new QIconPrivate(engine))
824
825
828 if (d && !d->ref.deref())
833
834
835
836QIcon &QIcon::operator=(
const QIcon &other)
840 if (d && !d->ref.deref())
847
848
849
850
851
852
855
856
857
860
861
862QIcon::operator QVariant()
const
864 return QVariant::fromValue(*
this);
868
869
870
871
872
873
874
875
876
877
878
879qint64 QIcon::cacheKey()
const
883 return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no));
887
888
889
890
891
892
893
894QPixmap QIcon::pixmap(
const QSize &size, Mode mode, State state)
const
898 const qreal dpr = -1;
899 return pixmap(size, dpr, mode, state);
903
904
905
906
907
908
909
910
913
914
915
916
917
918
919
920
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939QPixmap QIcon::pixmap(
const QSize &size, qreal devicePixelRatio, Mode mode, State state)
const
945 if (devicePixelRatio == -1)
946 devicePixelRatio = qApp->devicePixelRatio();
948 QPixmap pixmap = d->engine->scaledPixmap(size, mode, state, devicePixelRatio);
952 pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size()));
956#if QT_DEPRECATED_SINCE(6
, 0
)
958
959
960
961
962
963
964
965
966
967
968
969
971QPixmap QIcon::pixmap(QWindow *window,
const QSize &size, Mode mode, State state)
const
976 qreal devicePixelRatio = window ? window->devicePixelRatio() : qApp->devicePixelRatio();
977 return pixmap(size, devicePixelRatio, mode, state);
983
984
985
986
987
988
989QSize QIcon::actualSize(
const QSize &size, Mode mode, State state)
const
994 const qreal devicePixelRatio = qApp->devicePixelRatio();
997 if (!(devicePixelRatio > 1.0))
998 return d->engine->actualSize(size, mode, state);
1000 const QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state);
1001 return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
1004#if QT_DEPRECATED_SINCE(6
, 0
)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1018QSize QIcon::actualSize(QWindow *window,
const QSize &size, Mode mode, State state)
const
1023 qreal devicePixelRatio = window ? window->devicePixelRatio() : qApp->devicePixelRatio();
1026 if (!(devicePixelRatio > 1.0))
1027 return d->engine->actualSize(size, mode, state);
1029 QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state);
1030 return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
1035
1036
1037
1038
1039
1040void QIcon::paint(QPainter *painter,
const QRect &rect, Qt::Alignment alignment, Mode mode, State state)
const
1046 const QSize size = d->engine->actualSize(rect.size(), mode, state);
1047 alignment = QGuiApplicationPrivate::visualAlignment(painter->layoutDirection(), alignment);
1050 int w = size.width();
1051 int h = size.height();
1052 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
1053 y += rect.size().height()/2 - h/2;
1054 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
1055 y += rect.size().height() - h;
1056 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
1057 x += rect.size().width() - w;
1058 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
1059 x += rect.size().width()/2 - w/2;
1060 QRect alignedRect(x, y, w, h);
1062 d->engine->paint(painter, alignedRect, mode, state);
1066
1067
1068
1069
1070
1071
1072
1075
1076
1077
1078
1079
1080
1081
1082bool QIcon::isNull()
const
1084 return !d || d->engine->isNull();
1088
1089bool QIcon::isDetached()
const
1091 return !d || d->ref.loadRelaxed() == 1;
1095
1099 if (d->engine->isNull()) {
1100 if (!d->ref.deref())
1104 }
else if (d->ref.loadRelaxed() != 1) {
1105 QIconPrivate *x =
new QIconPrivate(d->engine->clone());
1106 if (!d->ref.deref())
1115
1116
1117
1118
1119
1120
1121
1122
1123void QIcon::addPixmap(
const QPixmap &pixmap, Mode mode, State state)
1125 if (pixmap.isNull())
1129 d =
new QIconPrivate(
new QPixmapIconEngine);
1130 d->engine->addPixmap(pixmap, mode, state);
1135 if (!suffix.isEmpty()) {
1136 const int index = iceLoader()->indexOf(suffix);
1138 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(iceLoader()->instance(index))) {
1139 return factory->create(fileName);
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176void QIcon::addFile(
const QString &fileName,
const QSize &size, Mode mode, State state)
1178 if (fileName.isEmpty())
1181 bool alreadyAdded =
false;
1184 QFileInfo info(fileName);
1185 QString suffix = info.suffix();
1186#if QT_CONFIG(mimetype)
1187 if (suffix.isEmpty())
1188 suffix = QMimeDatabase().mimeTypeForFile(info).preferredSuffix();
1190 QIconEngine *engine = iconEngineFromSuffix(fileName, suffix);
1192 alreadyAdded = !engine->isNull();
1193 d =
new QIconPrivate(engine ? engine :
new QPixmapIconEngine);
1196 d->engine->addFile(fileName, size, mode, state);
1198 if (d->engine->key() ==
"svg"_L1)
1202 QVarLengthArray<
int, 4> devicePixelRatios;
1203 const auto screens = qApp->screens();
1204 for (
const auto *screen : screens) {
1205 const auto dpr = qCeil(screen->devicePixelRatio());
1206 if (dpr >= 1 && !devicePixelRatios.contains(dpr))
1207 devicePixelRatios.push_back(dpr);
1209 std::sort(devicePixelRatios.begin(), devicePixelRatios.end(), std::greater<
int>());
1210 qreal sourceDevicePixelRatio = std::numeric_limits<qreal>::max();
1211 for (
const auto dpr : std::as_const(devicePixelRatios)) {
1212 if (dpr >= sourceDevicePixelRatio)
1214 const QString atNxFileName = qt_findAtNxFile(fileName, dpr, &sourceDevicePixelRatio);
1215 if (atNxFileName != fileName)
1216 d->engine->addFile(atNxFileName, size, mode, state);
1221
1222
1223
1224QList<QSize> QIcon::availableSizes(Mode mode, State state)
const
1226 if (!d || !d->engine)
1227 return QList<QSize>();
1228 return d->engine->availableSizes(mode, state);
1232
1233
1234
1235
1236
1237
1238
1239QString QIcon::name()
const
1241 if (!d || !d->engine)
1243 return d->engine->iconName();
1247
1248
1249
1250
1251
1252
1253
1254void QIcon::setThemeSearchPaths(
const QStringList &paths)
1256 QIconLoader::instance()->setThemeSearchPath(paths);
1260
1261
1262
1263
1264
1265
1266
1267QStringList QIcon::themeSearchPaths()
1269 return QIconLoader::instance()->themeSearchPaths();
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287QStringList QIcon::fallbackSearchPaths()
1289 return QIconLoader::instance()->fallbackSearchPaths();
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308void QIcon::setFallbackSearchPaths(
const QStringList &paths)
1310 QIconLoader::instance()->setFallbackSearchPaths(paths);
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329void QIcon::setThemeName(
const QString &name)
1331 QIconLoader::instance()->setThemeName(name);
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347QString QIcon::themeName()
1349 return QIconLoader::instance()->themeName();
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366QString QIcon::fallbackThemeName()
1368 return QIconLoader::instance()->fallbackThemeName();
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389void QIcon::setFallbackThemeName(
const QString &name)
1391 QIconLoader::instance()->setFallbackThemeName(name);
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415QIcon QIcon::fromTheme(
const QString &name)
1418 if (QIcon *cachedIcon = qtIconCache()->object(name))
1421 if (QDir::isAbsolutePath(name))
1424 QIcon icon(
new QThemeIconEngine(name));
1425 qtIconCache()->insert(name,
new QIcon(icon));
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453QIcon QIcon::fromTheme(
const QString &name,
const QIcon &fallback)
1455 QIcon icon = fromTheme(name);
1457 if (icon.isNull() || icon.availableSizes().isEmpty())
1464
1465
1466
1467
1468
1469
1470bool QIcon::hasThemeIcon(
const QString &name)
1472 QIcon icon = fromTheme(name);
1474 return icon.name() == name;
1486 "document-open-recent",
1487 "document-page-setup",
1489 "document-print-preview",
1490 "document-properties",
1505 "format-indent-less",
1506 "format-indent-more",
1507 "format-justify-center",
1508 "format-justify-fill",
1509 "format-justify-left",
1510 "format-justify-right",
1511 "format-text-direction-ltr",
1512 "format-text-direction-rtl",
1514 "format-text-italic",
1515 "format-text-underline",
1516 "format-text-strikethrough",
1530 "mail-mark-important",
1535 "mail-reply-sender",
1538 "media-playback-pause",
1539 "media-playback-start",
1540 "media-playback-stop",
1542 "media-seek-backward",
1543 "media-seek-forward",
1544 "media-skip-backward",
1545 "media-skip-forward",
1546 "object-rotate-left",
1547 "object-rotate-right",
1549 "system-lock-screen",
1554 "tools-check-spelling",
1565 "audio-input-microphone",
1580 "multimedia-player",
1588 "appointment-missed",
1590 "audio-volume-high",
1592 "audio-volume-medium",
1593 "audio-volume-muted",
1597 "dialog-information",
1601 "folder-drag-accept",
1610 "media-playlist-repeat",
1611 "media-playlist-shuffle",
1616 "software-update-available",
1617 "software-update-urgent",
1619 "sync-synchronizing",
1623 "weather-clear-night",
1624 "weather-few-clouds",
1625 "weather-few-clouds-night",
1631static_assert(QIcon::ThemeIcon::NThemeIcons == QIcon::ThemeIcon(themeIconMapping.count()));
1635 using ThemeIconIndex = std::underlying_type_t<QIcon::ThemeIcon>;
1636 const auto index =
static_cast<ThemeIconIndex>(icon);
1637 Q_ASSERT(index < themeIconMapping.count());
1638 return QLatin1StringView(themeIconMapping.viewAt(index));
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834bool QIcon::hasThemeIcon(QIcon::ThemeIcon icon)
1836 return hasThemeIcon(themeIconName(icon));
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862QIcon QIcon::fromTheme(QIcon::ThemeIcon icon)
1864 return fromTheme(themeIconName(icon));
1867QIcon QIcon::fromTheme(QIcon::ThemeIcon icon,
const QIcon &fallback)
1869 return fromTheme(themeIconName(icon), fallback);
1873
1874
1875
1876
1877
1878
1879void QIcon::setIsMask(
bool isMask)
1881 if (isMask == (d && d->is_mask))
1886 d =
new QIconPrivate(
new QPixmapIconEngine);
1887 d->is_mask = isMask;
1891
1892
1893
1894
1895
1896
1897
1898
1899bool QIcon::isMask()
const
1907
1908
1909#if !defined(QT_NO_DATASTREAM)
1911
1912
1913
1914
1915
1916
1917
1918
1920QDataStream &operator<<(QDataStream &s,
const QIcon &icon)
1922 if (s.version() >= QDataStream::Qt_4_3) {
1923 if (icon.isNull()) {
1926 s << icon.d->engine->key();
1927 icon.d->engine->write(s);
1929 }
else if (s.version() == QDataStream::Qt_4_2) {
1930 if (icon.isNull()) {
1933 QPixmapIconEngine *engine =
static_cast<QPixmapIconEngine *>(icon.d->engine);
1934 int num_entries = engine->pixmaps.size();
1936 for (
int i=0; i < num_entries; ++i) {
1937 s << engine->pixmaps.at(i).pixmap;
1938 s << engine->pixmaps.at(i).fileName;
1939 s << engine->pixmaps.at(i).size;
1940 s << (uint) engine->pixmaps.at(i).mode;
1941 s << (uint) engine->pixmaps.at(i).state;
1945 s << QPixmap(icon.pixmap(22,22));
1951
1952
1953
1954
1955
1956
1960 if (s.version() >= QDataStream::Qt_4_3) {
1964 if (key ==
"QPixmapIconEngine"_L1) {
1965 icon.d =
new QIconPrivate(
new QPixmapIconEngine);
1966 icon.d->engine->read(s);
1967 }
else if (key ==
"QIconLoaderEngine"_L1 || key ==
"QThemeIconEngine"_L1) {
1968 icon.d =
new QIconPrivate(
new QThemeIconEngine);
1969 icon.d->engine->read(s);
1971 const int index = iceLoader()->indexOf(key);
1973 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(iceLoader()->instance(index))) {
1974 if (QIconEngine *engine= factory->create()) {
1981 }
else if (s.version() == QDataStream::Qt_4_2) {
1991 for (
int i=0; i < num_entries; ++i) {
1998 icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
2000 icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
2012#ifndef QT_NO_DEBUG_STREAM
2015 QDebugStateSaver saver(dbg);
2022 if (!i.name().isEmpty())
2023 dbg << i.name() <<
',';
2024 dbg <<
"availableSizes[normal,Off]=" << i.availableSizes()
2025 <<
",cacheKey=" << Qt::showbase << Qt::hex << i.cacheKey() << Qt::dec << Qt::noshowbase;
2033
2034
2035
2038
2039
2040
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2055 qreal *sourceDevicePixelRatio)
2057 if (sourceDevicePixelRatio)
2058 *sourceDevicePixelRatio = 1;
2059 if (targetDevicePixelRatio <= 1.0)
2060 return baseFileName;
2062 static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty(
"QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
2063 if (disableNxImageLoading)
2064 return baseFileName;
2066 int dotIndex = baseFileName.lastIndexOf(u'.');
2067 if (dotIndex == -1) {
2068 dotIndex = baseFileName.size();
2069 }
else if (dotIndex >= 2 && baseFileName[dotIndex - 1] == u'9'
2070 && baseFileName[dotIndex - 2] == u'.') {
2075 QString atNxfileName = baseFileName;
2076 atNxfileName.insert(dotIndex,
"@2x"_L1);
2078 for (
int n = qMin(qCeil(targetDevicePixelRatio), 9); n > 1; --n) {
2079 atNxfileName[dotIndex + 1] = QLatin1Char(
'0' + n);
2080 if (QFile::exists(atNxfileName)) {
2081 if (sourceDevicePixelRatio)
2082 *sourceDevicePixelRatio = n;
2083 return atNxfileName;
2087 return baseFileName;
QIconPrivate(QIconEngine *e)
static void clearIconCache()
QString fileName() const
If the currently assigned device is a QFile, or if setFileName() has been called, this function retur...
\macro QT_RESTRICTED_CAST_FROM_ASCII
Combined button and popup list for selecting options.
QDataStream & operator>>(QDataStream &s, QKeyCombination &combination)
QDebug operator<<(QDebug dbg, const QFileInfo &fi)
static void qt_cleanup_icon_cache()
static constexpr auto themeIconMapping
static int origIcoDepth(const QImage &image)
static qint64 area(const QSize &s)
static int nextSerialNumCounter()
static QIconEngine * iconEngineFromSuffix(const QString &fileName, const QString &suffix)
QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio)
static int findBySize(const QList< QImage > &images, const QSize &size)
static QPixmapIconEngineEntry * bestSizeScaleMatch(const QSize &size, qreal scale, QPixmapIconEngineEntry *pa, QPixmapIconEngineEntry *pb)
static constexpr QLatin1StringView themeIconName(QIcon::ThemeIcon icon)
#define QIconEngineFactoryInterface_iid
Q_GLOBAL_STATIC_WITH_ARGS(PermissionStatusHash, g_permissionStatusHash,({ { qMetaTypeId< QCameraPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QMicrophonePermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QBluetoothPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QContactsPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QCalendarPermission >(), Qt::PermissionStatus::Undetermined }, { qMetaTypeId< QLocationPermission >(), Qt::PermissionStatus::Undetermined } }))