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 if (pe->pixmap.convertFromImage(image))
321 pe->size = pe->pixmap.size();
323 if (!pe->size.isValid()) {
324 removePixmapEntry(pe);
332QPixmap QPixmapIconEngine::pixmap(
const QSize &size, QIcon::Mode mode, QIcon::State state)
334 return scaledPixmap(size, mode, state, 1.0);
337QPixmap QPixmapIconEngine::scaledPixmap(
const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)
340 QPixmapIconEngineEntry *pe = bestMatch(size, scale, mode, state);
347 removePixmapEntry(pe);
350 return scaledPixmap(size, mode, state, scale);
353 const auto actualSize = adjustSize(size * scale, pm.size());
354 const auto calculatedDpr = QIconPrivate::pixmapDevicePixelRatio(scale, size, actualSize);
355 QString key =
"qt_"_L1
356 % HexString<quint64>(pm.cacheKey())
357 % HexString<quint8>(pe->mode)
358 % HexString<quint64>(QGuiApplication::palette().cacheKey())
359 % HexString<uint>(actualSize.width())
360 % HexString<uint>(actualSize.height())
361 % HexString<quint16>(qRound(calculatedDpr * 1000));
363 if (mode == QIcon::Active) {
364 if (QPixmapCache::find(key % HexString<quint8>(mode), &pm))
366 if (QPixmapCache::find(key % HexString<quint8>(QIcon::Normal), &pm)) {
368 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
369 active =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(QIcon::Active, pm);
370 if (pm.cacheKey() == active.cacheKey())
375 if (!QPixmapCache::find(key % HexString<quint8>(mode), &pm)) {
376 if (pm.size() != actualSize)
377 pm = pm.scaled(actualSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
378 if (pe->mode != mode && mode != QIcon::Normal) {
379 QPixmap generated = pm;
380 if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(qApp))
381 generated =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(guiApp))->applyQIconStyleHelper(mode, pm);
382 if (!generated.isNull())
385 pm.setDevicePixelRatio(calculatedDpr);
386 QPixmapCache::insert(key % HexString<quint8>(mode), pm);
391QSize QPixmapIconEngine::actualSize(
const QSize &size, QIcon::Mode mode, QIcon::State state)
400 if (QPixmapIconEngineEntry *pe = bestMatch(size, scale, mode, state))
401 actualSize = pe->size;
403 return adjustSize(size, actualSize);
406QList<QSize> QPixmapIconEngine::availableSizes(QIcon::Mode mode, QIcon::State state)
409 for (QPixmapIconEngineEntry &pe : pixmaps) {
410 if (pe.mode != mode || pe.state != state)
412 if (pe.size.isEmpty() && pe.pixmap.isNull()) {
413 pe.pixmap = QPixmap(pe.fileName);
414 pe.size = pe.pixmap.size();
416 if (!pe.size.isEmpty() && !sizes.contains(pe.size))
417 sizes.push_back(pe.size);
422void QPixmapIconEngine::addPixmap(
const QPixmap &pixmap, QIcon::Mode mode, QIcon::State state)
424 if (!pixmap.isNull()) {
425 QPixmapIconEngineEntry *pe = tryMatch(pixmap.size() / pixmap.devicePixelRatio(),
426 pixmap.devicePixelRatio(), mode, state);
427 if (pe && pe->size == pixmap.size() && pe->pixmap.devicePixelRatio() == pixmap.devicePixelRatio()) {
429 pe->fileName.clear();
431 pixmaps.emplace_back(pixmap, mode, state);
439 const QString s = image.text(QStringLiteral(
"_q_icoOrigDepth"));
440 return s.isEmpty() ? 32 : s.toInt();
443static inline int findBySize(
const QList<QImage> &images,
const QSize &size)
445 for (qsizetype i = 0; i < images.size(); ++i) {
446 if (images.at(i).size() == size)
452void QPixmapIconEngine::addFile(
const QString &fileName,
const QSize &size, QIcon::Mode mode, QIcon::State state)
454 if (fileName.isEmpty())
456 const QString abs = fileName.startsWith(u':') ? fileName : QFileInfo(fileName).absoluteFilePath();
457 const bool ignoreSize = !size.isValid();
458 ImageReader imageReader(abs, size);
459 const QByteArray format = imageReader.format();
460 if (format.isEmpty())
463 if (format !=
"ico") {
465 if (imageReader.supportsReadSize()) {
467 pixmaps.emplace_back(abs, imageReader.size(), mode, state);
468 }
while (imageReader.jumpToNextImage());
470 while (imageReader.read(&image))
471 pixmaps.emplace_back(abs, image, mode, state);
474 pixmaps.emplace_back(abs, size, mode, state);
482 QList<QImage> icoImages;
483 while (imageReader.read(&image)) {
484 if (ignoreSize || image.size() == size) {
485 const int position = findBySize(icoImages, image.size());
487 if (origIcoDepth(image) > origIcoDepth(icoImages.at(position)))
488 icoImages[position] = image;
490 icoImages.append(image);
494 for (
const QImage &i : std::as_const(icoImages))
495 pixmaps.emplace_back(abs, i, mode, state);
496 if (icoImages.empty() && !ignoreSize)
497 pixmaps.emplace_back(abs, size, mode, state);
500bool QPixmapIconEngine::isNull()
502 return pixmaps.empty();
505QString QPixmapIconEngine::key()
const
507 return "QPixmapIconEngine"_L1;
510QIconEngine *QPixmapIconEngine::clone()
const
512 return new QPixmapIconEngine(*
this);
515bool QPixmapIconEngine::read(QDataStream &in)
525 for (
int i=0; i < num_entries; ++i) {
536 addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
538 QPixmapIconEngineEntry pe(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
540 pixmaps.push_back(std::move(pe));
546bool QPixmapIconEngine::write(QDataStream &out)
const
548 int num_entries = pixmaps.size();
550 for (
int i=0; i < num_entries; ++i) {
551 if (pixmaps.at(i).pixmap.isNull())
552 out << QPixmap(pixmaps.at(i).fileName);
554 out << pixmaps.at(i).pixmap;
555 out << pixmaps.at(i).fileName;
556 out << pixmaps.at(i).size;
557 out << (uint) pixmaps.at(i).mode;
558 out << (uint) pixmaps.at(i).state;
566QFactoryLoader *qt_iconEngineFactoryLoader()
573
574
575
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
753
754
755QIcon::QIcon()
noexcept
761
762
763QIcon::QIcon(
const QPixmap &pixmap)
770
771
772QIcon::QIcon(
const QIcon &other)
780
781
782
783
784
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804QIcon::QIcon(
const QString &fileName)
812
813
814
815QIcon::QIcon(QIconEngine *engine)
816 :d(
new QIconPrivate(engine))
821
822
825 if (d && !d->ref.deref())
830
831
832
833QIcon &QIcon::operator=(
const QIcon &other)
837 if (d && !d->ref.deref())
844
845
846
847
848
849
852
853
854
857
858
859QIcon::operator QVariant()
const
861 return QVariant::fromValue(*
this);
865
866
867
868
869
870
871
872
873
874
875
876qint64 QIcon::cacheKey()
const
880 return (((qint64) d->serialNum) << 32) | ((qint64) (d->detach_no));
884
885
886
887
888
889
890
891QPixmap QIcon::pixmap(
const QSize &size, Mode mode, State state)
const
895 const qreal dpr = -1;
896 return pixmap(size, dpr, mode, state);
900
901
902
903
904
905
906
907
910
911
912
913
914
915
916
917
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936QPixmap QIcon::pixmap(
const QSize &size, qreal devicePixelRatio, Mode mode, State state)
const
942 if (devicePixelRatio == -1)
943 devicePixelRatio = qApp->devicePixelRatio();
945 QPixmap pixmap = d->engine->scaledPixmap(size, mode, state, devicePixelRatio);
949 pixmap.setDevicePixelRatio(d->pixmapDevicePixelRatio(devicePixelRatio, size, pixmap.size()));
953#if QT_DEPRECATED_SINCE(6
, 0
)
955
956
957
958
959
960
961
962
963
964
965
966
968QPixmap QIcon::pixmap(QWindow *window,
const QSize &size, Mode mode, State state)
const
973 qreal devicePixelRatio = window ? window->devicePixelRatio() : qApp->devicePixelRatio();
974 return pixmap(size, devicePixelRatio, mode, state);
980
981
982
983
984
985
986QSize QIcon::actualSize(
const QSize &size, Mode mode, State state)
const
991 const qreal devicePixelRatio = qApp->devicePixelRatio();
994 if (!(devicePixelRatio > 1.0))
995 return d->engine->actualSize(size, mode, state);
997 const QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state);
998 return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
1001#if QT_DEPRECATED_SINCE(6
, 0
)
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1015QSize QIcon::actualSize(QWindow *window,
const QSize &size, Mode mode, State state)
const
1020 qreal devicePixelRatio = window ? window->devicePixelRatio() : qApp->devicePixelRatio();
1023 if (!(devicePixelRatio > 1.0))
1024 return d->engine->actualSize(size, mode, state);
1026 QSize actualSize = d->engine->actualSize(size * devicePixelRatio, mode, state);
1027 return actualSize / d->pixmapDevicePixelRatio(devicePixelRatio, size, actualSize);
1032
1033
1034
1035
1036
1037void QIcon::paint(QPainter *painter,
const QRect &rect, Qt::Alignment alignment, Mode mode, State state)
const
1043 const QSize size = d->engine->actualSize(rect.size(), mode, state);
1044 alignment = QGuiApplicationPrivate::visualAlignment(painter->layoutDirection(), alignment);
1047 int w = size.width();
1048 int h = size.height();
1049 if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter)
1050 y += rect.size().height()/2 - h/2;
1051 else if ((alignment & Qt::AlignBottom) == Qt::AlignBottom)
1052 y += rect.size().height() - h;
1053 if ((alignment & Qt::AlignRight) == Qt::AlignRight)
1054 x += rect.size().width() - w;
1055 else if ((alignment & Qt::AlignHCenter) == Qt::AlignHCenter)
1056 x += rect.size().width()/2 - w/2;
1057 QRect alignedRect(x, y, w, h);
1059 d->engine->paint(painter, alignedRect, mode, state);
1063
1064
1065
1066
1067
1068
1069
1072
1073
1074
1075
1076
1077
1078
1079bool QIcon::isNull()
const
1081 return !d || d->engine->isNull();
1085
1086bool QIcon::isDetached()
const
1088 return !d || d->ref.loadRelaxed() == 1;
1092
1096 if (d->engine->isNull()) {
1097 if (!d->ref.deref())
1101 }
else if (d->ref.loadRelaxed() != 1) {
1102 QIconPrivate *x =
new QIconPrivate(d->engine->clone());
1103 if (!d->ref.deref())
1112
1113
1114
1115
1116
1117
1118
1119
1120void QIcon::addPixmap(
const QPixmap &pixmap, Mode mode, State state)
1122 if (pixmap.isNull())
1126 d =
new QIconPrivate(
new QPixmapIconEngine);
1127 d->engine->addPixmap(pixmap, mode, state);
1132 if (!suffix.isEmpty()) {
1133 const int index = iceLoader()->indexOf(suffix);
1135 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(iceLoader()->instance(index))) {
1136 return factory->create(fileName);
1144
1145
1146
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
1173void QIcon::addFile(
const QString &fileName,
const QSize &size, Mode mode, State state)
1175 if (fileName.isEmpty())
1178 bool alreadyAdded =
false;
1181 QFileInfo info(fileName);
1182 QString suffix = info.suffix();
1183#if QT_CONFIG(mimetype)
1184 if (suffix.isEmpty())
1185 suffix = QMimeDatabase().mimeTypeForFile(info).preferredSuffix();
1187 QIconEngine *engine = iconEngineFromSuffix(fileName, suffix);
1189 alreadyAdded = !engine->isNull();
1190 d =
new QIconPrivate(engine ? engine :
new QPixmapIconEngine);
1193 d->engine->addFile(fileName, size, mode, state);
1195 if (d->engine->key() ==
"svg"_L1)
1199 QVarLengthArray<
int, 4> devicePixelRatios;
1200 const auto screens = qApp->screens();
1201 for (
const auto *screen : screens) {
1202 const auto dpr = qCeil(screen->devicePixelRatio());
1203 if (dpr >= 1 && !devicePixelRatios.contains(dpr))
1204 devicePixelRatios.push_back(dpr);
1206 std::sort(devicePixelRatios.begin(), devicePixelRatios.end(), std::greater<
int>());
1207 qreal sourceDevicePixelRatio = std::numeric_limits<qreal>::max();
1208 for (
const auto dpr : std::as_const(devicePixelRatios)) {
1209 if (dpr >= sourceDevicePixelRatio)
1211 const QString atNxFileName = qt_findAtNxFile(fileName, dpr, &sourceDevicePixelRatio);
1212 if (atNxFileName != fileName)
1213 d->engine->addFile(atNxFileName, size, mode, state);
1218
1219
1220
1221QList<QSize> QIcon::availableSizes(Mode mode, State state)
const
1223 if (!d || !d->engine)
1224 return QList<QSize>();
1225 return d->engine->availableSizes(mode, state);
1229
1230
1231
1232
1233
1234
1235
1236QString QIcon::name()
const
1238 if (!d || !d->engine)
1240 return d->engine->iconName();
1244
1245
1246
1247
1248
1249
1250
1251void QIcon::setThemeSearchPaths(
const QStringList &paths)
1253 QIconLoader::instance()->setThemeSearchPath(paths);
1257
1258
1259
1260
1261
1262
1263
1264QStringList QIcon::themeSearchPaths()
1266 return QIconLoader::instance()->themeSearchPaths();
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284QStringList QIcon::fallbackSearchPaths()
1286 return QIconLoader::instance()->fallbackSearchPaths();
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305void QIcon::setFallbackSearchPaths(
const QStringList &paths)
1307 QIconLoader::instance()->setFallbackSearchPaths(paths);
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326void QIcon::setThemeName(
const QString &name)
1328 QIconLoader::instance()->setThemeName(name);
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344QString QIcon::themeName()
1346 return QIconLoader::instance()->themeName();
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363QString QIcon::fallbackThemeName()
1365 return QIconLoader::instance()->fallbackThemeName();
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386void QIcon::setFallbackThemeName(
const QString &name)
1388 QIconLoader::instance()->setFallbackThemeName(name);
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412QIcon QIcon::fromTheme(
const QString &name)
1417 if (QIcon *cachedIcon = qtIconCache()->object(name))
1420 if (QDir::isAbsolutePath(name))
1423 QIcon icon(
new QThemeIconEngine(name));
1424 qtIconCache()->insert(name,
new QIcon(icon));
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452QIcon QIcon::fromTheme(
const QString &name,
const QIcon &fallback)
1454 QIcon icon = fromTheme(name);
1456 if (icon.isNull() || icon.availableSizes().isEmpty())
1463
1464
1465
1466
1467
1468
1469bool QIcon::hasThemeIcon(
const QString &name)
1471 QIcon icon = fromTheme(name);
1473 return icon.name() == name;
1485 "document-open-recent",
1486 "document-page-setup",
1488 "document-print-preview",
1489 "document-properties",
1504 "format-indent-less",
1505 "format-indent-more",
1506 "format-justify-center",
1507 "format-justify-fill",
1508 "format-justify-left",
1509 "format-justify-right",
1510 "format-text-direction-ltr",
1511 "format-text-direction-rtl",
1513 "format-text-italic",
1514 "format-text-underline",
1515 "format-text-strikethrough",
1529 "mail-mark-important",
1534 "mail-reply-sender",
1537 "media-playback-pause",
1538 "media-playback-start",
1539 "media-playback-stop",
1541 "media-seek-backward",
1542 "media-seek-forward",
1543 "media-skip-backward",
1544 "media-skip-forward",
1545 "object-rotate-left",
1546 "object-rotate-right",
1548 "system-lock-screen",
1553 "tools-check-spelling",
1564 "audio-input-microphone",
1579 "multimedia-player",
1587 "appointment-missed",
1589 "audio-volume-high",
1591 "audio-volume-medium",
1592 "audio-volume-muted",
1596 "dialog-information",
1600 "folder-drag-accept",
1609 "media-playlist-repeat",
1610 "media-playlist-shuffle",
1615 "software-update-available",
1616 "software-update-urgent",
1618 "sync-synchronizing",
1622 "weather-clear-night",
1623 "weather-few-clouds",
1624 "weather-few-clouds-night",
1630static_assert(QIcon::ThemeIcon::NThemeIcons == QIcon::ThemeIcon(themeIconMapping.count()));
1634 using ThemeIconIndex = std::underlying_type_t<QIcon::ThemeIcon>;
1635 const auto index =
static_cast<ThemeIconIndex>(icon);
1636 Q_ASSERT(index < themeIconMapping.count());
1637 return QLatin1StringView(themeIconMapping.viewAt(index));
1641
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
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833bool QIcon::hasThemeIcon(QIcon::ThemeIcon icon)
1835 return hasThemeIcon(themeIconName(icon));
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861QIcon QIcon::fromTheme(QIcon::ThemeIcon icon)
1863 return fromTheme(themeIconName(icon));
1866QIcon QIcon::fromTheme(QIcon::ThemeIcon icon,
const QIcon &fallback)
1868 return fromTheme(themeIconName(icon), fallback);
1872
1873
1874
1875
1876
1877
1878void QIcon::setIsMask(
bool isMask)
1880 if (isMask == (d && d->is_mask))
1885 d =
new QIconPrivate(
new QPixmapIconEngine);
1886 d->is_mask = isMask;
1890
1891
1892
1893
1894
1895
1896
1897
1898bool QIcon::isMask()
const
1906
1907
1908#if !defined(QT_NO_DATASTREAM)
1910
1911
1912
1913
1914
1915
1916
1917
1919QDataStream &operator<<(QDataStream &s,
const QIcon &icon)
1921 if (s.version() >= QDataStream::Qt_4_3) {
1922 if (icon.isNull()) {
1925 s << icon.d->engine->key();
1926 icon.d->engine->write(s);
1928 }
else if (s.version() == QDataStream::Qt_4_2) {
1929 if (icon.isNull()) {
1932 QPixmapIconEngine *engine =
static_cast<QPixmapIconEngine *>(icon.d->engine);
1933 int num_entries = engine->pixmaps.size();
1935 for (
int i=0; i < num_entries; ++i) {
1936 s << engine->pixmaps.at(i).pixmap;
1937 s << engine->pixmaps.at(i).fileName;
1938 s << engine->pixmaps.at(i).size;
1939 s << (uint) engine->pixmaps.at(i).mode;
1940 s << (uint) engine->pixmaps.at(i).state;
1944 s << QPixmap(icon.pixmap(22,22));
1950
1951
1952
1953
1954
1955
1959 if (s.version() >= QDataStream::Qt_4_3) {
1963 if (key ==
"QPixmapIconEngine"_L1) {
1964 icon.d =
new QIconPrivate(
new QPixmapIconEngine);
1965 icon.d->engine->read(s);
1966 }
else if (key ==
"QIconLoaderEngine"_L1 || key ==
"QThemeIconEngine"_L1) {
1967 icon.d =
new QIconPrivate(
new QThemeIconEngine);
1968 icon.d->engine->read(s);
1970 const int index = iceLoader()->indexOf(key);
1972 if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(iceLoader()->instance(index))) {
1973 if (QIconEngine *engine= factory->create()) {
1980 }
else if (s.version() == QDataStream::Qt_4_2) {
1990 for (
int i=0; i < num_entries; ++i) {
1997 icon.addFile(fileName, sz, QIcon::Mode(mode), QIcon::State(state));
1999 icon.addPixmap(pm, QIcon::Mode(mode), QIcon::State(state));
2011#ifndef QT_NO_DEBUG_STREAM
2014 QDebugStateSaver saver(dbg);
2021 if (!i.name().isEmpty())
2022 dbg << i.name() <<
',';
2023 dbg <<
"availableSizes[normal,Off]=" << i.availableSizes()
2024 <<
",cacheKey=" << Qt::showbase << Qt::hex << i.cacheKey() << Qt::dec << Qt::noshowbase;
2032
2033
2034
2037
2038
2039
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2054 qreal *sourceDevicePixelRatio)
2056 if (sourceDevicePixelRatio)
2057 *sourceDevicePixelRatio = 1;
2058 if (targetDevicePixelRatio <= 1.0)
2059 return baseFileName;
2061 static bool disableNxImageLoading = !qEnvironmentVariableIsEmpty(
"QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING");
2062 if (disableNxImageLoading)
2063 return baseFileName;
2065 int dotIndex = baseFileName.lastIndexOf(u'.');
2066 if (dotIndex == -1) {
2067 dotIndex = baseFileName.size();
2068 }
else if (dotIndex >= 2 && baseFileName[dotIndex - 1] == u'9'
2069 && baseFileName[dotIndex - 2] == u'.') {
2074 QString atNxfileName = baseFileName;
2075 atNxfileName.insert(dotIndex,
"@2x"_L1);
2077 for (
int n = qMin(qCeil(targetDevicePixelRatio), 9); n > 1; --n) {
2078 atNxfileName[dotIndex + 1] = QLatin1Char(
'0' + n);
2079 if (QFile::exists(atNxfileName)) {
2080 if (sourceDevicePixelRatio)
2081 *sourceDevicePixelRatio = n;
2082 return atNxfileName;
2086 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 } }))