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>bb10
parent
2079081dcf
commit
40bb2d29b9
|
|
@ -44,6 +44,7 @@
|
|||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/qfileinfo.h>
|
||||
#include <qicon.h>
|
||||
#include <qpalette.h>
|
||||
#include <qtextformat.h>
|
||||
#include <private/qiconloader_p.h>
|
||||
|
|
@ -405,6 +406,24 @@ QPixmap QPlatformTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) co
|
|||
return QPixmap();
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Return an icon for \a fileInfo, observing \a iconOptions.
|
||||
|
||||
This function is queried by QFileIconProvider and similar classes to obtain
|
||||
an icon for a file. If it does not return a non-null icon, fileIconPixmap()
|
||||
is queried for a specific size.
|
||||
|
||||
\since 5.8
|
||||
*/
|
||||
|
||||
QIcon QPlatformTheme::fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions iconOptions) const
|
||||
{
|
||||
Q_UNUSED(fileInfo);
|
||||
Q_UNUSED(iconOptions);
|
||||
// TODO Should return QCommonStyle pixmaps?
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
QPixmap QPlatformTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size,
|
||||
QPlatformTheme::IconOptions iconOptions) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@
|
|||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIcon;
|
||||
class QIconEngine;
|
||||
class QMenu;
|
||||
class QMenuBar;
|
||||
|
|
@ -301,6 +302,8 @@ public:
|
|||
virtual QVariant themeHint(ThemeHint hint) const;
|
||||
|
||||
virtual QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const;
|
||||
virtual QIcon fileIcon(const QFileInfo &fileInfo,
|
||||
QPlatformTheme::IconOptions iconOptions = 0) const;
|
||||
virtual QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size,
|
||||
QPlatformTheme::IconOptions iconOptions = 0) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
Loading…
Reference in New Issue