forked from qt-creator/qt-creator
Utils::Icon: Make the style options flag based
A drop shadow and the "punching of edges" are now independantly settable. Change-Id: I48bf88944d0cfce504aef0a1c04979ab2dc4cb9f Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -96,20 +96,20 @@ static const QIcon &icon(IconIndex icon)
|
|||||||
case OkIcon: {
|
case OkIcon: {
|
||||||
static const QIcon ok =
|
static const QIcon ok =
|
||||||
Icon({{QLatin1String(":/extensionsystem/images/ok.png"),
|
Icon({{QLatin1String(":/extensionsystem/images/ok.png"),
|
||||||
Theme::IconsRunColor}}, Icon::Style::Tinted).icon();
|
Theme::IconsRunColor}}, Icon::Tint).icon();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
case ErrorIcon: {
|
case ErrorIcon: {
|
||||||
static const QIcon error =
|
static const QIcon error =
|
||||||
Icon({{QLatin1String(":/extensionsystem/images/error.png"),
|
Icon({{QLatin1String(":/extensionsystem/images/error.png"),
|
||||||
Theme::IconsErrorColor}}, Icon::Style::Tinted).icon();
|
Theme::IconsErrorColor}}, Icon::Tint).icon();
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
case NotLoadedIcon: {
|
case NotLoadedIcon: {
|
||||||
static const QIcon notLoaded =
|
static const QIcon notLoaded =
|
||||||
Icon({{QLatin1String(":/extensionsystem/images/notloaded.png"),
|
Icon({{QLatin1String(":/extensionsystem/images/notloaded.png"),
|
||||||
Theme::IconsErrorColor}}, Icon::Style::Tinted).icon();
|
Theme::IconsErrorColor}}, Icon::Tint).icon();
|
||||||
return notLoaded;
|
return notLoaded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ static void smearPixmap(QPainter *painter, const QPixmap &pixmap, qreal radius)
|
|||||||
painter->drawPixmap(QPointF(nagative, 0), pixmap);
|
painter->drawPixmap(QPointF(nagative, 0), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QPixmap combinedMask(const MasksAndColors &masks)
|
static QPixmap combinedMask(const MasksAndColors &masks, Icon::IconStyleOptions style)
|
||||||
{
|
{
|
||||||
if (masks.count() == 1)
|
if (masks.count() == 1)
|
||||||
return masks.first().first;
|
return masks.first().first;
|
||||||
@@ -98,18 +98,20 @@ static QPixmap combinedMask(const MasksAndColors &masks)
|
|||||||
auto maskImage = masks.constBegin();
|
auto maskImage = masks.constBegin();
|
||||||
maskImage++;
|
maskImage++;
|
||||||
for (;maskImage != masks.constEnd(); ++maskImage) {
|
for (;maskImage != masks.constEnd(); ++maskImage) {
|
||||||
p.save();
|
if (style & Icon::PunchEdges) {
|
||||||
p.setOpacity(0.4);
|
p.save();
|
||||||
p.setCompositionMode(QPainter::CompositionMode_Lighten);
|
p.setOpacity(0.4);
|
||||||
smearPixmap(&p, maskToColorAndAlpha((*maskImage).first, Qt::white), 0.5);
|
p.setCompositionMode(QPainter::CompositionMode_Lighten);
|
||||||
p.restore();
|
smearPixmap(&p, maskToColorAndAlpha((*maskImage).first, Qt::white), 0.5);
|
||||||
|
p.restore();
|
||||||
|
}
|
||||||
p.drawPixmap(0, 0, (*maskImage).first);
|
p.drawPixmap(0, 0, (*maskImage).first);
|
||||||
}
|
}
|
||||||
p.end();
|
p.end();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedMask, Icon::Style style)
|
static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedMask, Icon::IconStyleOptions style)
|
||||||
{
|
{
|
||||||
QPixmap result(combinedMask.size());
|
QPixmap result(combinedMask.size());
|
||||||
result.setDevicePixelRatio(combinedMask.devicePixelRatio());
|
result.setDevicePixelRatio(combinedMask.devicePixelRatio());
|
||||||
@@ -118,7 +120,7 @@ static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedM
|
|||||||
|
|
||||||
for (MasksAndColors::const_iterator maskImage = masks.constBegin();
|
for (MasksAndColors::const_iterator maskImage = masks.constBegin();
|
||||||
maskImage != masks.constEnd(); ++maskImage) {
|
maskImage != masks.constEnd(); ++maskImage) {
|
||||||
if (style == Icon::Style::TintedWithShadow && maskImage != masks.constBegin()) {
|
if (style & Icon::PunchEdges && maskImage != masks.constBegin()) {
|
||||||
// Punch a transparent outline around an overlay.
|
// Punch a transparent outline around an overlay.
|
||||||
p.save();
|
p.save();
|
||||||
p.setOpacity(0.4);
|
p.setOpacity(0.4);
|
||||||
@@ -129,7 +131,7 @@ static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedM
|
|||||||
p.drawPixmap(0, 0, maskToColorAndAlpha((*maskImage).first, (*maskImage).second));
|
p.drawPixmap(0, 0, maskToColorAndAlpha((*maskImage).first, (*maskImage).second));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (style == Icon::Style::TintedWithShadow) {
|
if (style & Icon::DropShadow) {
|
||||||
const QPixmap shadowMask = maskToColorAndAlpha(combinedMask, Qt::black);
|
const QPixmap shadowMask = maskToColorAndAlpha(combinedMask, Qt::black);
|
||||||
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
|
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
|
||||||
p.setOpacity(0.05);
|
p.setOpacity(0.05);
|
||||||
@@ -163,14 +165,14 @@ Icon::Icon()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon::Icon(std::initializer_list<IconMaskAndColor> args, Style style)
|
Icon::Icon(std::initializer_list<IconMaskAndColor> args, Icon::IconStyleOptions style)
|
||||||
: QVector<IconMaskAndColor>(args)
|
: QVector<IconMaskAndColor>(args)
|
||||||
, m_style(style)
|
, m_style(style)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Icon::Icon(const QString &imageFileName)
|
Icon::Icon(const QString &imageFileName)
|
||||||
: m_style(Style::Plain)
|
: m_style(None)
|
||||||
{
|
{
|
||||||
append({imageFileName, Theme::Color(-1)});
|
append({imageFileName, Theme::Color(-1)});
|
||||||
}
|
}
|
||||||
@@ -179,12 +181,12 @@ QIcon Icon::icon() const
|
|||||||
{
|
{
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return QIcon();
|
return QIcon();
|
||||||
} else if (m_style == Style::Plain) {
|
} else if (m_style == None) {
|
||||||
return QIcon(combinedPlainPixmaps(*this));
|
return QIcon(combinedPlainPixmaps(*this));
|
||||||
} else {
|
} else {
|
||||||
QIcon result;
|
QIcon result;
|
||||||
const MasksAndColors masks = masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
const MasksAndColors masks = masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
||||||
const QPixmap combinedMask = Utils::combinedMask(masks);
|
const QPixmap combinedMask = Utils::combinedMask(masks, m_style);
|
||||||
result.addPixmap(masksToIcon(masks, combinedMask, m_style));
|
result.addPixmap(masksToIcon(masks, combinedMask, m_style));
|
||||||
|
|
||||||
QColor disabledColor = creatorTheme()->palette().mid().color();
|
QColor disabledColor = creatorTheme()->palette().mid().color();
|
||||||
@@ -198,12 +200,12 @@ QPixmap Icon::pixmap() const
|
|||||||
{
|
{
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return QPixmap();
|
return QPixmap();
|
||||||
} else if (m_style == Style::Plain) {
|
} else if (m_style == None) {
|
||||||
return combinedPlainPixmaps(*this);
|
return combinedPlainPixmaps(*this);
|
||||||
} else {
|
} else {
|
||||||
const MasksAndColors masks =
|
const MasksAndColors masks =
|
||||||
masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
masksAndColors(*this, qRound(qApp->devicePixelRatio()));
|
||||||
const QPixmap combinedMask = Utils::combinedMask(masks);
|
const QPixmap combinedMask = Utils::combinedMask(masks, m_style);
|
||||||
return masksToIcon(masks, combinedMask, m_style);
|
return masksToIcon(masks, combinedMask, m_style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,14 +51,19 @@ typedef QPair<QString, Theme::Color> IconMaskAndColor;
|
|||||||
class QTCREATOR_UTILS_EXPORT Icon : public QVector<IconMaskAndColor>
|
class QTCREATOR_UTILS_EXPORT Icon : public QVector<IconMaskAndColor>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum class Style {
|
enum IconStyleOption {
|
||||||
Plain,
|
None = 0,
|
||||||
Tinted,
|
Tint = 1,
|
||||||
TintedWithShadow
|
DropShadow = 2,
|
||||||
|
PunchEdges = 4,
|
||||||
|
|
||||||
|
ToolBarStyle = Tint | DropShadow | PunchEdges
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_FLAGS(IconStyleOptions, IconStyleOption)
|
||||||
|
|
||||||
Icon();
|
Icon();
|
||||||
Icon(std::initializer_list<IconMaskAndColor> args, Style style = Style::TintedWithShadow);
|
Icon(std::initializer_list<IconMaskAndColor> args, IconStyleOptions style = ToolBarStyle);
|
||||||
Icon(const QString &imageFileName);
|
Icon(const QString &imageFileName);
|
||||||
Icon(const Icon &other) = default;
|
Icon(const Icon &other) = default;
|
||||||
|
|
||||||
@@ -80,9 +85,11 @@ public:
|
|||||||
static QIcon combinedIcon(const QList<QIcon> &icons);
|
static QIcon combinedIcon(const QList<QIcon> &icons);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Style m_style = Style::Plain;
|
IconStyleOptions m_style = None;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Utils::Icon::IconStyleOptions)
|
||||||
|
|
||||||
#endif // THEMEHELPER_H
|
#endif // THEMEHELPER_H
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace Utils {
|
|||||||
namespace Icons {
|
namespace Icons {
|
||||||
|
|
||||||
const Utils::Icon EDIT_CLEAR({
|
const Utils::Icon EDIT_CLEAR({
|
||||||
{QLatin1String(":/core/images/editclear.png"), Utils::Theme::PanelTextColorMid}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/editclear.png"), Utils::Theme::BackgroundColorHover}}, Utils::Icon::Tint);
|
||||||
|
|
||||||
} // namespace Icons
|
} // namespace Icons
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ const Utils::Icon NEXT({
|
|||||||
const Utils::Icon PREV({
|
const Utils::Icon PREV({
|
||||||
{QLatin1String(":/core/images/prev.png"), Utils::Theme::IconsNavigationArrowsColor}});
|
{QLatin1String(":/core/images/prev.png"), Utils::Theme::IconsNavigationArrowsColor}});
|
||||||
const Utils::Icon MAGNIFIER({
|
const Utils::Icon MAGNIFIER({
|
||||||
{QLatin1String(":/core/images/magnifier.png"), Utils::Theme::PanelTextColorMid}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/magnifier.png"), Utils::Theme::BackgroundColorHover}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon CLEAN_PANE({
|
const Utils::Icon CLEAN_PANE({
|
||||||
{QLatin1String(":/core/images/clean_pane_small.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/core/images/clean_pane_small.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon RELOAD({
|
const Utils::Icon RELOAD({
|
||||||
@@ -100,9 +100,9 @@ const Utils::Icon TOGGLE_SIDEBAR({
|
|||||||
const Utils::Icon CLOSE_TOOLBAR({
|
const Utils::Icon CLOSE_TOOLBAR({
|
||||||
{QLatin1String(":/core/images/close.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/core/images/close.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon CLOSE_FOREGROUND({
|
const Utils::Icon CLOSE_FOREGROUND({
|
||||||
{QLatin1String(":/core/images/close.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/close.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon CLOSE_BACKGROUND({
|
const Utils::Icon CLOSE_BACKGROUND({
|
||||||
{QLatin1String(":/core/images/close.png"), Utils::Theme::PanelTextColorLight}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/close.png"), Utils::Theme::PanelTextColorLight}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon SPLIT_HORIZONTAL({
|
const Utils::Icon SPLIT_HORIZONTAL({
|
||||||
{QLatin1String(":/core/images/splitbutton_horizontal.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/core/images/splitbutton_horizontal.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon SPLIT_VERTICAL({
|
const Utils::Icon SPLIT_VERTICAL({
|
||||||
@@ -121,19 +121,19 @@ const Utils::Icon LINK({
|
|||||||
{QLatin1String(":/core/images/linkicon.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/core/images/linkicon.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon WARNING({
|
const Utils::Icon WARNING({
|
||||||
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
||||||
{QLatin1String(":/core/images/warning.png"), Utils::Theme::IconsWarningColor}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/warning.png"), Utils::Theme::IconsWarningColor}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon WARNING_TOOLBAR({
|
const Utils::Icon WARNING_TOOLBAR({
|
||||||
{QLatin1String(":/core/images/warning.png"), Utils::Theme::IconsWarningToolBarColor}});
|
{QLatin1String(":/core/images/warning.png"), Utils::Theme::IconsWarningToolBarColor}});
|
||||||
const Utils::Icon ERROR({
|
const Utils::Icon ERROR({
|
||||||
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
||||||
{QLatin1String(":/core/images/error.png"), Utils::Theme::IconsErrorColor}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/error.png"), Utils::Theme::IconsErrorColor}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon ERROR_TOOLBAR({
|
const Utils::Icon ERROR_TOOLBAR({
|
||||||
{QLatin1String(":/core/images/error.png"), Utils::Theme::IconsErrorToolBarColor}});
|
{QLatin1String(":/core/images/error.png"), Utils::Theme::IconsErrorToolBarColor}});
|
||||||
const Utils::Icon ERROR_TASKBAR({
|
const Utils::Icon ERROR_TASKBAR({
|
||||||
{QLatin1String(":/core/images/compile_error_taskbar.png"), Utils::Theme::IconsErrorColor}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/compile_error_taskbar.png"), Utils::Theme::IconsErrorColor}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon INFO({
|
const Utils::Icon INFO({
|
||||||
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
{QLatin1String(":/core/images/warningfill.png"), Utils::Theme::BackgroundColorNormal},
|
||||||
{QLatin1String(":/core/images/info.png"), Utils::Theme::IconsInfoColor}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/core/images/info.png"), Utils::Theme::IconsInfoColor}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon INFO_TOOLBAR({
|
const Utils::Icon INFO_TOOLBAR({
|
||||||
{QLatin1String(":/core/images/info.png"), Utils::Theme::IconsInfoToolBarColor}});
|
{QLatin1String(":/core/images/info.png"), Utils::Theme::IconsInfoToolBarColor}});
|
||||||
const Utils::Icon EXPAND({
|
const Utils::Icon EXPAND({
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ const Utils::Icon EMPTY(
|
|||||||
const Utils::Icon STEP_OVER({
|
const Utils::Icon STEP_OVER({
|
||||||
{QLatin1String(":/debugger/images/debugger_stepover_small.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/debugger/images/debugger_stepover_small.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon STEP_OVER_TOOLBUTTON({
|
const Utils::Icon STEP_OVER_TOOLBUTTON({
|
||||||
{QLatin1String(":/debugger/images/debugger_stepover_small.png"), Utils::Theme::TextColorNormal}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/debugger/images/debugger_stepover_small.png"), Utils::Theme::TextColorNormal}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon STEP_INTO({
|
const Utils::Icon STEP_INTO({
|
||||||
{QLatin1String(":/debugger/images/debugger_stepinto_small.png"), Utils::Theme::IconsBaseColor}});
|
{QLatin1String(":/debugger/images/debugger_stepinto_small.png"), Utils::Theme::IconsBaseColor}});
|
||||||
const Utils::Icon STEP_OUT({
|
const Utils::Icon STEP_OUT({
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ const Utils::Icon DEBUG_START_FLAT({
|
|||||||
{QLatin1String(":/projectexplorer/images/debugger_run_mask.png"), Utils::Theme::IconsRunColor}});
|
{QLatin1String(":/projectexplorer/images/debugger_run_mask.png"), Utils::Theme::IconsRunColor}});
|
||||||
|
|
||||||
const Utils::Icon BUILDSTEP_MOVEUP({
|
const Utils::Icon BUILDSTEP_MOVEUP({
|
||||||
{QLatin1String(":/projectexplorer/images/buildstepmoveup.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/projectexplorer/images/buildstepmoveup.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon BUILDSTEP_MOVEDOWN({
|
const Utils::Icon BUILDSTEP_MOVEDOWN({
|
||||||
{QLatin1String(":/projectexplorer/images/buildstepmovedown.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/projectexplorer/images/buildstepmovedown.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon BUILDSTEP_DISABLE({
|
const Utils::Icon BUILDSTEP_DISABLE({
|
||||||
{QLatin1String(":/projectexplorer/images/buildstepdisable.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/projectexplorer/images/buildstepdisable.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint);
|
||||||
const Utils::Icon BUILDSTEP_REMOVE({
|
const Utils::Icon BUILDSTEP_REMOVE({
|
||||||
{QLatin1String(":/projectexplorer/images/buildstepremove.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Style::Tinted);
|
{QLatin1String(":/projectexplorer/images/buildstepremove.png"), Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint);
|
||||||
|
|
||||||
const Utils::Icon RUN_SMALL({
|
const Utils::Icon RUN_SMALL({
|
||||||
{QLatin1String(":/projectexplorer/images/run_small.png"), Utils::Theme::IconsRunColor}});
|
{QLatin1String(":/projectexplorer/images/run_small.png"), Utils::Theme::IconsRunColor}});
|
||||||
|
|||||||
Reference in New Issue
Block a user