diff options
author | Bastiaan Veelo <Bastiaan@SARC.nl> | 2013-11-16 21:42:01 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-30 17:48:50 +0100 |
commit | 6e13f4b3e03a055bafc78037b0bf68d90fbbe98d (patch) | |
tree | 8a885a7cf5983a65d863acf06690ad11442414ec | |
parent | 97fd5399bca4f10393884cfd3bb20c29fb5361b4 (diff) | |
download | qtbase-6e13f4b3e03a055bafc78037b0bf68d90fbbe98d.tar.gz |
Load all available pixmaps in an icon file.
Fixes the problem that only the first icon would be read from an .ico
file with muliple icons of various sizes in it.
Task-number: QTBUG-28267
Change-Id: I50daa89769054234e9ffc5246f59b46975948871
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
-rw-r--r-- | src/gui/image/qicon.cpp | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index c1a8cfaa1e..0a4b50bbea 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -43,6 +43,7 @@ #include "qicon_p.h" #include "qiconengine.h" #include "qiconengineplugin.h" +#include "qimagereader.h" #include "private/qfactoryloader_p.h" #include "private/qiconloader_p.h" #include "qpainter.h" @@ -365,37 +366,40 @@ void QPixmapIconEngine::addPixmap(const QPixmap &pixmap, QIcon::Mode mode, QIcon void QPixmapIconEngine::addFile(const QString &fileName, const QSize &_size, QIcon::Mode mode, QIcon::State state) { if (!fileName.isEmpty()) { - QSize size = _size; - QPixmap pixmap; - QString abs = fileName; if (fileName.at(0) != QLatin1Char(':')) abs = QFileInfo(fileName).absoluteFilePath(); - - for (int i = 0; i < pixmaps.count(); ++i) { - if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) { - QPixmapIconEngineEntry *pe = &pixmaps[i]; - if(size == QSize()) { - pixmap = QPixmap(abs); - size = pixmap.size(); - } - if (pe->size == QSize() && pe->pixmap.isNull()) { - pe->pixmap = QPixmap(pe->fileName); - // Reset the devicePixelRatio. The pixmap may be loaded from a @2x file, - // but be used as a 1x pixmap by QIcon. - pe->pixmap.setDevicePixelRatio(1.0); - pe->size = pe->pixmap.size(); - } - if(pe->size == size) { - pe->pixmap = pixmap; - pe->fileName = abs; - return; + QImageReader reader(abs); + + do { + QSize size = _size; + QPixmap pixmap; + + for (int i = 0; i < pixmaps.count(); ++i) { + if (pixmaps.at(i).mode == mode && pixmaps.at(i).state == state) { + QPixmapIconEngineEntry *pe = &pixmaps[i]; + if (size == QSize()) { + pixmap.convertFromImage(reader.read()); + size = pixmap.size(); + } + if (pe->size == QSize() && pe->pixmap.isNull()) { + pe->pixmap = QPixmap(pe->fileName); + // Reset the devicePixelRatio. The pixmap may be loaded from a @2x file, + // but be used as a 1x pixmap by QIcon. + pe->pixmap.setDevicePixelRatio(1.0); + pe->size = pe->pixmap.size(); + } + if (pe->size == size) { + pe->pixmap = pixmap; + pe->fileName = abs; + return; + } } } - } - QPixmapIconEngineEntry e(abs, size, mode, state); - e.pixmap = pixmap; - pixmaps += e; + QPixmapIconEngineEntry e(abs, size, mode, state); + e.pixmap = pixmap; + pixmaps += e; + } while (reader.jumpToNextImage()); } } |