Commit 850141ce authored by Alessandro Portale's avatar Alessandro Portale

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: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 22e8e888
......@@ -96,20 +96,20 @@ static const QIcon &icon(IconIndex icon)
case OkIcon: {
static const QIcon ok =
Icon({{QLatin1String(":/extensionsystem/images/ok.png"),
Theme::IconsRunColor}}, Icon::Style::Tinted).icon();
Theme::IconsRunColor}}, Icon::Tint).icon();
return ok;
}
case ErrorIcon: {
static const QIcon error =
Icon({{QLatin1String(":/extensionsystem/images/error.png"),
Theme::IconsErrorColor}}, Icon::Style::Tinted).icon();
Theme::IconsErrorColor}}, Icon::Tint).icon();
return error;
}
default:
case NotLoadedIcon: {
static const QIcon notLoaded =
Icon({{QLatin1String(":/extensionsystem/images/notloaded.png"),
Theme::IconsErrorColor}}, Icon::Style::Tinted).icon();
Theme::IconsErrorColor}}, Icon::Tint).icon();
return notLoaded;
}
}
......
......@@ -87,7 +87,7 @@ static void smearPixmap(QPainter *painter, const QPixmap &pixmap, qreal radius)
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)
return masks.first().first;
......@@ -98,18 +98,20 @@ static QPixmap combinedMask(const MasksAndColors &masks)
auto maskImage = masks.constBegin();
maskImage++;
for (;maskImage != masks.constEnd(); ++maskImage) {
p.save();
p.setOpacity(0.4);
p.setCompositionMode(QPainter::CompositionMode_Lighten);
smearPixmap(&p, maskToColorAndAlpha((*maskImage).first, Qt::white), 0.5);
p.restore();
if (style & Icon::PunchEdges) {
p.save();
p.setOpacity(0.4);
p.setCompositionMode(QPainter::CompositionMode_Lighten);
smearPixmap(&p, maskToColorAndAlpha((*maskImage).first, Qt::white), 0.5);
p.restore();
}
p.drawPixmap(0, 0, (*maskImage).first);
}
p.end();
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());
result.setDevicePixelRatio(combinedMask.devicePixelRatio());
......@@ -118,7 +120,7 @@ static QPixmap masksToIcon(const MasksAndColors &masks, const QPixmap &combinedM
for (MasksAndColors::const_iterator maskImage = masks.constBegin();
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.
p.save();
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));
}
if (style == Icon::Style::TintedWithShadow) {
if (style & Icon::DropShadow) {
const QPixmap shadowMask = maskToColorAndAlpha(combinedMask, Qt::black);
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
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)
, m_style(style)
{
}
Icon::Icon(const QString &imageFileName)
: m_style(Style::Plain)
: m_style(None)
{
append({imageFileName, Theme::Color(-1)});
}
......@@ -179,12 +181,12 @@ QIcon Icon::icon() const
{
if (isEmpty()) {
return QIcon();
} else if (m_style == Style::Plain) {
} else if (m_style == None) {
return QIcon(combinedPlainPixmaps(*this));
} else {
QIcon result;
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));
QColor disabledColor = creatorTheme()->palette().mid().color();
......@@ -198,12 +200,12 @@ QPixmap Icon::pixmap() const
{
if (isEmpty()) {
return QPixmap();
} else if (m_style == Style::Plain) {
} else if (m_style == None) {
return combinedPlainPixmaps(*this);
} else {
const MasksAndColors masks =
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);
}
}
......
......@@ -51,14 +51,19 @@ typedef QPair<QString, Theme::Color> IconMaskAndColor;
class QTCREATOR_UTILS_EXPORT Icon : public QVector<IconMaskAndColor>
{
public:
enum class Style {
Plain,
Tinted,
TintedWithShadow
enum IconStyleOption {
None = 0,
Tint = 1,
DropShadow = 2,
PunchEdges = 4,
ToolBarStyle = Tint | DropShadow | PunchEdges
};
Q_DECLARE_FLAGS(IconStyleOptions, IconStyleOption)
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 Icon &other) = default;
......@@ -80,9 +85,11 @@ public:
static QIcon combinedIcon(const QList<QIcon> &icons);
private:
Style m_style = Style::Plain;
IconStyleOptions m_style = None;
};
} // namespace Utils
Q_DECLARE_OPERATORS_FOR_FLAGS(Utils::Icon::IconStyleOptions)
#endif // THEMEHELPER_H
......@@ -37,7 +37,7 @@ namespace Utils {
namespace Icons {
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 Utils
......
......@@ -90,7 +90,7 @@ const Utils::Icon NEXT({
const Utils::Icon PREV({
{QLatin1String(":/core/images/prev.png"), Utils::Theme::IconsNavigationArrowsColor}});
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({
{QLatin1String(":/core/images/clean_pane_small.png"), Utils::Theme::IconsBaseColor}});
const Utils::Icon RELOAD({
......@@ -100,9 +100,9 @@ const Utils::Icon TOGGLE_SIDEBAR({
const Utils::Icon CLOSE_TOOLBAR({
{QLatin1String(":/core/images/close.png"), Utils::Theme::IconsBaseColor}});
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({
{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({
{QLatin1String(":/core/images/splitbutton_horizontal.png"), Utils::Theme::IconsBaseColor}});
const Utils::Icon SPLIT_VERTICAL({
......@@ -121,19 +121,19 @@ const Utils::Icon LINK({
{QLatin1String(":/core/images/linkicon.png"), Utils::Theme::IconsBaseColor}});
const Utils::Icon WARNING({
{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({
{QLatin1String(":/core/images/warning.png"), Utils::Theme::IconsWarningToolBarColor}});
const Utils::Icon ERROR({
{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({
{QLatin1String(":/core/images/error.png"), Utils::Theme::IconsErrorToolBarColor}});
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({
{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({
{QLatin1String(":/core/images/info.png"), Utils::Theme::IconsInfoToolBarColor}});
const Utils::Icon EXPAND({
......
......@@ -76,7 +76,7 @@ const Utils::Icon EMPTY(
const Utils::Icon STEP_OVER({
{QLatin1String(":/debugger/images/debugger_stepover_small.png"), Utils::Theme::IconsBaseColor}});
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({
{QLatin1String(":/debugger/images/debugger_stepinto_small.png"), Utils::Theme::IconsBaseColor}});
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}});
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({
{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({
{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({
{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({
{QLatin1String(":/projectexplorer/images/run_small.png"), Utils::Theme::IconsRunColor}});
......
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