Core::FileIconProvider: Add helper method to get a directory icon with overlay

Add a helper method to request a directory icon with an overlay icon for the
project tree.

Change-Id: Idea2ea9ec2ea6790bf8d087723700364fbcafec6
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Tobias Hunger
2017-09-06 11:32:15 +02:00
parent bae73e7246
commit 1cf1700d1c
7 changed files with 26 additions and 50 deletions

View File

@@ -31,8 +31,6 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <QApplication>
using namespace CMakeProjectManager; using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal; using namespace CMakeProjectManager::Internal;
@@ -57,13 +55,7 @@ bool CMakeInputsNode::showInSimpleTree() const
CMakeListsNode::CMakeListsNode(const Utils::FileName &cmakeListPath) : CMakeListsNode::CMakeListsNode(const Utils::FileName &cmakeListPath) :
ProjectExplorer::ProjectNode(cmakeListPath) ProjectExplorer::ProjectNode(cmakeListPath)
{ {
static QIcon folderIcon; static QIcon folderIcon = Core::FileIconProvider::directoryIcon(Constants::FILEOVERLAY_CMAKE);
if (folderIcon.isNull()) {
const QIcon overlayIcon(Constants::FILEOVERLAY_CMAKE);
QPixmap dirPixmap = QApplication::style()->standardIcon(QStyle::SP_DirIcon).pixmap(QSize(16, 16));
folderIcon.addPixmap(Core::FileIconProvider::overlayIcon(dirPixmap, overlayIcon));
}
setIcon(folderIcon); setIcon(folderIcon);
} }

View File

@@ -217,5 +217,18 @@ void registerIconOverlayForFilename(const QString &path, const QString &filename
instance()->registerIconOverlayForFilename(QIcon(path), filename); instance()->registerIconOverlayForFilename(QIcon(path), filename);
} }
// Return a standard directory icon with the specified overlay:
QIcon directoryIcon(const QString &overlay)
{
// Overlay the SP_DirIcon with the custom icons
const QSize desiredSize = QSize(16, 16);
const QPixmap dirPixmap = QApplication::style()->standardIcon(QStyle::SP_DirIcon).pixmap(desiredSize);
const QIcon overlayIcon(overlay);
QIcon result;
result.addPixmap(Core::FileIconProvider::overlayIcon(dirPixmap, overlayIcon));
return result;
}
} // namespace FileIconProvider } // namespace FileIconProvider
} // namespace Core } // namespace Core

View File

@@ -49,5 +49,7 @@ CORE_EXPORT void registerIconOverlayForFilename(const QString &path, const QStri
CORE_EXPORT void registerIconOverlayForMimeType(const QString &path, const QString &mimeType); CORE_EXPORT void registerIconOverlayForMimeType(const QString &path, const QString &mimeType);
CORE_EXPORT void registerIconOverlayForMimeType(const QIcon &icon, const QString &mimeType); CORE_EXPORT void registerIconOverlayForMimeType(const QIcon &icon, const QString &mimeType);
CORE_EXPORT QIcon directoryIcon(const QString &overlay);
} // namespace FileIconProvider } // namespace FileIconProvider
} // namespace Core } // namespace Core

View File

