Changeset View
Standalone View
kstyle/breezestyle.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 5003 Lines • ▼ Show 20 Line(s) | 5002 | { | |||
---|---|---|---|---|---|
5004 | // cast option and check | 5004 | // cast option and check | ||
5005 | const auto sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) ); | 5005 | const auto sliderOption( qstyleoption_cast<const QStyleOptionSlider*>( option ) ); | ||
5006 | if( !sliderOption ) return true; | 5006 | if( !sliderOption ) return true; | ||
5007 | 5007 | | |||
5008 | // copy rect and palette | 5008 | // copy rect and palette | ||
5009 | const auto& rect( option->rect ); | 5009 | const auto& rect( option->rect ); | ||
5010 | const auto& palette( option->palette ); | 5010 | const auto& palette( option->palette ); | ||
5011 | 5011 | | |||
5012 | //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 | ||||
5013 | const bool widgetMouseOver( widget ? _animations->scrollBarEngine().isHovered( widget, QStyle::SC_ScrollBarGroove ) : option->styleObject->property("hover").toBool()); | ||||
5014 | | ||||
5015 | qreal grooveAnimationOpacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) ); | ||||
5016 | if( grooveAnimationOpacity == AnimationData::OpacityInvalid ) grooveAnimationOpacity = (widgetMouseOver ? 1 : 0); | ||||
hpereiradacosta: Ok. Just checked: this whole code should still work if replaced by:
const bool… | |||||
it works ok for the qwidget case, unfortunately in the case of qml, _animations will always be empty, so i still have to check option->styleObject anyways mart: it works ok for the qwidget case, unfortunately in the case of qml, _animations will always be… | |||||
this is the shortest form i could come up which works with both qwidgets and qml mart: this is the shortest form i could come up which works with both qwidgets and qml | |||||
5017 | const qreal handleSize = StyleConfigData::animationsEnabled() ? ((Metrics::ScrollBar_SliderWidth / 2.0) * (1 - grooveAnimationOpacity) + Metrics::ScrollBar_SliderWidth * grooveAnimationOpacity) : (int)Metrics::ScrollBar_SliderWidth; | ||||
5018 | | ||||
5012 | // define handle rect | 5019 | // define handle rect | ||
5013 | QRect handleRect; | 5020 | QRect handleRect; | ||
5014 | const State& state( option->state ); | 5021 | const State& state( option->state ); | ||
5015 | const bool horizontal( state & State_Horizontal ); | 5022 | const bool horizontal( state & State_Horizontal ); | ||
5016 | if( horizontal ) handleRect = centerRect( rect, rect.width(), Metrics::ScrollBar_SliderWidth ); | 5023 | if( horizontal ) handleRect = centerRect( rect, rect.width(), handleSize ); | ||
5017 | else handleRect = centerRect( rect, Metrics::ScrollBar_SliderWidth, rect.height() ); | 5024 | else handleRect = centerRect( rect, handleSize, rect.height() ); | ||
5018 | 5025 | | |||
5019 | const bool enabled( state & State_Enabled ); | 5026 | const bool enabled( state & State_Enabled ); | ||
5020 | const bool mouseOver( enabled && ( state & State_MouseOver ) ); | 5027 | const bool mouseOver( enabled && ( state & State_MouseOver ) ); | ||
5021 | 5028 | | |||
5022 | // check focus from relevant parent | 5029 | // check focus from relevant parent | ||
5023 | const QWidget* parent( scrollBarParent( widget ) ); | 5030 | const QWidget* parent( scrollBarParent( widget ) ); | ||
5024 | const bool hasFocus( enabled && ( (widget && widget->hasFocus()) || (parent && parent->hasFocus()) ) ); | 5031 | const bool hasFocus( enabled && ( (widget && widget->hasFocus()) || (parent && parent->hasFocus()) ) ); | ||
5025 | 5032 | | |||
5026 | // enable animation state | 5033 | // enable animation state | ||
5027 | const bool handleActive( sliderOption->activeSubControls & SC_ScrollBarSlider ); | 5034 | const bool handleActive( sliderOption->activeSubControls & SC_ScrollBarSlider ); | ||
5028 | _animations->scrollBarEngine().updateState( widget, AnimationFocus, hasFocus ); | 5035 | _animations->scrollBarEngine().updateState( widget, AnimationFocus, hasFocus ); | ||
5029 | 5036 | | |||
5030 | _animations->scrollBarEngine().updateState( widget, AnimationHover, mouseOver && handleActive ); | 5037 | _animations->scrollBarEngine().updateState( widget, AnimationHover, mouseOver && handleActive ); | ||
5031 | 5038 | | |||
5032 | const auto mode( _animations->scrollBarEngine().animationMode( widget, SC_ScrollBarSlider ) ); | 5039 | const auto mode( _animations->scrollBarEngine().animationMode( widget, SC_ScrollBarSlider ) ); | ||
5033 | const qreal opacity( _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) ); | 5040 | const qreal opacity( _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) ); | ||
5034 | const auto color = _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode ); | 5041 | auto color = _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode ); | ||
5042 | if (StyleConfigData::animationsEnabled()) { | ||||
5043 | color.setAlphaF(color.alphaF() * (0.7 + 0.3 * grooveAnimationOpacity)); | ||||
This generates some warnings here, because 0.7 + grooveAnimationOpacity can become larger than unity. hpereiradacosta: This generates some warnings here, because 0.7 + grooveAnimationOpacity can become larger than… | |||||
5044 | } | ||||
5035 | 5045 | | |||
5036 | _helper->renderScrollBarHandle( painter, handleRect, color ); | 5046 | _helper->renderScrollBarHandle( painter, handleRect, color ); | ||
5037 | return true; | 5047 | return true; | ||
5038 | } | 5048 | } | ||
This whole code feels hackish. hpereiradacosta: This whole code feels hackish.
In principle we know (elsewhere in the code), if any part of the… | |||||
One possibility, maybe, would be to call drawScrollbarSliderControl explicitely in drawScrollBarComplexControl rather than letting the parent class method do that, and just pass it a modified (smaller) rectangle when not mouseovered. hpereiradacosta: One possibility, maybe, would be to call drawScrollbarSliderControl explicitely in… | |||||
mart: you mean making drawScrollBarSliderControl a complete noop? | |||||
i like the second option, calling by hand drawScrollBarSliderControl, tough it would still need to call the superclass drawScrollBarComplexControl? which then would have to know about not drawing the handle? mart: i like the second option, calling by hand drawScrollBarSliderControl, tough it would still need… | |||||
Yeah this needs some thinking. Maybe not call the base class drawComplexControl and implement all the subcontrol calls ourselves ? Disable the call for slider subcontrol (CE_ScrollBarSlider), as we already do for CE_ScrollBarAddPage and SubPage ? The second has the disadvantage that applications that call this control element directly (for say a custom scrollbar), will get broken. hpereiradacosta: Yeah this needs some thinking.
Maybe not call the base class drawComplexControl and implement… | |||||
5039 | 5049 | | |||
5040 | //___________________________________________________________________________________ | 5050 | //___________________________________________________________________________________ | ||
5041 | bool Style::drawScrollBarAddLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | 5051 | bool Style::drawScrollBarAddLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const | ||
5042 | { | 5052 | { | ||
5043 | 5053 | | |||
5044 | // do nothing if no buttons are defined | 5054 | // do nothing if no buttons are defined | ||
5045 | if( _addLineButtons == NoButton ) return true; | 5055 | if( _addLineButtons == NoButton ) return true; | ||
5046 | 5056 | | |||
▲ Show 20 Lines • Show All 2081 Lines • Show Last 20 Lines |
Ok. Just checked: this whole code should still work if replaced by:
(used elsewhere also)
it relies on the fact that hover state is properly updated, which seems to be the case, at least with QWidget.
Can you double check with QtQuick ? If yes, that would be a nice replacement.