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>
This commit is contained in:
parent
97fd5399bc
commit
6e13f4b3e0
@ -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();
|
||||
QImageReader reader(abs);
|
||||
|
||||
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;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user