QmlDesigner: Modify the style of slider for panelwidgets

Task-number: QDS-9134
Change-Id: Ie1a6ab94a546247e0cdd35798fc8085be005d13c
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
This commit is contained in:
Ali Kianian
2023-02-20 19:02:43 +02:00
parent 0d8c76e853
commit a98c6583be
6 changed files with 39 additions and 31 deletions

View File

@@ -425,7 +425,7 @@ PaletteWindowTextDisabled=textDisabled
PaletteBaseDisabled=backgroundColorDisabled
PaletteTextDisabled=textDisabled
PaletteMid=ffa0a0a0
PalettePlaceholderText=ff8d8d8d
PalettePlaceholderText=slateGrey
QmlDesigner_BackgroundColor=qmlDesignerButtonColor
QmlDesigner_HighlightColor=ff46a2da

View File

@@ -89,11 +89,6 @@ bool panelWidget(const QWidget *widget)
return false;
}
inline bool isDSSlider(const QWidget *widget)
{
return (widget && widget->property("DSSlider").toBool());
}
// Consider making this a QStyle state
static bool isQmlEditorMenu(const QWidget *widget)
{
@@ -496,7 +491,7 @@ QRect ManhattanStyle::subControlRect(ComplexControl control, const QStyleOptionC
#endif
QRect retval = QProxyStyle::subControlRect(control, option, subControl, widget);;
if (isDSSlider(widget)) {
if (panelWidget(widget)) {
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
switch (subControl) {
case SubControl::SC_SliderGroove:
@@ -1649,7 +1644,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
QPainter *painter, const QWidget *widget) const
{
if (!panelWidget(widget))
return QProxyStyle::drawComplexControl(control, option, painter, widget);
return QProxyStyle::drawComplexControl(control, option, painter, widget);
QRect rect = option->rect;
switch (control) {
@@ -1792,11 +1787,6 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
break;
case CC_Slider:
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
if (!isDSSlider(widget)) {
QProxyStyle::drawComplexControl(control, option, painter, widget);
break;
}
QRect groove = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
@@ -1804,26 +1794,40 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
bool enabled = option->state & QStyle::State_Enabled;
bool grooveHover = slider->activeSubControls & SC_SliderGroove;
bool handleHover = slider->activeSubControls & SC_SliderHandle;
bool interaction = option->state & State_Sunken;
bool activeFocus = option->state & State_HasFocus && option->state & State_KeyboardFocusChange;
int sliderPaintingOffset = horizontal
? handle.center().x()
: handle.center().y();
int borderRadius = 4;
painter->save();
painter->setRenderHint(QPainter::RenderHint::Antialiasing);
int lineWidth = pixelMetric(QStyle::PM_DefaultFrameWidth, option, widget);
Theme::Color themeframeColor = enabled
? activeFocus
? Theme::DSstateBackgroundColor_hover
: Theme::DSBackgroundColorAlternate
: Theme::DScontrolBackgroundDisabled;
? interaction
? Theme::DSstateControlBackgroundColor_hover // Pressed
: grooveHover
? Theme::DSstateSeparatorColor // GrooveHover
: Theme::DSpopupBackground // Idle
: Theme::DSpopupBackground; // Disabled
QColor frameColor = creatorTheme()->color(themeframeColor);
if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
Theme::Color bgPlusColor = enabled ? Theme::DSBackgroundColorAlternate : Theme::DScontrolOutlineDisabled;
Theme::Color bgMinusColor = enabled ? Theme::DScontrolBackground : Theme::DScontrolOutlineDisabled;
Theme::Color bgPlusColor = enabled
? interaction
? Theme::DSstateControlBackgroundColor_hover // Pressed
: grooveHover
? Theme::DSstateSeparatorColor // GrooveHover
: Theme::DStoolbarBackground // Idle
: Theme::DStoolbarBackground; // Disabled
Theme::Color bgMinusColor = Theme::DSpopupBackground;
QRect minusRect(groove);
QRect plusRect(groove);
@@ -1846,9 +1850,13 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
}
}
painter->save();
painter->setPen(Qt::NoPen);
painter->fillRect(plusRect, creatorTheme()->color(bgPlusColor));
painter->fillRect(minusRect, creatorTheme()->color(bgMinusColor));
painter->setBrush(creatorTheme()->color(bgPlusColor));
painter->drawRoundedRect(plusRect, borderRadius, borderRadius);
painter->setBrush(creatorTheme()->color(bgMinusColor));
painter->drawRoundedRect(minusRect, borderRadius, borderRadius);
painter->restore();
}
if (option->subControls & SC_SliderTickmarks) {
@@ -1916,17 +1924,18 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
// draw handle
if ((option->subControls & SC_SliderHandle) ) {
Theme::Color handleColor = enabled
? slider->state & QStyle::State_Editing
? Theme::DSsliderHandleInteraction
: slider->activeSubControls & SC_SliderHandle
? Theme::DSsliderHandleHover
: Theme::DSsliderHandle
: Theme::DSiconColorDisabled;
? interaction
? Theme::DSinteraction // Interaction
: grooveHover || handleHover
? Theme::DStabActiveText // Hover
: Theme::PalettePlaceholderText // Idle
: Theme::DStoolbarIcon_blocked; // Disabled
int halfSliderThickness = horizontal
? handle.width() / 2
: handle.height() / 2;
painter->setBrush(creatorTheme()->color(handleColor));
painter->setPen(Qt::NoPen);
painter->drawRoundedRect(handle,
halfSliderThickness,
halfSliderThickness);
@@ -1935,7 +1944,7 @@ void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOpti
if (groove.isValid()) {
painter->setBrush(Qt::NoBrush);
painter->setPen(QPen(frameColor, lineWidth));
painter->drawRect(groove);
painter->drawRoundedRect(groove, borderRadius, borderRadius);
}
painter->restore();
}

View File

@@ -152,7 +152,6 @@ CurveEditorToolBar::CurveEditorToolBar(CurveEditorModel *model, QWidget* parent)
m_zoomSlider = new QSlider(Qt::Horizontal);
m_zoomSlider->setRange(0, 100);
m_zoomSlider->setProperty("DSSlider", true);
m_zoomSlider->setProperty("panelwidget", true);
m_zoomSlider->setProperty("panelwidget_singlerow", true);
m_zoomSlider->setFixedWidth(120);

View File

@@ -17,7 +17,6 @@ SeekerSlider::SeekerSlider(QWidget *parent)
{
setProperty("panelwidget", true);
setProperty("panelwidget_singlerow", true);
setProperty("DSSlider", true);
setOrientation(Qt::Horizontal);
setFixedWidth(120);
setMaxValue(30);

View File

@@ -429,7 +429,6 @@ void TimelineToolBar::createRightControls()
m_scale = new QSlider(this);
m_scale->setOrientation(Qt::Horizontal);
m_scale->setProperty("DSSlider", true);
m_scale->setProperty("panelwidget", true);
m_scale->setProperty("panelwidget_singlerow", true);
m_scale->setMaximumWidth(200);

View File

@@ -249,6 +249,8 @@ void TransitionEditorToolBar::createRightControls()
addSpacing(10);
m_scale = new QSlider(this);
m_scale->setProperty("panelwidget", true);
m_scale->setProperty("panelwidget_singlerow", true);
m_scale->setOrientation(Qt::Horizontal);
m_scale->setMaximumWidth(200);
m_scale->setMinimumWidth(100);