summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-07-27 11:57:46 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-08-04 14:31:15 +0000
commit40bb2d29b92c28c662a94b77a8170567aba087ab (patch)
tree8bf2ae8ceed43013b04b9d59682b2d80f142d0b7 /src/widgets
parent2079081dcf6968690d0c8c50c46531c31989ffd4 (diff)
Add QPlatformTheme::fileIcon()
Add a way to return an icon instead of a pixmap of a specific size for a file for usage by QFileIconProvider, etc. Fall back to fileIconPixmap() if fileIcon() returns a null icon. This allows for supporting XDG theme icons and Qt Quick applications accessing file icons. Change-Id: I9ffbd6602e1a6a490c0046d950636447c5127474 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/itemviews/qfileiconprovider.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp
index 78ff5f79ab..5638e438d5 100644
--- a/src/widgets/itemviews/qfileiconprovider.cpp
+++ b/src/widgets/itemviews/qfileiconprovider.cpp
@@ -62,6 +62,14 @@ QT_BEGIN_NAMESPACE
static bool isCacheable(const QFileInfo &fi);
+static QPlatformTheme::IconOptions toThemeIconOptions(QFileIconProvider::Options options)
+{
+ QPlatformTheme::IconOptions result;
+ if (options & QFileIconProvider::DontUseCustomDirectoryIcons)
+ result |= QPlatformTheme::DontUseCustomDirectoryIcons;
+ return result;
+}
+
class QFileIconEngine : public QPixmapIconEngine
{
public:
@@ -91,11 +99,7 @@ public:
return pixmap;
}
- QPlatformTheme::IconOptions iconOptions;
- if (m_fipOpts & QFileIconProvider::DontUseCustomDirectoryIcons)
- iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons;
-
- pixmap = theme->fileIconPixmap(m_fileInfo, size, iconOptions);
+ pixmap = theme->fileIconPixmap(m_fileInfo, size, toThemeIconOptions(m_fipOpts));
if (!pixmap.isNull()) {
if (cacheable)
QPixmapCache::insert(keyBase + QString::number(size.width()), pixmap);
@@ -345,11 +349,12 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const
if (!theme)
return QIcon();
- QList<int> sizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >();
- if (sizes.isEmpty())
- return QIcon();
+ QIcon themeFileIcon = theme->fileIcon(fi, toThemeIconOptions(options));
+ if (!themeFileIcon.isNull())
+ return themeFileIcon;
- return QIcon(new QFileIconEngine(fi, options));
+ QList<int> sizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<int> >();
+ return sizes.isEmpty() ? QIcon() : QIcon(new QFileIconEngine(fi, options));
}
/*!