Let QPlatformTheme decide which engine QIcon::fromTheme uses

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 <ogoffart@woboq.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: David Faure (KDE) <faure@kde.org>
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
This commit is contained in:
Kevin Ottens 2013-02-01 08:15:50 +01:00 committed by The Qt Project
parent 388f4f16b0
commit fc6b214363
3 changed files with 24 additions and 1 deletions

View File

@ -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;
}

View File

@ -46,6 +46,7 @@
#include <QtCore/qfileinfo.h>
#include <qpalette.h>
#include <qtextformat.h>
#include <qiconloader_p.h>
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

View File

@ -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);
};