aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/coreplugin/manhattanstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/coreplugin/manhattanstyle.cpp')
-rw-r--r--src/plugins/coreplugin/manhattanstyle.cpp198
1 files changed, 116 insertions, 82 deletions
diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp
index 3d51642e44f..0f16100e11e 100644
--- a/src/plugins/coreplugin/manhattanstyle.cpp
+++ b/src/plugins/coreplugin/manhattanstyle.cpp
@@ -3,9 +3,12 @@
#include "manhattanstyle.h"
+#include "generalsettings.h"
+
#include <utils/algorithm.h>
#include <utils/fancymainwindow.h>
#include <utils/hostosinfo.h>
+#include <utils/itemviews.h>
#include <utils/qtcassert.h>
#include <utils/styleanimator.h>
#include <utils/stylehelper.h>
@@ -24,6 +27,8 @@
#include <QPainter>
#include <QPainterPath>
#include <QPixmap>
+#include <QPixmapCache>
+#include <QScrollArea>
#include <QSpinBox>
#include <QStatusBar>
#include <QStyleFactory>
@@ -53,7 +58,7 @@ static bool isInUnstyledDialogOrPopup(const QWidget *widget)
{
// Do not style contents of dialogs or popups without "panelwidget" property
const QWidget *window = widget->window();
- if (window->property("panelwidget").toBool())
+ if (window->property(StyleHelper::C_PANEL_WIDGET).toBool())
return false;
const Qt::WindowType windowType = window->windowType();
return (windowType == Qt::Dialog || windowType == Qt::Popup);
@@ -74,12 +79,15 @@ bool panelWidget(const QWidget *widget)
if (qobject_cast<const QTabBar *>(widget))
return styleEnabled(widget);
+ if (qobject_cast<const QScrollArea *>(widget)) // See DebuggerMainWindowPrivate
+ return widget->property(StyleHelper::C_PANEL_WIDGET_SINGLE_ROW).toBool();
+
const QWidget *p = widget;
while (p) {
if (qobject_cast<const QToolBar *>(p) ||
qobject_cast<const QStatusBar *>(p) ||
qobject_cast<const QMenuBar *>(p) ||
- p->property("panelwidget").toBool())
+ p->property(StyleHelper::C_PANEL_WIDGET).toBool())
return styleEnabled(widget);
p = p->parentWidget();
}
@@ -97,7 +105,7 @@ bool lightColored(const QWidget *widget)
const QWidget *p = widget;
while (p) {
- if (p->property("lightColored").toBool())
+ if (p->property(StyleHelper::C_LIGHT_COLORED).toBool())
return true;
p = p->parentWidget();
}
@@ -131,6 +139,7 @@ ManhattanStyle::ManhattanStyle(const QString &baseStyleName)
: QProxyStyle(QStyleFactory::create(baseStyleName))
, d(new ManhattanStylePrivate())
{
+ Core::Internal::GeneralSettings::applyToolbarStyleFromSettings();
}
ManhattanStyle::~ManhattanStyle()
@@ -154,7 +163,7 @@ QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *op
switch (type) {
case CT_Splitter:
- if (widget && widget->property("minisplitter").toBool())
+ if (widget && widget->property(StyleHelper::C_MINI_SPLITTER).toBool())
newSize = QSize(1, 1);
break;
case CT_ComboBox:
@@ -203,8 +212,14 @@ int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
int retval = QProxyStyle::pixelMetric(metric, option, widget);
switch (metric) {
+#ifdef Q_OS_MACOS
+ case PM_MenuButtonIndicator:
+ if (widget && option->type == QStyleOption::SO_ToolButton)
+ return 12;
+ break;
+#endif
case PM_SplitterWidth:
- if (widget && widget->property("minisplitter").toBool())
+ if (widget && widget->property(StyleHelper::C_MINI_SPLITTER).toBool())
retval = 1;
break;
case PM_ToolBarIconSize:
@@ -295,16 +310,26 @@ void ManhattanStyle::polish(QWidget *widget)
widget->setAttribute(Qt::WA_LayoutUsesWidgetRect, true);
// So that text isn't cutoff in line-edits, comboboxes... etc.
const int height = qMax(StyleHelper::navigationWidgetHeight(), QApplication::fontMetrics().height());
- if (qobject_cast<QToolButton*>(widget) || qobject_cast<QLineEdit*>(widget)) {
+ if (qobject_cast<QToolButton*>(widget)) {
+ widget->setMinimumWidth(
+ StyleHelper::toolbarStyle() == StyleHelper::ToolbarStyleCompact ? 24 : 28);
widget->setAttribute(Qt::WA_Hover);
widget->setMaximumHeight(height - 2);
+ } else if (qobject_cast<QLineEdit*>(widget)) {
+ widget->setAttribute(Qt::WA_Hover);
+ widget->setFixedHeight(height - (StyleHelper::toolbarStyle()
+ == StyleHelper::ToolbarStyleCompact ? 1 : 3));
} else if (qobject_cast<QLabel*>(widget) || qobject_cast<QSpinBox*>(widget)
|| qobject_cast<QCheckBox*>(widget)) {
widget->setPalette(panelPalette(widget->palette(), lightColored(widget)));
- } else if (widget->property("panelwidget_singlerow").toBool()) {
+ } else if ((qobject_cast<QToolBar*>(widget) && !StyleHelper::isQDSTheme())
+ || widget->property(StyleHelper::C_PANEL_WIDGET_SINGLE_ROW).toBool()) {
widget->setFixedHeight(height);
} else if (qobject_cast<QStatusBar*>(widget)) {
- widget->setFixedHeight(height + 2);
+ const bool flatAndNotCompact =
+ StyleHelper::toolbarStyle() != StyleHelper::ToolbarStyleCompact
+ && creatorTheme()->flag(Theme::FlatToolBars);
+ widget->setFixedHeight(height + (flatAndNotCompact ? 3 : 2));
} else if (qobject_cast<QComboBox*>(widget)) {
const bool isLightColored = lightColored(widget);
QPalette palette = panelPalette(widget->palette(), isLightColored);
@@ -314,6 +339,9 @@ void ManhattanStyle::polish(QWidget *widget)
widget->setPalette(palette);
widget->setMaximumHeight(height - 2);
widget->setAttribute(Qt::WA_Hover);
+ } else if (qobject_cast<QScrollArea*>(widget)
+ && widget->property(StyleHelper::C_PANEL_WIDGET_SINGLE_ROW).toBool()) {
+ widget->setFixedHeight(height);
}
}
}
@@ -393,7 +421,7 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
case QStyle::SH_ItemView_ActivateItemOnSingleClick:
// default depends on the style
if (widget) {
- QVariant activationMode = widget->property("ActivationMode");
+ QVariant activationMode = widget->property(activationModeC);
if (activationMode.isValid())
ret = activationMode.toBool();
}
@@ -633,76 +661,76 @@ void ManhattanStyle::drawPrimitiveForPanelWidget(PrimitiveElement element,
const bool animating = (state & State_Animating);
if (widget && !animating) {
- auto w = const_cast<QWidget *> (widget);
- int oldState = w->property("_q_stylestate").toInt();
- QRect oldRect = w->property("_q_stylerect").toRect();
- QRect newRect = w->rect();
- w->setProperty("_q_stylestate", (int)option->state);
- w->setProperty("_q_stylerect", w->rect());
-
- // Determine the animated transition
- bool doTransition = ((state & State_On) != (oldState & State_On) ||
- (state & State_MouseOver) != (oldState & State_MouseOver));
- if (oldRect != newRect) {
- doTransition = false;
- d->animator.stopAnimation(widget);
- }
-
- if (doTransition) {
- QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
- Animation *anim = d->animator.widgetAnimation(widget);
- QStyleOption opt = *option;
- opt.state = (QStyle::State)oldState;
- opt.state |= State_Animating;
- startImage.fill(0);
- auto t = new Transition;
- t->setWidget(w);
- QPainter startPainter(&startImage);
- if (!anim) {
- drawPrimitive(element, &opt, &startPainter, widget);
- } else {
- anim->paint(&startPainter, &opt);
+ auto w = const_cast<QWidget *> (widget);
+ int oldState = w->property("_q_stylestate").toInt();
+ QRect oldRect = w->property("_q_stylerect").toRect();
+ QRect newRect = w->rect();
+ w->setProperty("_q_stylestate", (int)option->state);
+ w->setProperty("_q_stylerect", w->rect());
+
+ // Determine the animated transition
+ bool doTransition = ((state & State_On) != (oldState & State_On) ||
+ (state & State_MouseOver) != (oldState & State_MouseOver));
+ if (oldRect != newRect) {
+ doTransition = false;
d->animator.stopAnimation(widget);
}
- QStyleOption endOpt = *option;
- endOpt.state |= State_Animating;
- t->setStartImage(startImage);
- d->animator.startAnimation(t);
- endImage.fill(0);
- QPainter endPainter(&endImage);
- drawPrimitive(element, &endOpt, &endPainter, widget);
- t->setEndImage(endImage);
- if (oldState & State_MouseOver)
- t->setDuration(150);
- else
- t->setDuration(75);
- t->setStartTime(QTime::currentTime());
- }
+
+ if (doTransition) {
+ QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
+ QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
+ Animation *anim = d->animator.widgetAnimation(widget);
+ QStyleOption opt = *option;
+ opt.state = (QStyle::State)oldState;
+ opt.state |= State_Animating;
+ startImage.fill(0);
+ auto t = new Transition;
+ t->setWidget(w);
+ QPainter startPainter(&startImage);
+ if (!anim) {
+ drawPrimitive(element, &opt, &startPainter, widget);
+ } else {
+ anim->paint(&startPainter, &opt);
+ d->animator.stopAnimation(widget);
+ }
+ QStyleOption endOpt = *option;
+ endOpt.state |= State_Animating;
+ t->setStartImage(startImage);
+ d->animator.startAnimation(t);
+ endImage.fill(0);
+ QPainter endPainter(&endImage);
+ drawPrimitive(element, &endOpt, &endPainter, widget);
+ t->setEndImage(endImage);
+ if (oldState & State_MouseOver)
+ t->setDuration(150);
+ else
+ t->setDuration(75);
+ t->setStartTime(QTime::currentTime());
+ }
}
Animation *anim = d->animator.widgetAnimation(widget);
if (!animating && anim) {
- anim->paint(painter, option);
+ anim->paint(painter, option);
} else {
- bool pressed = option->state & State_Sunken || option->state & State_On;
- painter->setPen(StyleHelper::sidebarShadow());
- if (pressed) {
- const QColor shade = creatorTheme()->color(Theme::FancyToolButtonSelectedColor);
- painter->fillRect(rect, shade);
- 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());
- painter->drawLine(borderRect.topRight(), borderRect.bottomRight());
+ const bool pressed = option->state & State_Sunken || option->state & State_On
+ || (widget && widget->property(StyleHelper::C_HIGHLIGHT_WIDGET).toBool());
+ painter->setPen(StyleHelper::sidebarShadow());
+ if (pressed) {
+ StyleHelper::drawPanelBgRect(
+ painter, rect, creatorTheme()->color(Theme::FancyToolButtonSelectedColor));
+ if (StyleHelper::toolbarStyle() == StyleHelper::ToolbarStyleCompact
+ && !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());
+ painter->drawLine(borderRect.topRight(), borderRect.bottomRight());
+ }
+ } else if (option->state & State_Enabled && option->state & State_MouseOver) {
+ StyleHelper::drawPanelBgRect(
+ painter, rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
}
- } else if (option->state & State_Enabled && option->state & State_MouseOver) {
- painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
- } else if (widget && widget->property("highlightWidget").toBool()) {
- QColor shade(0, 0, 0, 128);
- painter->fillRect(rect, shade);
- }
if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) {
QColor highlight = option->palette.highlight().color();
highlight.setAlphaF(0.4f);
@@ -884,7 +912,8 @@ void ManhattanStyle::drawControl(
painter->save();
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
QPalette customPal = cb->palette;
- bool drawIcon = !(widget && widget->property("hideicon").toBool());
+ const bool drawIcon =
+ !(widget && widget->property(StyleHelper::C_HIDE_ICON).toBool());
if (!cb->currentIcon.isNull() && drawIcon) {
QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
@@ -909,14 +938,15 @@ void ManhattanStyle::drawControl(
}
Qt::TextElideMode elideMode = Qt::ElideRight;
- if (widget && widget->dynamicPropertyNames().contains("elidemode"))
- elideMode = widget->property("elidemode").value<Qt::TextElideMode>();
+ if (widget && widget->dynamicPropertyNames().contains(StyleHelper::C_ELIDE_MODE))
+ elideMode = widget->property(StyleHelper::C_ELIDE_MODE)
+ .value<Qt::TextElideMode>();
QLatin1Char asterisk('*');
int elideWidth = editRect.width();
bool notElideAsterisk = elideMode == Qt::ElideRight && widget
- && widget->property("notelideasterisk").toBool()
+ && widget->property(StyleHelper::C_NOT_ELIDE_ASTERISK).toBool()
&& cb->currentText.endsWith(asterisk)
&& option->fontMetrics.horizontalAdvance(cb->currentText)
> elideWidth;
@@ -1031,7 +1061,7 @@ void ManhattanStyle::drawControl(
: StyleHelper::sidebarHighlight();
const QColor borderColor = drawLightColored
? QColor(255, 255, 255, 180) : hightLight;
- if (widget && widget->property("topBorder").toBool()) {
+ if (widget && widget->property(StyleHelper::C_TOP_BORDER).toBool()) {
painter->drawLine(borderRect.topLeft(), borderRect.topRight());
painter->setPen(borderColor);
painter->drawLine(borderRect.topLeft() + QPointF(0, 1), borderRect.topRight() + QPointF(0, 1));
@@ -1047,7 +1077,7 @@ void ManhattanStyle::drawControl(
}
if (creatorTheme()->flag(Theme::DrawToolBarBorders)) {
painter->setPen(StyleHelper::toolBarBorderColor());
- if (widget && widget->property("topBorder").toBool())
+ if (widget && widget->property(StyleHelper::C_TOP_BORDER).toBool())
painter->drawLine(borderRect.topLeft(), borderRect.topRight());
else
painter->drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
@@ -1076,7 +1106,8 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
case CC_ToolButton:
if (const auto toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
bool reverse = option->direction == Qt::RightToLeft;
- bool drawborder = (widget && widget->property("showborder").toBool());
+ const bool drawborder =
+ (widget && widget->property(StyleHelper::C_SHOW_BORDER).toBool());
if (drawborder)
drawButtonSeparator(painter, rect, reverse);
@@ -1110,7 +1141,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
QStyleOptionToolButton label = *toolbutton;
label.palette = panelPalette(option->palette, lightColored(widget));
- if (widget && widget->property("highlightWidget").toBool()) {
+ if (widget && widget->property(StyleHelper::C_HIGHLIGHT_WIDGET).toBool()) {
label.palette.setColor(QPalette::ButtonText,
creatorTheme()->color(Theme::IconsWarningToolBarColor));
}
@@ -1137,7 +1168,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
tool.rect = tool.rect.adjusted(2, 2, -2, -2);
drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
} else if (toolbutton->features & QStyleOptionToolButton::HasMenu
- && widget && !widget->property("noArrow").toBool()) {
+ && widget && !widget->property(StyleHelper::C_NO_ARROW).toBool()) {
int arrowSize = 6;
QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
QStyleOptionToolButton newBtn = *toolbutton;
@@ -1154,9 +1185,12 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
painter->save();
bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
bool reverse = option->direction == Qt::RightToLeft;
- bool drawborder = !(widget && widget->property("hideborder").toBool());
- bool drawleftborder = (widget && widget->property("drawleftborder").toBool());
- bool alignarrow = !(widget && widget->property("alignarrow").toBool());
+ const bool drawborder =
+ !(widget && widget->property(StyleHelper::C_HIDE_BORDER).toBool());
+ const bool drawleftborder =
+ (widget && widget->property(StyleHelper::C_DRAW_LEFT_BORDER).toBool());
+ const bool alignarrow =
+ !(widget && widget->property(StyleHelper::C_ALIGN_ARROW).toBool());
if (drawborder) {
drawButtonSeparator(painter, rect, reverse);