forked from qt-creator/qt-creator
Icons: Add FilePath based API
Don't completely remove the QString based API though, since many icons are constructed from constants and that would add a lot of noise with FilePath. Change-Id: I6a1b53bb1f1a79bb2b5756f94d5a2e7ca4cf0dc4 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -63,10 +63,12 @@ static MasksAndColors masksAndColors(const Icon &icon, int dpr)
|
|||||||
{
|
{
|
||||||
MasksAndColors result;
|
MasksAndColors result;
|
||||||
for (const IconMaskAndColor &i: icon) {
|
for (const IconMaskAndColor &i: icon) {
|
||||||
const QString &fileName = i.first;
|
const QString &fileName = i.first.toString();
|
||||||
const QColor color = creatorTheme()->color(i.second);
|
const QColor color = creatorTheme()->color(i.second);
|
||||||
const QString dprFileName = StyleHelper::availableImageResolutions(i.first).contains(dpr) ?
|
const QString dprFileName = StyleHelper::availableImageResolutions(i.first.toString())
|
||||||
StyleHelper::imageFileWithResolution(fileName, dpr) : fileName;
|
.contains(dpr)
|
||||||
|
? StyleHelper::imageFileWithResolution(fileName, dpr)
|
||||||
|
: fileName;
|
||||||
QPixmap pixmap;
|
QPixmap pixmap;
|
||||||
if (!pixmap.load(dprFileName)) {
|
if (!pixmap.load(dprFileName)) {
|
||||||
pixmap = QPixmap(1, 1);
|
pixmap = QPixmap(1, 1);
|
||||||
@@ -161,18 +163,30 @@ Icon::Icon(std::initializer_list<IconMaskAndColor> args, Icon::IconStyleOptions
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon::Icon(const QString &imageFileName)
|
Icon::Icon(std::initializer_list<IconStringMaskAndColor> args, Icon::IconStyleOptions style)
|
||||||
: m_style(None)
|
: m_style(style)
|
||||||
|
{
|
||||||
|
reserve(args.size());
|
||||||
|
for (const IconStringMaskAndColor &i : args)
|
||||||
|
append({FilePath::fromString(i.first), i.second});
|
||||||
|
}
|
||||||
|
|
||||||
|
Icon::Icon(const FilePath &imageFileName)
|
||||||
{
|
{
|
||||||
append({imageFileName, Theme::Color(-1)});
|
append({imageFileName, Theme::Color(-1)});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Icon::Icon(const QString &imageFileName)
|
||||||
|
: Icon(FilePath::fromString(imageFileName))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
QIcon Icon::icon() const
|
QIcon Icon::icon() const
|
||||||
{
|
{
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return QIcon();
|
return QIcon();
|
||||||
} else if (m_style == None) {
|
} else if (m_style == None) {
|
||||||
return QIcon(constFirst().first);
|
return QIcon(constFirst().first.toString());
|
||||||
} else {
|
} else {
|
||||||
QIcon result;
|
QIcon result;
|
||||||
const int maxDpr = qRound(qApp->devicePixelRatio());
|
const int maxDpr = qRound(qApp->devicePixelRatio());
|
||||||
@@ -193,7 +207,7 @@ QPixmap Icon::pixmap(QIcon::Mode iconMode) const
|
|||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
} else if (m_style == None) {
|
} else if (m_style == None) {
|
||||||
return QPixmap(StyleHelper::dpiSpecificImageFile(constFirst().first));
|
return QPixmap(StyleHelper::dpiSpecificImageFile(constFirst().first.toString()));
|
||||||
} else {
|
} else {
|
||||||
const MasksAndColors masks =
|
const MasksAndColors masks =
|
||||||
masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
||||||
@@ -204,9 +218,9 @@ QPixmap Icon::pixmap(QIcon::Mode iconMode) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Icon::imageFileName() const
|
FilePath Icon::imageFilePath() const
|
||||||
{
|
{
|
||||||
QTC_ASSERT(length() == 1, return QString());
|
QTC_ASSERT(length() == 1, return {});
|
||||||
return first().first;
|
return first().first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,8 +25,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "utils_global.h"
|
#include "fileutils.h"
|
||||||
#include "theme/theme.h"
|
#include "theme/theme.h"
|
||||||
|
#include "utils_global.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@@ -38,7 +39,8 @@ QT_FORWARD_DECLARE_CLASS(QString)
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
using IconMaskAndColor = QPair<QString, Theme::Color>;
|
using IconMaskAndColor = QPair<FilePath, Theme::Color>;
|
||||||
|
using IconStringMaskAndColor = QPair<QString, Theme::Color>;
|
||||||
|
|
||||||
// Returns a recolored icon with shadow and custom disabled state for a
|
// Returns a recolored icon with shadow and custom disabled state for a
|
||||||
// series of grayscalemask|Theme::Color mask pairs
|
// series of grayscalemask|Theme::Color mask pairs
|
||||||
@@ -59,7 +61,10 @@ public:
|
|||||||
|
|
||||||
Icon();
|
Icon();
|
||||||
Icon(std::initializer_list<IconMaskAndColor> args, IconStyleOptions style = ToolBarStyle);
|
Icon(std::initializer_list<IconMaskAndColor> args, IconStyleOptions style = ToolBarStyle);
|
||||||
|
Icon(std::initializer_list<IconStringMaskAndColor> args, IconStyleOptions style = ToolBarStyle);
|
||||||
|
Icon(const FilePath &imageFileName);
|
||||||
Icon(const QString &imageFileName);
|
Icon(const QString &imageFileName);
|
||||||
|
|
||||||
Icon(const Icon &other) = default;
|
Icon(const Icon &other) = default;
|
||||||
|
|
||||||
QIcon icon() const;
|
QIcon icon() const;
|
||||||
@@ -68,7 +73,7 @@ public:
|
|||||||
|
|
||||||
// Try to avoid it. it is just there for special API cases in Qt Creator
|
// Try to avoid it. it is just there for special API cases in Qt Creator
|
||||||
// where icons are still defined as filename.
|
// where icons are still defined as filename.
|
||||||
QString imageFileName() const;
|
FilePath imageFilePath() const;
|
||||||
|
|
||||||
// Returns either the classic or a themed icon depending on
|
// Returns either the classic or a themed icon depending on
|
||||||
// the current Theme::FlatModeIcons flag.
|
// the current Theme::FlatModeIcons flag.
|
||||||
|
@@ -300,37 +300,37 @@ const Icon MACOS_TOUCHBAR_CLEAR(
|
|||||||
|
|
||||||
QIcon CodeModelIcon::iconForType(CodeModelIcon::Type type)
|
QIcon CodeModelIcon::iconForType(CodeModelIcon::Type type)
|
||||||
{
|
{
|
||||||
static const IconMaskAndColor classRelationIcon {
|
static const IconStringMaskAndColor classRelationIcon {
|
||||||
QLatin1String(":/codemodel/images/classrelation.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
QLatin1String(":/codemodel/images/classrelation.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
||||||
static const IconMaskAndColor classRelationBackgroundIcon {
|
static const IconStringMaskAndColor classRelationBackgroundIcon {
|
||||||
QLatin1String(":/codemodel/images/classrelationbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
QLatin1String(":/codemodel/images/classrelationbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
||||||
static const IconMaskAndColor classMemberFunctionIcon {
|
static const IconStringMaskAndColor classMemberFunctionIcon {
|
||||||
QLatin1String(":/codemodel/images/classmemberfunction.png"), Theme::IconsCodeModelFunctionColor};
|
QLatin1String(":/codemodel/images/classmemberfunction.png"), Theme::IconsCodeModelFunctionColor};
|
||||||
static const IconMaskAndColor classMemberVariableIcon {
|
static const IconStringMaskAndColor classMemberVariableIcon {
|
||||||
QLatin1String(":/codemodel/images/classmembervariable.png"), Theme::IconsCodeModelVariableColor};
|
QLatin1String(":/codemodel/images/classmembervariable.png"), Theme::IconsCodeModelVariableColor};
|
||||||
static const IconMaskAndColor functionIcon {
|
static const IconStringMaskAndColor functionIcon {
|
||||||
QLatin1String(":/codemodel/images/member.png"), Theme::IconsCodeModelFunctionColor};
|
QLatin1String(":/codemodel/images/member.png"), Theme::IconsCodeModelFunctionColor};
|
||||||
static const IconMaskAndColor variableIcon {
|
static const IconStringMaskAndColor variableIcon {
|
||||||
QLatin1String(":/codemodel/images/member.png"), Theme::IconsCodeModelVariableColor};
|
QLatin1String(":/codemodel/images/member.png"), Theme::IconsCodeModelVariableColor};
|
||||||
static const IconMaskAndColor signalIcon {
|
static const IconStringMaskAndColor signalIcon {
|
||||||
QLatin1String(":/codemodel/images/signal.png"), Theme::IconsCodeModelFunctionColor};
|
QLatin1String(":/codemodel/images/signal.png"), Theme::IconsCodeModelFunctionColor};
|
||||||
static const IconMaskAndColor slotIcon {
|
static const IconStringMaskAndColor slotIcon {
|
||||||
QLatin1String(":/codemodel/images/slot.png"), Theme::IconsCodeModelFunctionColor};
|
QLatin1String(":/codemodel/images/slot.png"), Theme::IconsCodeModelFunctionColor};
|
||||||
static const IconMaskAndColor propertyIcon {
|
static const IconStringMaskAndColor propertyIcon {
|
||||||
QLatin1String(":/codemodel/images/property.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
QLatin1String(":/codemodel/images/property.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
||||||
static const IconMaskAndColor propertyBackgroundIcon {
|
static const IconStringMaskAndColor propertyBackgroundIcon {
|
||||||
QLatin1String(":/codemodel/images/propertybackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
QLatin1String(":/codemodel/images/propertybackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
||||||
static const IconMaskAndColor protectedIcon {
|
static const IconStringMaskAndColor protectedIcon {
|
||||||
QLatin1String(":/codemodel/images/protected.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
QLatin1String(":/codemodel/images/protected.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
||||||
static const IconMaskAndColor protectedBackgroundIcon {
|
static const IconStringMaskAndColor protectedBackgroundIcon {
|
||||||
QLatin1String(":/codemodel/images/protectedbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
QLatin1String(":/codemodel/images/protectedbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
||||||
static const IconMaskAndColor privateIcon {
|
static const IconStringMaskAndColor privateIcon {
|
||||||
QLatin1String(":/codemodel/images/private.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
QLatin1String(":/codemodel/images/private.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
||||||
static const IconMaskAndColor privateBackgroundIcon {
|
static const IconStringMaskAndColor privateBackgroundIcon {
|
||||||
QLatin1String(":/codemodel/images/privatebackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
QLatin1String(":/codemodel/images/privatebackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
||||||
static const IconMaskAndColor staticIcon {
|
static const IconStringMaskAndColor staticIcon {
|
||||||
QLatin1String(":/codemodel/images/static.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
QLatin1String(":/codemodel/images/static.png"), Theme::IconsCodeModelOverlayForegroundColor};
|
||||||
static const IconMaskAndColor staticBackgroundIcon {
|
static const IconStringMaskAndColor staticBackgroundIcon {
|
||||||
QLatin1String(":/codemodel/images/staticbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
QLatin1String(":/codemodel/images/staticbackground.png"), Theme::IconsCodeModelOverlayBackgroundColor};
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@@ -71,12 +71,11 @@ bool CompilationDatabaseProjectManagerPlugin::initialize(const QStringList &argu
|
|||||||
|
|
||||||
d = new CompilationDatabaseProjectManagerPluginPrivate;
|
d = new CompilationDatabaseProjectManagerPluginPrivate;
|
||||||
|
|
||||||
|
FileIconProvider::registerIconOverlayForFilename(Utils::Icons::PROJECT.imageFilePath().toString(),
|
||||||
|
COMPILE_COMMANDS_JSON);
|
||||||
FileIconProvider::registerIconOverlayForFilename(
|
FileIconProvider::registerIconOverlayForFilename(
|
||||||
Utils::Icons::PROJECT.imageFileName(),
|
Utils::Icons::PROJECT.imageFilePath().toString(),
|
||||||
COMPILE_COMMANDS_JSON);
|
QString(COMPILE_COMMANDS_JSON) + Constants::COMPILATIONDATABASEPROJECT_FILES_SUFFIX);
|
||||||
FileIconProvider::registerIconOverlayForFilename(
|
|
||||||
Utils::Icons::PROJECT.imageFileName(),
|
|
||||||
QString(COMPILE_COMMANDS_JSON) + Constants::COMPILATIONDATABASEPROJECT_FILES_SUFFIX);
|
|
||||||
|
|
||||||
ProjectManager::registerProjectType<CompilationDatabaseProject>(
|
ProjectManager::registerProjectType<CompilationDatabaseProject>(
|
||||||
Constants::COMPILATIONDATABASEMIMETYPE);
|
Constants::COMPILATIONDATABASEMIMETYPE);
|
||||||
|
Reference in New Issue
Block a user