Add XDG file icon support for UNIX themes
Add helper class XdgFileIconHelper using the icon theme engine to implement QPlatformTheme::fileIconPixmap(). [ChangeLog][QtPlatformSupport] KDE/Gnome themes now implement QPlatformTheme::fileIconPixmap(), showing file icons. Change-Id: I32a948ece08305053ebadb3ace6cbc6fbd339946 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
40bb2d29b9
commit
46ea82188e
|
|
@ -50,6 +50,7 @@
|
|||
#include <QtCore/QFile>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QMimeDatabase>
|
||||
#include <QtCore/QLoggingCategory>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QVariant>
|
||||
|
|
@ -231,6 +232,28 @@ QVariant QGenericUnixTheme::themeHint(ThemeHint hint) const
|
|||
return QPlatformTheme::themeHint(hint);
|
||||
}
|
||||
|
||||
// Helper functions for implementing QPlatformTheme::fileIcon() for XDG icon themes.
|
||||
static QList<QSize> availableXdgFileIconSizes()
|
||||
{
|
||||
return QIcon::fromTheme(QStringLiteral("inode-directory")).availableSizes();
|
||||
}
|
||||
|
||||
static QIcon xdgFileIcon(const QFileInfo &fileInfo)
|
||||
{
|
||||
QMimeDatabase mimeDatabase;
|
||||
QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileInfo);
|
||||
if (!mimeType.isValid())
|
||||
return QIcon();
|
||||
const QString &iconName = mimeType.iconName();
|
||||
if (!iconName.isEmpty()) {
|
||||
const QIcon icon = QIcon::fromTheme(iconName);
|
||||
if (!icon.isNull())
|
||||
return icon;
|
||||
}
|
||||
const QString &genericIconName = mimeType.genericIconName();
|
||||
return genericIconName.isEmpty() ? QIcon() : QIcon::fromTheme(genericIconName);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_SETTINGS
|
||||
class QKdeThemePrivate : public QPlatformThemePrivate
|
||||
{
|
||||
|
|
@ -506,6 +529,8 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const
|
|||
return QVariant(d->iconFallbackThemeName);
|
||||
case QPlatformTheme::IconThemeSearchPaths:
|
||||
return QVariant(d->kdeIconThemeSearchPaths(d->kdeDirs));
|
||||
case QPlatformTheme::IconPixmapSizes:
|
||||
return QVariant::fromValue(availableXdgFileIconSizes());
|
||||
case QPlatformTheme::StyleNames:
|
||||
return QVariant(d->styleNames);
|
||||
case QPlatformTheme::KeyboardScheme:
|
||||
|
|
@ -520,6 +545,11 @@ QVariant QKdeTheme::themeHint(QPlatformTheme::ThemeHint hint) const
|
|||
return QPlatformTheme::themeHint(hint);
|
||||
}
|
||||
|
||||
QIcon QKdeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions) const
|
||||
{
|
||||
return xdgFileIcon(fileInfo);
|
||||
}
|
||||
|
||||
const QPalette *QKdeTheme::palette(Palette type) const
|
||||
{
|
||||
Q_D(const QKdeTheme);
|
||||
|
|
@ -657,6 +687,8 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const
|
|||
return QVariant(QStringLiteral("gnome"));
|
||||
case QPlatformTheme::IconThemeSearchPaths:
|
||||
return QVariant(QGenericUnixTheme::xdgIconThemePaths());
|
||||
case QPlatformTheme::IconPixmapSizes:
|
||||
return QVariant::fromValue(availableXdgFileIconSizes());
|
||||
case QPlatformTheme::StyleNames: {
|
||||
QStringList styleNames;
|
||||
styleNames << QStringLiteral("fusion") << QStringLiteral("windows");
|
||||
|
|
@ -674,6 +706,11 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const
|
|||
return QPlatformTheme::themeHint(hint);
|
||||
}
|
||||
|
||||
QIcon QGnomeTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions) const
|
||||
{
|
||||
return xdgFileIcon(fileInfo);
|
||||
}
|
||||
|
||||
const QFont *QGnomeTheme::font(Font type) const
|
||||
{
|
||||
Q_D(const QGnomeTheme);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,9 @@ public:
|
|||
static QPlatformTheme *createKdeTheme();
|
||||
QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE;
|
||||
|
||||
QIcon fileIcon(const QFileInfo &fileInfo,
|
||||
QPlatformTheme::IconOptions iconOptions = 0) const override;
|
||||
|
||||
const QPalette *palette(Palette type = SystemPalette) const Q_DECL_OVERRIDE;
|
||||
|
||||
const QFont *font(Font type) const Q_DECL_OVERRIDE;
|
||||
|
|
@ -129,6 +132,8 @@ class QGnomeTheme : public QPlatformTheme
|
|||
public:
|
||||
QGnomeTheme();
|
||||
QVariant themeHint(ThemeHint hint) const Q_DECL_OVERRIDE;
|
||||
QIcon fileIcon(const QFileInfo &fileInfo,
|
||||
QPlatformTheme::IconOptions = 0) const override;
|
||||
const QFont *font(Font type) const Q_DECL_OVERRIDE;
|
||||
QString standardButtonText(int button) const Q_DECL_OVERRIDE;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue