From 277e39253fbddfbb9cbb141445467d4cd48a87a0 Mon Sep 17 00:00:00 2001 From: Hugo Pereira Da Costa Date: Thu, 7 Aug 2014 19:47:43 +0200 Subject: [PATCH] Simplified scrollbar rendering Re-added option to set number of buttons --- kstyle/breeze.kcfg | 9 +++ kstyle/breezestyle.cpp | 149 +++++++++++++---------------------------- kstyle/breezestyle.h | 3 - 3 files changed, 54 insertions(+), 107 deletions(-) diff --git a/kstyle/breeze.kcfg b/kstyle/breeze.kcfg index 00a5ca9e..14ede1c6 100644 --- a/kstyle/breeze.kcfg +++ b/kstyle/breeze.kcfg @@ -35,6 +35,15 @@ 800 + + + 1 + + + + 1 + + diff --git a/kstyle/breezestyle.cpp b/kstyle/breezestyle.cpp index 633d6e05..5092750d 100644 --- a/kstyle/breezestyle.cpp +++ b/kstyle/breezestyle.cpp @@ -831,9 +831,11 @@ namespace Breeze // scrollbars case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; - case CE_ScrollBarAddPage: fcn = &Style::drawScrollBarAddPageControl; break; case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; - case CE_ScrollBarSubPage: fcn = &Style::drawScrollBarSubPageControl; break; + + // these two are handled directly in CC_ScrollBar + case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; + case CE_ScrollBarSubPage: fcn = &Style::emptyControl; break; // frame case CE_ShapedFrame: fcn = &Style::drawShapedFrameControl; break; @@ -1093,6 +1095,25 @@ namespace Breeze // clear icon cache _iconCache.clear(); + // scrollbar buttons + switch( StyleConfigData::scrollBarAddLineButtons() ) + { + case 0: _addLineButtons = NoButton; break; + case 1: _addLineButtons = SingleButton; break; + + default: + case 2: _addLineButtons = DoubleButton; break; + } + + switch( StyleConfigData::scrollBarSubLineButtons() ) + { + case 0: _subLineButtons = NoButton; break; + case 1: _subLineButtons = SingleButton; break; + + default: + case 2: _subLineButtons = DoubleButton; break; + } + } //___________________________________________________________________________________________________________________ @@ -3796,33 +3817,13 @@ namespace Breeze const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); - QWidget* parent( scrollBarParent( widget ) ); + // check focus from relevant parent + const QWidget* parent( scrollBarParent( widget ) ); const bool focus( enabled && parent && parent->hasFocus() ); // enable animation state _animations->scrollBarEngine().updateState( widget, enabled && ( sliderOption->activeSubControls & SC_ScrollBarSlider ) ); const qreal opacity( _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) ); - if( widget ) - { - // render background - // it is necessary to retrieve the complete widget rect, in order to properly handle overlaps - // at the scrollbar boundary - // define color - // TODO: try use subControlRect instead - const QPalette& palette( option->palette ); - const QColor color( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.3 ) ); - - // adjust rect - QStyleOptionSlider copy( *sliderOption ); - copy.rect = widget->rect(); - QRect backgroundRect( scrollBarSubControlRect( ©, SC_ScrollBarGroove, widget ) ); - if( horizontal ) backgroundRect = centerRect( backgroundRect, backgroundRect.width(), Metrics::ScrollBar_SliderWidth ); - else backgroundRect = centerRect( backgroundRect, Metrics::ScrollBar_SliderWidth, backgroundRect.height() ); - - _helper->renderScrollBarGroove( painter, backgroundRect, color ); - - } - { // render handle // define colors @@ -3918,46 +3919,6 @@ namespace Breeze return true; } - //___________________________________________________________________________________ - bool Style::drawScrollBarAddPageControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const - { - - // cast option and check - const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); - if ( !sliderOption ) return true; - - painter->setClipRect( option->rect ); - - const QPalette& palette( option->palette ); - const QColor color( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.3 ) ); - const State& state( option->state ); - - // define tiles and adjust rect - QRect backgroundRect; - const bool horizontal( state & State_Horizontal ); - const bool reverseLayout( sliderOption->direction == Qt::RightToLeft ); - - if( horizontal ) - { - - backgroundRect = centerRect( option->rect, option->rect.width(), Metrics::ScrollBar_SliderWidth ); - if( reverseLayout ) backgroundRect.adjust( 0, 0, Metrics::ScrollBar_SliderWidth/2, 0 ); - else backgroundRect.adjust( -Metrics::ScrollBar_SliderWidth/2, 0, 0, 0 ); - - - } else { - - backgroundRect = centerRect( option->rect, Metrics::ScrollBar_SliderWidth, option->rect.height() ); - backgroundRect.adjust( 0, -Metrics::ScrollBar_SliderWidth/2, 0, 0 ); - - } - - // render - _helper->renderScrollBarGroove( painter, backgroundRect, color ); - - return true; - - } //___________________________________________________________________________________ bool Style::drawScrollBarSubLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const @@ -4035,46 +3996,6 @@ namespace Breeze return true; } - //___________________________________________________________________________________ - bool Style::drawScrollBarSubPageControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const - { - - // cast option and check - const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); - if ( !sliderOption ) return true; - - painter->setClipRect( option->rect ); - - const QPalette& palette( option->palette ); - const QColor color( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.3 ) ); - const State& state( option->state ); - - // define tiles and adjust rect - QRect backgroundRect; - const bool horizontal( state & State_Horizontal ); - const bool reverseLayout( sliderOption->direction == Qt::RightToLeft ); - - if( horizontal ) - { - - backgroundRect = centerRect( option->rect, option->rect.width(), Metrics::ScrollBar_SliderWidth ); - if( reverseLayout ) backgroundRect.adjust( -Metrics::ScrollBar_SliderWidth/2, 0, 0, 0 ); - else backgroundRect.adjust( 0, 0, Metrics::ScrollBar_SliderWidth/2-1, 0 ); - - } else { - - backgroundRect = centerRect( option->rect, Metrics::ScrollBar_SliderWidth, option->rect.height() ); - backgroundRect.adjust( 0, 0, 0, Metrics::ScrollBar_SliderWidth/2-1 ); - - } - - // render - _helper->renderScrollBarGroove( painter, backgroundRect, color ); - - return true; - - } - //___________________________________________________________________________________ bool Style::drawShapedFrameControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const { @@ -5165,6 +5086,7 @@ namespace Breeze bool Style::drawScrollBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { + // render background behind widget with correct role if( widget ) { painter->setBrush( option->palette.color( widget->backgroundRole() ) ); @@ -5172,6 +5094,25 @@ namespace Breeze painter->drawRect( option->rect ); } + // render full groove directly, rather than using the addPage and subPage control element methods + if( option->subControls && SC_ScrollBarGroove ) + { + // retrieve groove rectangle + QRect grooveRect( subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) ); + + const QPalette& palette( option->palette ); + const QColor color( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.3 ) ); + const State& state( option->state ); + const bool horizontal( state & State_Horizontal ); + + if( horizontal ) grooveRect = centerRect( grooveRect, grooveRect.width(), Metrics::ScrollBar_SliderWidth ); + else grooveRect = centerRect( grooveRect, Metrics::ScrollBar_SliderWidth, grooveRect.height() ); + + // render + _helper->renderScrollBarGroove( painter, grooveRect, color ); + + } + // call base class primitive KStyle::drawComplexControl( CC_ScrollBar, option, painter, widget ); return true; diff --git a/kstyle/breezestyle.h b/kstyle/breezestyle.h index 8b76a071..88d7fd49 100644 --- a/kstyle/breezestyle.h +++ b/kstyle/breezestyle.h @@ -278,7 +278,6 @@ namespace Breeze // bool drawIndicatorTabTearPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorToolBarHandlePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorToolBarSeparatorPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; -// bool drawWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorBranchPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; //@} @@ -303,8 +302,6 @@ namespace Breeze virtual bool drawScrollBarSliderControl( const QStyleOption*, QPainter*, const QWidget* ) const; virtual bool drawScrollBarAddLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; virtual bool drawScrollBarSubLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawScrollBarAddPageControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawScrollBarSubPageControl( const QStyleOption*, QPainter*, const QWidget* ) const; virtual bool drawShapedFrameControl( const QStyleOption*, QPainter*, const QWidget* ) const; virtual bool drawRubberBandControl( const QStyleOption*, QPainter*, const QWidget* ) const;