Commit 8588cf26 authored by Alessandro Portale's avatar Alessandro Portale Committed by Alessandro Portale

Utils: Replace Theme::widgetStyle with a flag

Theme::widgetStyle with its two possible return values makes less sense
than a bool flag. Especially since we already have several separate
theme flags for ui elements which might be "flat" or not.

Change-Id: Ic521bb58c04386b735b784079de05e521bc1f45f
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent eeadfbba
......@@ -185,6 +185,7 @@ DrawSearchResultWidgetFrame=false
DrawTargetSelectorBottom=false
DrawToolBarHighlights=true
ApplyThemePaletteGlobally=true
FlatToolBars=true
FlatSideBarIcons=true
FlatProjectsMode=true
FlatMenuBar=true
......@@ -208,6 +209,3 @@ BuildStepDisable=:/projectexplorer/images/lightdisabledbuildstep.png
BuildStepRemove=:/core/images/lightclose.png
BuildStepMoveDown=:/core/images/lightarrowdown.png
BuildStepMoveUp=:/core/images/lightarrowup.png
[Style]
WidgetStyle=StyleFlat
......@@ -179,6 +179,7 @@ DrawSearchResultWidgetFrame=true
DrawTargetSelectorBottom=true
DrawToolBarHighlights=true
ApplyThemePaletteGlobally=false
FlatToolBars=false
FlatSideBarIcons=false
FlatProjectsMode=false
FlatMenuBar=false
......@@ -188,6 +189,3 @@ ToolBarIconShadow=true
DetailsWidgetHeaderGradient\1\color=ffffff
DetailsWidgetHeaderGradient\1\pos=1
DetailsWidgetHeaderGradient\size=1
[Style]
WidgetStyle=StyleDefault
......@@ -189,6 +189,7 @@ DrawSearchResultWidgetFrame=false
DrawTargetSelectorBottom=false
DrawToolBarHighlights=false
ApplyThemePaletteGlobally=false
FlatToolBars=true
FlatSideBarIcons=true
FlatProjectsMode=false
FlatMenuBar=false
......@@ -198,6 +199,3 @@ ToolBarIconShadow=true
DetailsWidgetHeaderGradient\1\color=0
DetailsWidgetHeaderGradient\1\pos=1
DetailsWidgetHeaderGradient\size=1
[Style]
WidgetStyle=StyleFlat
......@@ -39,7 +39,6 @@ namespace Utils {
static Theme *m_creatorTheme = 0;
ThemePrivate::ThemePrivate()
: widgetStyle(Theme::StyleDefault)
{
const QMetaObject &m = Theme::staticMetaObject;
colors.resize (m.enumerator(m.indexOfEnumerator("Color")).keyCount());
......@@ -73,11 +72,6 @@ Theme::~Theme()
delete d;
}
Theme::WidgetStyle Theme::widgetStyle() const
{
return d->widgetStyle;
}
QStringList Theme::preferredStyles() const
{
return d->preferredStyles;
......@@ -164,10 +158,6 @@ QVariantHash Theme::values() const
result.insert(key, flag(static_cast<Theme::Flag>(i)));
}
}
{
const QMetaEnum e = m.enumerator(m.indexOfEnumerator("WidgetStyle"));
result.insert(QLatin1String("WidgetStyle"), QLatin1String(e.valueToKey(widgetStyle())));
}
return result;
}
......@@ -198,13 +188,6 @@ void Theme::readSettings(QSettings &settings)
}
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Style"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("WidgetStyle"));
QString val = settings.value(QLatin1String("WidgetStyle")).toString();
d->widgetStyle = static_cast<Theme::WidgetStyle>(e.keysToValue (val.toLatin1().data()));
settings.endGroup();
}
{
settings.beginGroup(QLatin1String("Colors"));
QMetaEnum e = m.enumerator(m.indexOfEnumerator("Color"));
......
......@@ -272,18 +272,13 @@ public:
ComboBoxDrawTextShadow,
DerivePaletteFromTheme,
ApplyThemePaletteGlobally,
FlatToolBars,
FlatSideBarIcons,
FlatProjectsMode,
FlatMenuBar,
ToolBarIconShadow
};
enum WidgetStyle {
StyleDefault,
StyleFlat
};
WidgetStyle widgetStyle() const;
bool flag(Flag f) const;
QColor color(Color role) const;
QString imageFile(ImageFile imageFile, const QString &fallBack) const;
......
......@@ -47,7 +47,6 @@ public:
QVector<QString> imageFiles;
QVector<QGradientStops> gradients;
QVector<bool> flags;
Theme::WidgetStyle widgetStyle;
QMap<QString, QColor> palette;
};
......
......@@ -291,14 +291,14 @@ void EditorView::paintEvent(QPaintEvent *)
QPainter painter(this);
QRect rect = m_container->geometry();
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
painter.fillRect(rect, creatorTheme()->color(Theme::EditorPlaceholderColor));
} else {
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
painter.setBrush(creatorTheme()->color(Theme::EditorPlaceholderColor));
const int r = 3;
painter.drawRoundedRect(rect.adjusted(r , r, -r, -r), r * 2, r * 2);
} else {
painter.fillRect(rect, creatorTheme()->color(Theme::EditorPlaceholderColor));
}
}
......
......@@ -145,20 +145,22 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
if (!HostOsInfo::isMacHost() // Mac UIs usually don't hover
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
painter.save();
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
painter.setOpacity(m_fader);
FancyToolButton::hoverOverlay(&painter, rect());
} else {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
QColor fadedHoverColor = hoverColor;
fadedHoverColor.setAlpha(int(m_fader * hoverColor.alpha()));
painter.fillRect(rect(), fadedHoverColor);
} else {
painter.setOpacity(m_fader);
FancyToolButton::hoverOverlay(&painter, rect());
}
painter.restore();
} else if (isDown() || isChecked()) {
painter.save();
const QColor selectedColor = creatorTheme()->color(Theme::FancyToolButtonSelectedColor);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
painter.fillRect(rect(), selectedColor);
} else {
QLinearGradient grad(rect().topLeft(), rect().topRight());
grad.setColorAt(0, Qt::transparent);
grad.setColorAt(0.5, selectedColor);
......@@ -171,8 +173,6 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
painter.drawLine(borderRectF.topLeft() + QPointF(0, 1), borderRectF.topRight() + QPointF(0, 1));
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
painter.drawLine(borderRectF.bottomLeft(), borderRectF.bottomRight());
} else {
painter.fillRect(rect(), selectedColor);
}
painter.restore();
}
......@@ -269,7 +269,7 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
const QRectF borderRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
if (creatorTheme()->widgetStyle () == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
// this paints the background of the bottom portion of the
// left tab bar
painter.fillRect(event->rect(), StyleHelper::baseColor());
......
......@@ -114,7 +114,7 @@ QSize FancyTabBar::tabSizeHint(bool minimum) const
void FancyTabBar::paintEvent(QPaintEvent *event)
{
QPainter p(this);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
// draw background of upper part of left tab widget
// (Welcome, ... Help)
p.fillRect(event->rect(), StyleHelper::baseColor());
......@@ -293,7 +293,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
bool enabled = isTabEnabled(tabIndex);
if (selected) {
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
// background color of a fancy tab that is active
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonSelectedColor));
} else {
......@@ -317,14 +317,14 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
painter->save();
painter->setOpacity(fader);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
if (creatorTheme()->flag(Theme::FlatToolBars))
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
else
FancyToolButton::hoverOverlay(painter, rect);
painter->restore();
}
if (!enabled && creatorTheme()->widgetStyle() == Theme::StyleDefault)
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
painter->setOpacity(0.7);
if (drawIcon) {
......
......@@ -455,7 +455,13 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
// Fill the line edit background
QRectF backgroundRect = option->rect;
const bool enabled = option->state & State_Enabled;
if (Utils::creatorTheme()->widgetStyle() == Utils::Theme::StyleDefault) {
if (Utils::creatorTheme()->flag(Theme::FlatToolBars)) {
painter->save();
if (!enabled)
painter->setOpacity(0.75);
painter->fillRect(backgroundRect, option->palette.base());
painter->restore();
} else {
backgroundRect.adjust(1, 1, -1, -1);
painter->setBrushOrigin(backgroundRect.topLeft());
painter->fillRect(backgroundRect, option->palette.base());
......@@ -467,12 +473,6 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
StyleHelper::drawCornerImage(enabled ? bg : bg_disabled,
painter, option->rect, 5, 5, 5, 5);
} else {
painter->save();
if (!enabled)
painter->setOpacity(0.75);
painter->fillRect(backgroundRect, option->palette.base());
painter->restore();
}
const bool hasFocus = state & State_HasFocus;
......@@ -499,7 +499,7 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
if (pressed) {
const QColor shade = creatorTheme()->color(Theme::FancyToolButtonSelectedColor);
painter->fillRect(rect, shade);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (!creatorTheme()->flag(Theme::FlatToolBars)) {
const QRectF borderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
painter->drawLine(borderRect.topLeft() + QPointF(1, 0), borderRect.topRight() - QPointF(1, 0));
painter->drawLine(borderRect.topLeft(), borderRect.bottomLeft());
......@@ -527,7 +527,9 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
case PE_PanelStatusBar:
{
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
painter->fillRect(rect, StyleHelper::baseColor());
} else {
painter->save();
QLinearGradient grad = StyleHelper::statusBarGradient(rect);
painter->fillRect(rect, grad);
......@@ -538,8 +540,6 @@ void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption
painter->setPen(StyleHelper::borderColor().darker(110)); //TODO: make themable
painter->drawLine(borderRect.topLeft(), borderRect.topRight());
painter->restore();
} else {
painter->fillRect(rect, StyleHelper::baseColor());
}
}
break;
......@@ -819,7 +819,7 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
bool drawLightColored = lightColored(widget);
// draws the background of the 'Type hierarchy', 'Projects' headers
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
if (creatorTheme()->flag(Theme::FlatToolBars))
painter->fillRect(rect, StyleHelper::baseColor(drawLightColored));
else if (horizontal)
StyleHelper::horizontalGradient(painter, gradientSpan, rect, drawLightColored);
......@@ -836,9 +836,9 @@ void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *opt
// Note: This is a hack to determine if the
// toolbar should draw the top or bottom outline
// (needed for the find toolbar for instance)
const QColor hightLight = creatorTheme()->widgetStyle() == Theme::StyleDefault
? StyleHelper::sidebarHighlight()
: creatorTheme()->color(Theme::FancyToolBarSeparatorColor);
const QColor hightLight = creatorTheme()->flag(Theme::FlatToolBars)
? creatorTheme()->color(Theme::FancyToolBarSeparatorColor)
: StyleHelper::sidebarHighlight();
const QColor borderColor = drawLightColored
? QColor(255, 255, 255, 180) : hightLight;
if (widget && widget->property("topBorder").toBool()) {
......@@ -1017,7 +1017,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
void ManhattanStyle::drawButtonSeparator(QPainter *painter, const QRect &rect, bool reverse) const
{
const QRectF borderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
const int margin = 3;
painter->setPen(creatorTheme()->color(Theme::FancyToolBarSeparatorColor));
painter->drawLine(borderRect.topRight() + QPointF(0, margin),
......
......@@ -76,7 +76,7 @@ static const int buttonBorderWidth = 3;
static int numberAreaWidth()
{
return creatorTheme()->widgetStyle() == Theme::StyleDefault ? 19 : 15;
return creatorTheme()->flag(Theme::FlatToolBars) ? 15 : 19;
}
////
......@@ -192,7 +192,7 @@ OutputPaneManager::OutputPaneManager(QWidget *parent) :
m_buttonsWidget->setLayout(new QHBoxLayout);
m_buttonsWidget->layout()->setContentsMargins(5,0,0,0);
m_buttonsWidget->layout()->setSpacing(
creatorTheme()->widgetStyle() == Theme::StyleDefault ? 4 : 9);
creatorTheme()->flag(Theme::FlatToolBars) ? 9 : 4);
}
OutputPaneManager::~OutputPaneManager()
......@@ -687,16 +687,7 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent*)
const bool hovered = !HostOsInfo::isMacHost() && (styleOption.state & QStyle::State_MouseOver);
const QImage *image = 0;
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (isDown())
image = &panelButtonPressed;
else if (isChecked())
image = hovered ? &panelButtonCheckedHover : &panelButtonChecked;
else
image = hovered ? &panelButtonHover : &panelButton;
if (image)
StyleHelper::drawCornerImage(*image, &p, rect(), numberAreaWidth(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth);
} else {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
Theme::Color c = Theme::BackgroundColorDark;
if (hovered)
......@@ -706,13 +697,22 @@ void OutputPaneToggleButton::paintEvent(QPaintEvent*)
if (c != Theme::BackgroundColorDark)
p.fillRect(rect(), creatorTheme()->color(c));
} else {
if (isDown())
image = &panelButtonPressed;
else if (isChecked())
image = hovered ? &panelButtonCheckedHover : &panelButtonChecked;
else
image = hovered ? &panelButtonHover : &panelButton;
if (image)
StyleHelper::drawCornerImage(*image, &p, rect(), numberAreaWidth(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth);
}
if (m_flashTimer->state() == QTimeLine::Running)
{
QColor c = creatorTheme()->color(Theme::OutputPaneButtonFlashColor);
c.setAlpha (m_flashTimer->currentFrame());
QRect r = (creatorTheme()->widgetStyle() == Theme::StyleFlat)
QRect r = creatorTheme()->flag(Theme::FlatToolBars)
? rect() : rect().adjusted(numberAreaWidth(), 1, -1, -1);
p.fillRect(r, c);
}
......@@ -781,7 +781,7 @@ QSize OutputPaneManageButton::sizeHint() const
void OutputPaneManageButton::paintEvent(QPaintEvent*)
{
QPainter p(this);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (!creatorTheme()->flag(Theme::FlatToolBars)) {
static const QImage button(StyleHelper::dpiSpecificImageFile(QStringLiteral(":/core/images/panel_manage_button.png")));
StyleHelper::drawCornerImage(button, &p, rect(), buttonBorderWidth, buttonBorderWidth, buttonBorderWidth, buttonBorderWidth);
}
......
......@@ -295,7 +295,7 @@ void FutureProgress::mousePressEvent(QMouseEvent *event)
void FutureProgress::paintEvent(QPaintEvent *)
{
QPainter p(this);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
p.fillRect(rect(), StyleHelper::baseColor());
} else {
QLinearGradient grad = StyleHelper::statusBarGradient(rect());
......
......@@ -295,7 +295,7 @@ void ProgressBar::paintEvent(QPaintEvent *)
const QColor c = creatorTheme()->color(themeColor);
//draw the progress bar
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
p.fillRect(rect.adjusted(2, 2, -2, -2),
creatorTheme()->color(Theme::ProgressBarBackgroundColor));
p.fillRect(inner, c);
......@@ -336,7 +336,7 @@ void ProgressBar::paintEvent(QPaintEvent *)
const bool hover = m_cancelRect.contains(mapFromGlobal(QCursor::pos()));
const QRectF cancelVisualRect(m_cancelRect.adjusted(0, 1, -2, -2));
int intensity = hover ? 90 : 70;
if (creatorTheme()->widgetStyle() != Theme::StyleFlat) {
if (!creatorTheme()->flag(Theme::FlatToolBars)) {
QLinearGradient grad(cancelVisualRect.topLeft(), cancelVisualRect.bottomLeft());
QColor buttonColor(intensity, intensity, intensity, 255);
grad.setColorAt(0, buttonColor.lighter(130));
......
......@@ -708,7 +708,7 @@ ToggleButton::ToggleButton(QWidget *parent)
: QToolButton(parent)
{
setToolButtonStyle(Qt::ToolButtonIconOnly);
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
QPalette p = palette();
p.setBrush(QPalette::Base, creatorTheme()->color(Theme::ToggleButtonBackgroundColor));
setPalette(p);
......
......@@ -135,7 +135,7 @@ void TargetSelectorDelegate::paint(QPainter *painter,
const QColor color = (option.state & QStyle::State_HasFocus) ?
option.palette.highlight().color() :
option.palette.dark().color();
if (creatorTheme()->widgetStyle() == Theme::StyleFlat) {
if (creatorTheme()->flag(Theme::FlatToolBars)) {
painter->fillRect(option.rect, color);
} else {
painter->fillRect(option.rect, color.darker(140));
......
......@@ -85,7 +85,7 @@ void RootWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
if (!creatorTheme()->flag(Theme::FlatToolBars)) {
// draw separator line to the right of the settings panel
QPainter painter(this);
QColor light = StyleHelper::mergedColors(
......
......@@ -170,7 +170,7 @@ NavigatorTreeView::NavigatorTreeView(QWidget *parent)
void NavigatorTreeView::drawSelectionBackground(QPainter *painter, const QStyleOption &option)
{
painter->save();
if (Utils::creatorTheme()->widgetStyle() == Utils::Theme::StyleFlat) {
if (Utils::creatorTheme()->flag(Utils::Theme::FlatToolBars)) {
painter->setOpacity(0.5);
painter->fillRect(option.rect, option.palette.color(QPalette::Highlight));
} else {
......
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