Simplified scrollbar rendering

Re-added option to set number of buttons
wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent c0bf8d33bc
commit 277e39253f
  1. 9
      kstyle/breeze.kcfg
  2. 149
      kstyle/breezestyle.cpp
  3. 3
      kstyle/breezestyle.h

@ -35,6 +35,15 @@
<default>800</default>
</entry>
<!-- scrollbar buttons -->
<entry name="ScrollBarAddLineButtons" type="Int">
<default>1</default>
</entry>
<entry name="ScrollBarSubLineButtons" type="Int">
<default>1</default>
</entry>
<!-- mnemonics -->
<entry name="MnemonicsMode" type="Enum">
<choices>

@ -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( &copy, 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<const QStyleOptionSlider*>( 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<const QStyleOptionSlider*>( 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;

@ -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;

Loading…
Cancel
Save