forked from qt-creator/qt-creator
QmakePM: Avoid multiple loads of the same standard icon
Loading a standard icon is expensive. Change-Id: Ic6bae20c9d0bdcb07fda48309bebcc3a959bc031 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
f900b4e1ba
commit
925492a1b3
@@ -149,17 +149,26 @@ QIcon icon(QFileIconProvider::IconType type)
|
||||
return instance()->icon(type);
|
||||
}
|
||||
|
||||
/*!
|
||||
Creates a pixmap with baseicon and overlays overlayIcon over it.
|
||||
See platform note in class documentation about recommended usage.
|
||||
*/
|
||||
QPixmap overlayIcon(const QPixmap &baseIcon, const QIcon &overlayIcon)
|
||||
{
|
||||
QPixmap iconPixmap = baseIcon;
|
||||
QPainter painter(&iconPixmap);
|
||||
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 &overlayIcon, const QSize &size)
|
||||
QPixmap overlayIcon(QStyle::StandardPixmap baseIcon, const QIcon &overlay, const QSize &size)
|
||||
{
|
||||
QPixmap iconPixmap = qApp->style()->standardIcon(baseIcon).pixmap(size);
|
||||
QPainter painter(&iconPixmap);
|
||||
painter.drawPixmap(0, 0, overlayIcon.pixmap(size));
|
||||
painter.end();
|
||||
return iconPixmap;
|
||||
return overlayIcon(qApp->style()->standardIcon(baseIcon).pixmap(size), overlay);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user