diff options
author | Sérgio Martins <sergio.martins@kdab.com> | 2013-04-29 12:58:23 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-09 14:56:32 +0200 |
commit | 46685f755b01288fd53c4483cb97a22c426a57f0 (patch) | |
tree | b18c0a65dd82dd7717879dafa34e3b04c11c2e4b /src/widgets/itemviews/qfileiconprovider.cpp | |
parent | 0e9ea64edcdb451ffcfbf055174354e6c8f2df88 (diff) |
Windows: Introduce QFileDialog::DontUseCustomDirectoryIcons
Folders can have a custom icon, set by the user. Some system
folders also have one, for example c:\windows\fonts.
This option allows you to disable this behavior, you'll get the
folder directory icon.
As a side-effect, you'll get a very big performance improvement
on removable/network media: 2 seconds vs 60 seconds on a SDCard
with 10000 folders.
Change-Id: Id55ea628186e0a6523585ec7a4ff622d6f5da505
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/widgets/itemviews/qfileiconprovider.cpp')
-rw-r--r-- | src/widgets/itemviews/qfileiconprovider.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/widgets/itemviews/qfileiconprovider.cpp b/src/widgets/itemviews/qfileiconprovider.cpp index b435639390..f03d9fb81b 100644 --- a/src/widgets/itemviews/qfileiconprovider.cpp +++ b/src/widgets/itemviews/qfileiconprovider.cpp @@ -83,6 +83,16 @@ QT_BEGIN_NAMESPACE \value File */ + +/*! + \enum QFileIconProvider::Option + \since 5.2 + + \value DontUseCustomDirectoryIcons Always use the default directory icon. + Some platforms allow the user to set a different icon. Custom icon lookup + cause a big performance impact over network or removable drives. +*/ + class QFileIconProviderPrivate { Q_DECLARE_PUBLIC(QFileIconProvider) @@ -94,6 +104,7 @@ public: QFileIconProvider *q_ptr; const QString homePath; + QFileIconProvider::Options options; private: mutable QIcon file; @@ -193,6 +204,31 @@ QFileIconProvider::~QFileIconProvider() } /*! + \since 5.2 + Sets \a options that affect the icon provider. + \sa options() +*/ + +void QFileIconProvider::setOptions(QFileIconProvider::Options options) +{ + Q_D(QFileIconProvider); + d->options = options; +} + +/*! + \since 5.2 + Returns all the options that affect the icon provider. + By default, all options are disabled. + \sa setOptions() +*/ + +QFileIconProvider::Options QFileIconProvider::options() const +{ + Q_D(const QFileIconProvider); + return d->options; +} + +/*! Returns an icon set for the given \a type. */ @@ -228,6 +264,7 @@ static bool isCacheable(const QFileInfo &fi) #ifdef Q_OS_WIN // On windows it's faster to just look at the file extensions. QTBUG-13182 const QString fileExtension = fi.suffix(); + // Will return false for .exe, .lnk and .ico extensions return fileExtension.compare(QLatin1String("exe"), Qt::CaseInsensitive) && fileExtension.compare(QLatin1String("lnk"), Qt::CaseInsensitive) && fileExtension.compare(QLatin1String("ico"), Qt::CaseInsensitive); @@ -247,7 +284,6 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const if (sizes.isEmpty()) return retIcon; - const QString fileExtension = fi.suffix().toUpper(); const QString keyBase = QLatin1String("qt_.") + fi.suffix().toUpper(); bool cacheable = isCacheable(fi); @@ -269,8 +305,12 @@ QIcon QFileIconProviderPrivate::getIcon(const QFileInfo &fi) const } } + QPlatformTheme::IconOptions iconOptions; + if (options & QFileIconProvider::DontUseCustomDirectoryIcons) + iconOptions |= QPlatformTheme::DontUseCustomDirectoryIcons; + Q_FOREACH (int size, sizes) { - QPixmap pixmap = theme->fileIconPixmap(fi, QSizeF(size, size)); + QPixmap pixmap = theme->fileIconPixmap(fi, QSizeF(size, size), iconOptions); if (!pixmap.isNull()) { retIcon.addPixmap(pixmap); if (cacheable) |