@@ -43,7 +43,6 @@
#include <QtDebug> #include <QtDebug>
#include <QDir> #include <QDir>
#include <QIcon> #include <QIcon>
#include <QStyle>
using namespace ProjectExplorer; using namespace ProjectExplorer;
@@ -51,19 +50,6 @@ using namespace ProjectExplorer;
// Helpers: // Helpers:
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
static QIcon generateIcon(const QString &overlay)
{
const QSize desiredSize = QSize(16, 16);
const QIcon overlayIcon(overlay);
const QPixmap pixmap
= Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon, overlayIcon, desiredSize);
QIcon result;
result.addPixmap(pixmap);
return result;
}
namespace QbsProjectManager { namespace QbsProjectManager {
namespace Internal { namespace Internal {
@@ -375,7 +361,7 @@ QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
QbsBaseProjectNode(Utils::FileName::fromString(prd.location().filePath())), QbsBaseProjectNode(Utils::FileName::fromString(prd.location().filePath())),
m_qbsProductData(prd) m_qbsProductData(prd)
{ {
static QIcon productIcon = generateIcon(QString(Constants::QBS_PRODUCT_OVERLAY_ICON)); static QIcon productIcon = Core::FileIconProvider::directoryIcon(Constants::QBS_PRODUCT_OVERLAY_ICON);
setIcon(productIcon); setIcon(productIcon);
} }
@@ -468,7 +454,7 @@ QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurations() c
QbsProjectNode::QbsProjectNode(const Utils::FileName &projectDirectory) : QbsProjectNode::QbsProjectNode(const Utils::FileName &projectDirectory) :
QbsBaseProjectNode(projectDirectory) QbsBaseProjectNode(projectDirectory)
{ {
static QIcon projectIcon = generateIcon(QString(ProjectExplorer::Constants::FILEOVERLAY_QT)); static QIcon projectIcon = Core::FileIconProvider::directoryIcon(ProjectExplorer::Constants::FILEOVERLAY_QT);
setIcon(projectIcon); setIcon(projectIcon);
} }

View File

@@ -37,9 +37,6 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QApplication>
#include <QStyle>
using namespace Core; using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace QtSupport; using namespace QtSupport;
@@ -106,23 +103,15 @@ QmakeStaticData::QmakeStaticData()
const unsigned count = sizeof(fileTypeDataStorage)/sizeof(FileTypeDataStorage); const unsigned count = sizeof(fileTypeDataStorage)/sizeof(FileTypeDataStorage);
fileTypeData.reserve(count); fileTypeData.reserve(count);
// Overlay the SP_DirIcon with the custom icons
const QSize desiredSize = QSize(16, 16);
const QPixmap dirPixmap = QApplication::style()->standardIcon(QStyle::SP_DirIcon).pixmap(desiredSize);
for (unsigned i = 0 ; i < count; ++i) { for (unsigned i = 0 ; i < count; ++i) {
const QIcon overlayIcon(QLatin1String(fileTypeDataStorage[i].icon));
QIcon folderIcon;
folderIcon.addPixmap(FileIconProvider::overlayIcon(dirPixmap, overlayIcon));
const QString desc = QCoreApplication::translate("QmakeProjectManager::QmakePriFile", fileTypeDataStorage[i].typeName); const QString desc = QCoreApplication::translate("QmakeProjectManager::QmakePriFile", fileTypeDataStorage[i].typeName);
const QString filter = QString::fromUtf8(fileTypeDataStorage[i].addFileFilter); const QString filter = QString::fromUtf8(fileTypeDataStorage[i].addFileFilter);
fileTypeData.push_back(QmakeStaticData::FileTypeData(fileTypeDataStorage[i].type, fileTypeData.push_back(QmakeStaticData::FileTypeData(fileTypeDataStorage[i].type,
desc, filter, folderIcon)); desc, filter,
Core::FileIconProvider::directoryIcon(QLatin1String(fileTypeDataStorage[i].icon))));
} }
// Project icon // Project icon
const QIcon projectBaseIcon(ProjectExplorer::Constants::FILEOVERLAY_QT); projectIcon = Core::FileIconProvider::directoryIcon(ProjectExplorer::Constants::FILEOVERLAY_QT);
const QPixmap projectPixmap = FileIconProvider::overlayIcon(dirPixmap, projectBaseIcon);
projectIcon.addPixmap(projectPixmap);
qAddPostRoutine(clearQmakeStaticData); qAddPostRoutine(clearQmakeStaticData);
} }

View File

@@ -32,8 +32,6 @@
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <QStyle>
using namespace ProjectExplorer; using namespace ProjectExplorer;
namespace QmlProjectManager { namespace QmlProjectManager {
@@ -43,13 +41,9 @@ QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->proje
m_project(project) m_project(project)
{ {
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName()); setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
// make overlay
const QSize desiredSize = QSize(16, 16); static QIcon qmlProjectIcon = Core::FileIconProvider::directoryIcon(QLatin1String(":/qmlproject/images/qmlfolder.png"));
const QIcon projectBaseIcon(QLatin1String(":/qmlproject/images/qmlfolder.png")); setIcon(qmlProjectIcon);
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
projectBaseIcon,
desiredSize);
setIcon(QIcon(projectPixmap));
} }
bool QmlProjectNode::showInSimpleTree() const bool QmlProjectNode::showInSimpleTree() const

View File

@@ -564,8 +564,8 @@ void ResourceFile::clearPrefixList()
ResourceModel::ResourceModel(QObject *parent) ResourceModel::ResourceModel(QObject *parent)
: QAbstractItemModel(parent), m_dirty(false) : QAbstractItemModel(parent), m_dirty(false)
{ {
m_prefixIcon = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon, static QIcon resourceFolderIcon = Core::FileIconProvider::directoryIcon(QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QRC));
QIcon(QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QRC)), QSize(16, 16)); m_prefixIcon = resourceFolderIcon;
} }
void ResourceModel::setDirty(bool b) void ResourceModel::setDirty(bool b)