Commit 925492a1 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

QmakePM: Avoid multiple loads of the same standard icon

Loading a standard icon is expensive.

Change-Id: Ic6bae20c9d0bdcb07fda48309bebcc3a959bc031
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent f900b4e1
......@@ -150,18 +150,27 @@ QIcon icon(QFileIconProvider::IconType type)
}
/*!
Creates a pixmap with baseicon at size and overlays overlayIcon over it.
Creates a pixmap with baseicon and overlays overlayIcon over it.
See platform note in class documentation about recommended usage.
*/
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size)
QPixmap overlayIcon(const QPixmap &baseIcon, const QIcon &overlayIcon)
{
QPixmap iconPixmap = qApp->style()->standardIcon(baseIcon).pixmap(size);
QPixmap iconPixmap = baseIcon;
QPainter painter(&iconPixmap);
painter.drawPixmap(0, 0, overlayIcon.pixmap(size));
painter.drawPixmap(0, 0, overlayIcon.pixmap(baseIcon.size()));
painter.end();
return iconPixmap;
}
/*!
Creates a pixmap with baseicon at size and overlays overlayIcon over it.
See platform note in class documentation about recommended usage.
*/
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlay, const QSize &size)
{
return overlayIcon(qApp->style()->standardIcon(baseIcon).pixmap(size), overlay);
}
/*!
Registers an icon for a given suffix, overlaying the system file icon.
See platform note in class documentation about recommended usage.
......
......@@ -43,6 +43,7 @@ CORE_EXPORT QIcon icon(const QFileInfo &info);
CORE_EXPORT QIcon icon(QFileIconProvider::IconType type);
// Register additional overlay icons
CORE_EXPORT QPixmap overlayIcon(const QPixmap &baseIcon, const QIcon &overlayIcon);
CORE_EXPORT QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlayIcon, const QSize &size);
CORE_EXPORT void registerIconOverlayForSuffix(const char *path, const char *suffix);
CORE_EXPORT void registerIconOverlayForMimeType(const char *path, const char *mimeType);
......
......@@ -66,6 +66,7 @@
#include <proparser/prowriter.h>
#include <proparser/qmakevfs.h>
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QFile>
......@@ -155,16 +156,14 @@ QmakeNodeStaticData::QmakeNodeStaticData()
// Overlay the SP_DirIcon with the custom icons
const QSize desiredSize = QSize(16, 16);
const QPixmap dirPixmap = qApp->style()->standardIcon(QStyle::SP_DirIcon).pixmap(desiredSize);
for (unsigned i = 0 ; i < count; ++i) {
QIcon overlayIcon;
const QString iconFile = creatorTheme()->imageFile(fileTypeDataStorage[i].themeImage,
QString::fromLatin1(fileTypeDataStorage[i].icon));
overlayIcon = QIcon(iconFile);
const QPixmap folderPixmap =
Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
overlayIcon, desiredSize);
QIcon folderIcon;
folderIcon.addPixmap(folderPixmap);
folderIcon.addPixmap(FileIconProvider::overlayIcon(dirPixmap, overlayIcon));
const QString desc = QCoreApplication::translate("QmakeProjectManager::QmakePriFileNode", fileTypeDataStorage[i].typeName);
const QString filter = QString::fromUtf8(fileTypeDataStorage[i].addFileFilter);
fileTypeData.push_back(QmakeNodeStaticData::FileTypeData(fileTypeDataStorage[i].type,
......@@ -174,9 +173,7 @@ QmakeNodeStaticData::QmakeNodeStaticData()
const QString fileName = creatorTheme()->imageFile(Theme::ProjectFileIcon,
QLatin1String(":/qtsupport/images/qt_project.png"));
const QIcon projectBaseIcon(fileName);
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
projectBaseIcon,
desiredSize);
const QPixmap projectPixmap = FileIconProvider::overlayIcon(dirPixmap, projectBaseIcon);
projectIcon.addPixmap(projectPixmap);
qAddPostRoutine(clearQmakeNodeStaticData);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment