Show full scrollbar only on mouse over

Summary:
This is a proof of conceptof lighter scrollbars, according to
ideas from the VDG:
show only a tiny placeholder normally, and show the full scrollbar
only on mouse over.

Test Plan:
tested on few applications but i know well the
code is just an early hacky proof of concept,
so i'll redesign it as requested.
being a big visible thing, it will probably need
an option as well to make it behave as it used to.
in action https://www.youtube.com/watch?v=O72qxQHjHcw

Reviewers: #plasma, #breeze, #vdg, hpereiradacosta

Reviewed By: hpereiradacosta

Subscribers: plasma-devel, abetts

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D3131
wilder-pre-rebase
Marco Martin 9 years ago
parent 58ee05914a
commit e33206e4f7
  1. 16
      kstyle/animations/breezescrollbardata.cpp
  2. 30
      kstyle/animations/breezescrollbardata.h
  3. 5
      kstyle/breeze.kcfg
  4. 54
      kstyle/breezestyle.cpp
  5. 4
      kstyle/config/breezestyleconfig.cpp
  6. 53
      kstyle/config/ui/breezestyleconfig.ui

@ -38,6 +38,7 @@ namespace Breeze
_addLineData._animation = new Animation( duration, this );
_subLineData._animation = new Animation( duration, this );
_grooveData._animation = new Animation( duration, this );
connect( addLineAnimation().data(), SIGNAL(finished()), SLOT(clearAddLineRect()) );
connect( subLineAnimation().data(), SIGNAL(finished()), SLOT(clearSubLineRect()) );
@ -45,6 +46,7 @@ namespace Breeze
// setup animation
setupAnimation( addLineAnimation(), "addLineOpacity" );
setupAnimation( subLineAnimation(), "subLineOpacity" );
setupAnimation( grooveAnimation(), "grooveOpacity" );
}
@ -60,12 +62,20 @@ namespace Breeze
{
case QEvent::HoverEnter:
setGrooveHovered(true);
grooveAnimation().data()->setDirection( Animation::Forward );
if( !grooveAnimation().data()->isRunning() ) grooveAnimation().data()->start();
case QEvent::HoverMove:
hoverMoveEvent( object, event );
break;
case QEvent::HoverLeave:
setGrooveHovered(false);
grooveAnimation().data()->setDirection( Animation::Backward );
if( !grooveAnimation().data()->isRunning() ) grooveAnimation().data()->start();
hoverLeaveEvent( object, event );
break;
default: break;
@ -90,6 +100,9 @@ namespace Breeze
case QStyle::SC_ScrollBarSubLine:
return subLineAnimation();
case QStyle::SC_ScrollBarGroove:
return grooveAnimation();
}
}
@ -108,6 +121,9 @@ namespace Breeze
case QStyle::SC_ScrollBarSubLine:
return subLineOpacity();
case QStyle::SC_ScrollBarGroove:
return grooveOpacity();
}
}

@ -34,6 +34,7 @@ namespace Breeze
Q_OBJECT
Q_PROPERTY( qreal addLineOpacity READ addLineOpacity WRITE setAddLineOpacity )
Q_PROPERTY( qreal subLineOpacity READ subLineOpacity WRITE setSubLineOpacity )
Q_PROPERTY( qreal grooveOpacity READ grooveOpacity WRITE setGrooveOpacity )
public:
@ -64,6 +65,7 @@ namespace Breeze
{
case QStyle::SC_ScrollBarAddLine: return addLineArrowHovered();
case QStyle::SC_ScrollBarSubLine: return subLineArrowHovered();
case QStyle::SC_ScrollBarGroove: return grooveHovered();
default: return false;
}
@ -105,6 +107,7 @@ namespace Breeze
WidgetStateData::setDuration( duration );
addLineAnimation().data()->setDuration( duration );
subLineAnimation().data()->setDuration( duration );
grooveAnimation().data()->setDuration( duration );
}
//* addLine opacity
@ -133,6 +136,19 @@ namespace Breeze
virtual qreal subLineOpacity( void ) const
{ return _subLineData._opacity; }
//* groove opacity
virtual void setGrooveOpacity( qreal value )
{
value = digitize( value );
if( _grooveData._opacity == value ) return;
_grooveData._opacity = value;
setDirty();
}
//* groove opacity
virtual qreal grooveOpacity( void ) const
{ return _grooveData._opacity; }
//* mouse position
QPoint position( void ) const
{ return _position; }
@ -176,6 +192,12 @@ namespace Breeze
virtual void setSubLineArrowHovered( bool value )
{ _subLineData._hovered = value; }
virtual bool grooveHovered( void ) const
{ return _grooveData._hovered; }
virtual void setGrooveHovered( bool value )
{ _grooveData._hovered = value; }
//@}
//* update add line arrow
@ -193,9 +215,12 @@ namespace Breeze
virtual const Animation::Pointer& subLineAnimation( void ) const
{ return _subLineData._animation; }
virtual const Animation::Pointer& grooveAnimation( void ) const
{ return _grooveData._animation; }
private:
//* stores arrow data
//* stores sub control data
class Data
{
@ -228,6 +253,9 @@ namespace Breeze
//* subtract line data (up arrow)
Data _subLineData;
//* groove data
Data _grooveData;
//* mouse position
QPoint _position;

@ -72,6 +72,11 @@
<default>1</default>
</entry>
<!-- show scrollbar pieces only on hover? -->
<entry name="ScrollBarShowOnMouseOver" type="Bool">
<default>true</default>
</entry>
<!-- mnemonics -->
<entry name="MnemonicsMode" type="Enum">
<choices>

@ -4956,13 +4956,14 @@ namespace Breeze
// enable animation state
const bool handleActive( sliderOption->activeSubControls & SC_ScrollBarSlider );
_animations->scrollBarEngine().updateState( widget, AnimationFocus, hasFocus );
_animations->scrollBarEngine().updateState( widget, AnimationHover, mouseOver && handleActive );
const AnimationMode mode( _animations->scrollBarEngine().animationMode( widget, SC_ScrollBarSlider ) );
const qreal opacity( _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) );
const QColor color = _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode );
const QColor color( _helper->scrollBarHandleColor( palette, mouseOver, hasFocus, opacity, mode ) );
_helper->renderScrollBarHandle( painter, handleRect, color );
return true;
}
@ -6357,15 +6358,22 @@ namespace Breeze
//______________________________________________________________
bool Style::drawScrollBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const
{
//the animation for QStyle::SC_ScrollBarGroove is special: it will animate
//the opacity of everything else as well, included slider and arrows
qreal opacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) );
const bool animated( StyleConfigData::scrollBarShowOnMouseOver() && _animations->scrollBarEngine().isAnimated( widget, AnimationHover, QStyle::SC_ScrollBarGroove ) );
const bool mouseOver( option->state & State_MouseOver );
if( opacity == AnimationData::OpacityInvalid ) opacity = 1;
// render full groove directly, rather than using the addPage and subPage control element methods
if( option->subControls & SC_ScrollBarGroove )
if( (mouseOver || animated) && 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 QColor color( _helper->alphaColor( palette.color( QPalette::WindowText ), 0.3 * (animated ? opacity : 1) ) );
const State& state( option->state );
const bool horizontal( state & State_Horizontal );
@ -6374,11 +6382,11 @@ namespace Breeze
// render
_helper->renderScrollBarGroove( painter, grooveRect, color );
}
// call base class primitive
ParentStyleClass::drawComplexControl( CC_ScrollBar, option, painter, widget );
return true;
}
@ -6638,9 +6646,23 @@ namespace Breeze
const QPalette& palette( option->palette );
QColor color( _helper->arrowColor( palette, QPalette::WindowText ) );
bool widgetMouseOver;
if( widget ) widgetMouseOver = widget->underMouse();
// in case this QStyle is used by QQuickControls QStyle wrapper
else if( option->styleObject ) widgetMouseOver = option->styleObject->property("hover").toBool();
// check enabled state
const bool enabled( option->state & State_Enabled );
if( !enabled ) return color;
if( !enabled ) {
if( StyleConfigData::scrollBarShowOnMouseOver() ) {
// finally, global opacity when ScrollBarShowOnMouseOver
const qreal globalOpacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) );
if( globalOpacity >= 0 ) color.setAlphaF( globalOpacity );
// no mouse over and no animation in progress, don't draw arrows at all
else if( !widgetMouseOver ) return Qt::transparent;
}
return color;
}
if(
( control == SC_ScrollBarSubLine && option->sliderValue == option->minimum ) ||
@ -6648,8 +6670,15 @@ namespace Breeze
{
// manually disable arrow, to indicate that scrollbar is at limit
return _helper->arrowColor( palette, QPalette::Disabled, QPalette::WindowText );
color = _helper->arrowColor( palette, QPalette::Disabled, QPalette::WindowText );
if( StyleConfigData::scrollBarShowOnMouseOver() ) {
// finally, global opacity when ScrollBarShowOnMouseOver
const qreal globalOpacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) );
if( globalOpacity >= 0 ) color.setAlphaF( globalOpacity );
// no mouse over and no animation in progress, don't draw arrows at all
else if( !widgetMouseOver ) return Qt::transparent;
}
return color;
}
const bool mouseOver( _animations->scrollBarEngine().isHovered( widget, control ) );
@ -6684,6 +6713,15 @@ namespace Breeze
}
if( StyleConfigData::scrollBarShowOnMouseOver() ) {
const bool mouseOver( ( option->state & State_MouseOver ) );
// finally, global opacity when ScrollBarShowOnMouseOver
const qreal globalOpacity( _animations->scrollBarEngine().opacity( widget, QStyle::SC_ScrollBarGroove ) );
if( globalOpacity >= 0 ) color.setAlphaF( globalOpacity );
// no mouse over and no animation in progress, don't draw arrows at all
else if( !widgetMouseOver ) return Qt::transparent;
}
return color;
}

@ -63,6 +63,7 @@ namespace Breeze
connect( _animationsDuration, SIGNAL(valueChanged(int)), SLOT(updateChanged()) );
connect( _scrollBarAddLineButtons, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( _scrollBarSubLineButtons, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( _scrollBarShowOnMouseOver, SIGNAL(toggled(bool)), SLOT(updateChanged()) );
connect( _windowDragMode, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
}
@ -82,6 +83,7 @@ namespace Breeze
StyleConfigData::setMnemonicsMode( _mnemonicsMode->currentIndex() );
StyleConfigData::setScrollBarAddLineButtons( _scrollBarAddLineButtons->currentIndex() );
StyleConfigData::setScrollBarSubLineButtons( _scrollBarSubLineButtons->currentIndex() );
StyleConfigData::setScrollBarShowOnMouseOver( _scrollBarShowOnMouseOver->isChecked() );
StyleConfigData::setAnimationsEnabled( _animationsEnabled->isChecked() );
StyleConfigData::setAnimationsDuration( _animationsDuration->value() );
StyleConfigData::setWindowDragMode( _windowDragMode->currentIndex() );
@ -143,6 +145,7 @@ namespace Breeze
else if( _mnemonicsMode->currentIndex() != StyleConfigData::mnemonicsMode() ) modified = true;
else if( _scrollBarAddLineButtons->currentIndex() != StyleConfigData::scrollBarAddLineButtons() ) modified = true;
else if( _scrollBarSubLineButtons->currentIndex() != StyleConfigData::scrollBarSubLineButtons() ) modified = true;
else if( _scrollBarShowOnMouseOver->isChecked() != StyleConfigData::scrollBarShowOnMouseOver() ) modified = true;
else if( _splitterProxyEnabled->isChecked() != StyleConfigData::splitterProxyEnabled() ) modified = true;
else if( _animationsEnabled->isChecked() != StyleConfigData::animationsEnabled() ) modified = true;
else if( _animationsDuration->value() != StyleConfigData::animationsDuration() ) modified = true;
@ -168,6 +171,7 @@ namespace Breeze
_splitterProxyEnabled->setChecked( StyleConfigData::splitterProxyEnabled() );
_scrollBarAddLineButtons->setCurrentIndex( StyleConfigData::scrollBarAddLineButtons() );
_scrollBarSubLineButtons->setCurrentIndex( StyleConfigData::scrollBarSubLineButtons() );
_scrollBarShowOnMouseOver->setChecked( StyleConfigData::scrollBarShowOnMouseOver() );
_animationsEnabled->setChecked( StyleConfigData::animationsEnabled() );
_animationsDuration->setValue( StyleConfigData::animationsDuration() );
_windowDragMode->setCurrentIndex( StyleConfigData::windowDragMode() );

@ -6,12 +6,21 @@
<rect>
<x>0</x>
<y>0</y>
<width>464</width>
<width>508</width>
<height>246</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -279,10 +288,23 @@
<string>Scrollbars</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="_scrollBarAddLineLabel">
<property name="text">
<string>Botto&amp;m arrow button type:</string>
<string>Bottom arrow button t&amp;ype:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -343,20 +365,7 @@
</item>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<item row="3" column="0" colspan="3">
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -369,6 +378,16 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="_scrollBarShowOnMouseOver">
<property name="text">
<string>Only show full scrollbar on mouse over</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>

Loading…
Cancel
Save