From d4b07d9e1daf0dd1185eda8c905c2f2c87541ccf Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 18 Jan 2018 14:13:01 +0100 Subject: [PATCH] even slimmer scrollbars Summary: the scrollbar handle will be very slim normally, and grow a bit on mouse over, this makes it work better with QtQuickControls2 listviews where the contents overlap the scrollbar (as other platform are going in this direction since they all have scrollbars visible only on scroll or mouse over) this makes scrollbars appear more light but still always visible to convey information right now follows animations enabled to use this, as the scrollbar groove already did that, tough a "slim scrollbars" settings may make sense Test Plan: works both as qwidget and with the qstyle-based qqc2-desktop-style Reviewers: #plasma, #kirigami, #vdg, hpereiradacosta, abetts Reviewed By: #plasma, #vdg, hpereiradacosta, abetts Subscribers: davidedmundson, ngraham, colomar, abetts, plasma-devel Tags: #plasma, #kirigami Differential Revision: https://phabricator.kde.org/D9792 --- kstyle/breezestyle.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 6b1324e5..8c2212bd 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -5009,12 +5009,19 @@ namespace Breeze const auto& rect( option->rect ); const auto& palette( option->palette ); + //try to understand if anywhere the widget is under mouse, not just the handle, use _animations in case of QWidget, option->styleObject in case of QML + const bool widgetMouseOver( widget ? _animations->scrollBarEngine().isHovered( widget, QStyle::SC_ScrollBarGroove ) : option->styleObject->property("hover").toBool()); + + qreal grooveAnimationOpacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) ); + if( grooveAnimationOpacity == AnimationData::OpacityInvalid ) grooveAnimationOpacity = (widgetMouseOver ? 1 : 0); + const qreal handleSize = StyleConfigData::animationsEnabled() ? ((Metrics::ScrollBar_SliderWidth / 2.0) * (1 - grooveAnimationOpacity) + Metrics::ScrollBar_SliderWidth * grooveAnimationOpacity) : (int)Metrics::ScrollBar_SliderWidth; + // define handle rect QRect handleRect; const State& state( option->state ); const bool horizontal( state & State_Horizontal ); - if( horizontal ) handleRect = centerRect( rect, rect.width(), Metrics::ScrollBar_SliderWidth ); - else handleRect = centerRect( rect, Metrics::ScrollBar_SliderWidth, rect.height() ); + if( horizontal ) handleRect = centerRect( rect, rect.width(), handleSize ); + else handleRect = centerRect( rect, handleSize, rect.height() ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); @@ -5031,7 +5038,10 @@ namespace Breeze const auto mode( _animations->scrollBarEngine().animationMode( widget, SC_ScrollBarSlider ) ); const qreal opacity( _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) ); - const auto color = _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode ); + auto color = _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode ); + if (StyleConfigData::animationsEnabled()) { + color.setAlphaF(color.alphaF() * (0.7 + 0.3 * grooveAnimationOpacity)); + } _helper->renderScrollBarHandle( painter, handleRect, color ); return true;