From fc6b21436347f21c8a228bb0e256d946936095a2 Mon Sep 17 00:00:00 2001 From: Kevin Ottens Date: Fri, 1 Feb 2013 08:15:50 +0100 Subject: Let QPlatformTheme decide which engine QIcon::fromTheme uses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default we still use QIconLoaderEngine but now platform theme plugins have the opportunity to override that. It is in particular planned to be used in a WIP platform theme plugin for KDE sessions. Change-Id: I07a82dc91daea44709b3a790f3f6e2a7a090d108 Reviewed-by: Olivier Goffart Reviewed-by: Friedemann Kleint Reviewed-by: David Faure (KDE) Reviewed-by: Samuel Rødal Reviewed-by: Frederik Gladhorn --- src/gui/image/qicon.cpp | 6 +++++- src/gui/kernel/qplatformtheme.cpp | 16 ++++++++++++++++ src/gui/kernel/qplatformtheme.h | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index dce902301c..6b91ead666 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -60,6 +60,7 @@ #include "private/qhexstring_p.h" #include "private/qguiapplication_p.h" +#include "qpa/qplatformtheme.h" #ifndef QT_NO_ICON QT_BEGIN_NAMESPACE @@ -986,7 +987,10 @@ QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback) if (qtIconCache()->contains(name)) { icon = *qtIconCache()->object(name); } else { - QIcon *cachedIcon = new QIcon(new QIconLoaderEngine(name)); + QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); + QIconEngine * const engine = platformTheme ? platformTheme->createIconEngine(name) + : new QIconLoaderEngine(name); + QIcon *cachedIcon = new QIcon(engine); qtIconCache()->insert(name, cachedIcon); icon = *cachedIcon; } diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index ceb95c51e8..9f5c789a6e 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -46,6 +46,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -272,4 +273,19 @@ QPlatformSystemTrayIcon *QPlatformTheme::createPlatformSystemTrayIcon() const } #endif +/*! + Factory function for the QIconEngine used by QIcon::fromTheme(). By default this + function returns a QIconLoaderEngine, but subclasses can reimplement it to + provide their own. + + It is especially useful to benefit from some platform specific facilities or + optimizations like an inter-process cache in systems mostly built with Qt. + + \since 5.1 +*/ +QIconEngine *QPlatformTheme::createIconEngine(const QString &iconName) const +{ + return new QIconLoaderEngine(iconName); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index 14e2dac19d..0e95321102 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -55,6 +55,7 @@ QT_BEGIN_NAMESPACE +class QIconEngine; class QMenu; class QMenuBar; class QPlatformMenuItem; @@ -270,6 +271,8 @@ public: virtual QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const; virtual QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size) const; + virtual QIconEngine *createIconEngine(const QString &iconName) const; + static QVariant defaultThemeHint(ThemeHint hint); }; -- cgit v1.2.3