Commit 1cf1700d authored by Tobias Hunger's avatar Tobias Hunger

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's avatarTim Jenssen <tim.jenssen@qt.io>
parent bae73e72
......@@ -31,8 +31,6 @@
#include <utils/algorithm.h>
#include <QApplication>
using namespace CMakeProjectManager;
using namespace CMakeProjectManager::Internal;
......@@ -57,13 +55,7 @@ bool CMakeInputsNode::showInSimpleTree() const
CMakeListsNode::CMakeListsNode(const Utils::FileName &cmakeListPath) :
ProjectExplorer::ProjectNode(cmakeListPath)
{
static QIcon folderIcon;
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));
}
static QIcon folderIcon = Core::FileIconProvider::directoryIcon(Constants::FILEOVERLAY_CMAKE);
setIcon(folderIcon);
}
......
......@@ -217,5 +217,18 @@ void registerIconOverlayForFilename(const QString &path, const QString &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 Core
......@@ -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 QIcon &icon, const QString &mimeType);
CORE_EXPORT QIcon directoryIcon(const QString &overlay);
} // namespace FileIconProvider
} // namespace Core
......@@ -43,7 +43,6 @@
#include <QtDebug>
#include <QDir>
#include <QIcon>
#include <QStyle>
using namespace ProjectExplorer;
......@@ -51,19 +50,6 @@ using namespace ProjectExplorer;
// 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 Internal {
......@@ -375,7 +361,7 @@ QbsProductNode::QbsProductNode(const qbs::ProductData &prd) :
QbsBaseProjectNode(Utils::FileName::fromString(prd.location().filePath())),
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);
}
......@@ -468,7 +454,7 @@ QList<ProjectExplorer::RunConfiguration *> QbsProductNode::runConfigurations() c
QbsProjectNode::QbsProjectNode(const Utils::FileName &projectDirectory) :
QbsBaseProjectNode(projectDirectory)
{
static QIcon projectIcon = generateIcon(QString(ProjectExplorer::Constants::FILEOVERLAY_QT));
static QIcon projectIcon = Core::FileIconProvider::directoryIcon(ProjectExplorer::Constants::FILEOVERLAY_QT);
setIcon(projectIcon);
}
......
......@@ -37,9 +37,6 @@
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QApplication>
#include <QStyle>
using namespace Core;
using namespace ProjectExplorer;
using namespace QtSupport;
......@@ -106,23 +103,15 @@ QmakeStaticData::QmakeStaticData()
const unsigned count = sizeof(fileTypeDataStorage)/sizeof(FileTypeDataStorage);
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) {
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 filter = QString::fromUtf8(fileTypeDataStorage[i].addFileFilter);
fileTypeData.push_back(QmakeStaticData::FileTypeData(fileTypeDataStorage[i].type,
desc, filter, folderIcon));
desc, filter,
Core::FileIconProvider::directoryIcon(QLatin1String(fileTypeDataStorage[i].icon))));
}
// Project icon
const QIcon projectBaseIcon(ProjectExplorer::Constants::FILEOVERLAY_QT);
const QPixmap projectPixmap = FileIconProvider::overlayIcon(dirPixmap, projectBaseIcon);
projectIcon.addPixmap(projectPixmap);
projectIcon = Core::FileIconProvider::directoryIcon(ProjectExplorer::Constants::FILEOVERLAY_QT);
qAddPostRoutine(clearQmakeStaticData);
}
......
......@@ -32,8 +32,6 @@
#include <utils/algorithm.h>
#include <QStyle>
using namespace ProjectExplorer;
namespace QmlProjectManager {
......@@ -43,13 +41,9 @@ QmlProjectNode::QmlProjectNode(QmlProject *project) : ProjectNode(project->proje
m_project(project)
{
setDisplayName(project->projectFilePath().toFileInfo().completeBaseName());
// make overlay
const QSize desiredSize = QSize(16, 16);
const QIcon projectBaseIcon(QLatin1String(":/qmlproject/images/qmlfolder.png"));
const QPixmap projectPixmap = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
projectBaseIcon,
desiredSize);
setIcon(QIcon(projectPixmap));
static QIcon qmlProjectIcon = Core::FileIconProvider::directoryIcon(QLatin1String(":/qmlproject/images/qmlfolder.png"));
setIcon(qmlProjectIcon);
}
bool QmlProjectNode::showInSimpleTree() const
......
......@@ -564,8 +564,8 @@ void ResourceFile::clearPrefixList()
ResourceModel::ResourceModel(QObject *parent)
: QAbstractItemModel(parent), m_dirty(false)
{
m_prefixIcon = Core::FileIconProvider::overlayIcon(QStyle::SP_DirIcon,
QIcon(QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QRC)), QSize(16, 16));
static QIcon resourceFolderIcon = Core::FileIconProvider::directoryIcon(QLatin1String(ProjectExplorer::Constants::FILEOVERLAY_QRC));
m_prefixIcon = resourceFolderIcon;
}
void ResourceModel::setDirty(bool b)
......
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