summaryrefslogtreecommitdiff
path: root/src/gui/image/qicon.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-08-26 11:57:21 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-08-30 07:52:19 +0000
commit710ff392d95fb2888c14ea273f4d65ced908fe49 (patch)
treed0a0221dc8e789e2b48adc460cfb69d5f7f81f7e /src/gui/image/qicon.cpp
parentcc74452d6d259d36ac47c536f11a5efb269e8e44 (diff)
downloadqtbase-710ff392d95fb2888c14ea273f4d65ced908fe49.tar.gz
QIcon::addFile(): Invoke QMimeDatabase when matching by suffix fails
This will detect image files correctly even if case resource aliases without suffixed are used. Task-number: QTBUG-55388 Change-Id: I337ca1f6be7126fe731e5e278b23aaef6cdfd9ef Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src/gui/image/qicon.cpp')
-rw-r--r--src/gui/image/qicon.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 62ec8e93b2..716a7c52c2 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -47,6 +47,8 @@
#include "private/qiconloader_p.h"
#include "qpainter.h"
#include "qfileinfo.h"
+#include <qmimedatabase.h>
+#include <qmimetype.h>
#include "qpixmapcache.h"
#include "qvariant.h"
#include "qcache.h"
@@ -976,6 +978,18 @@ void QIcon::addPixmap(const QPixmap &pixmap, Mode mode, State state)
d->engine->addPixmap(pixmap, mode, state);
}
+static QIconEngine *iconEngineFromSuffix(const QString &fileName, const QString &suffix)
+{
+ if (!suffix.isEmpty()) {
+ const int index = loader()->indexOf(suffix);
+ if (index != -1) {
+ if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))) {
+ return factory->create(fileName);
+ }
+ }
+ }
+ return nullptr;
+}
/*! Adds an image from the file with the given \a fileName to the
icon, as a specialization for \a size, \a mode and \a state. The
@@ -1013,25 +1027,15 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
return;
detach();
if (!d) {
+
QFileInfo info(fileName);
- QString suffix = info.suffix();
- if (!suffix.isEmpty()) {
- // first try version 2 engines..
- const int index = loader()->indexOf(suffix);
- if (index != -1) {
- if (QIconEnginePlugin *factory = qobject_cast<QIconEnginePlugin*>(loader()->instance(index))) {
- if (QIconEngine *engine = factory->create(fileName)) {
- d = new QIconPrivate;
- d->engine = engine;
- }
- }
- }
- }
- // ...then fall back to the default engine
- if (!d) {
- d = new QIconPrivate;
- d->engine = new QPixmapIconEngine;
- }
+ QIconEngine *engine = iconEngineFromSuffix(fileName, info.suffix());
+#ifndef QT_NO_MIMETYPE
+ if (!engine)
+ engine = iconEngineFromSuffix(fileName, QMimeDatabase().mimeTypeForFile(info).preferredSuffix());
+#endif // !QT_NO_MIMETYPE
+ d = new QIconPrivate;
+ d->engine = engine ? engine : new QPixmapIconEngine;
}
d->engine->addFile(fileName, size, mode, state);