implemented pressed animations for radio buttons and checkboxes

wilder-pre-rebase
Hugo Pereira Da Costa 12 years ago
parent 15b5aae3fe
commit ce4be0f35c
  1. 6
      kstyle/animations/breezeanimations.cpp
  2. 8
      kstyle/animations/breezewidgetstateengine.cpp
  3. 3
      kstyle/animations/breezewidgetstateengine.h
  4. 13
      kstyle/breeze.h
  5. 35
      kstyle/breezehelper.cpp
  6. 4
      kstyle/breezehelper.h
  7. 19
      kstyle/breezestyle.cpp

@ -33,12 +33,14 @@
#include <QAbstractItemView>
#include <QComboBox>
#include <QCheckBox>
#include <QDial>
#include <QGroupBox>
#include <QHeaderView>
#include <QLineEdit>
#include <QMdiSubWindow>
#include <QProgressBar>
#include <QRadioButton>
#include <QScrollBar>
#include <QSpinBox>
#include <QTextEdit>
@ -124,6 +126,10 @@ namespace Breeze
_widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus );
} else if( qobject_cast<QCheckBox*>(widget) || qobject_cast<QRadioButton*>(widget) ) {
_widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus|AnimationPressed );
} else if( qobject_cast<QAbstractButton*>(widget) ) {
// register to toolbox engine if needed

@ -41,6 +41,7 @@ namespace Breeze
if( mode&AnimationHover && !_hoverData.contains( widget ) ) { _hoverData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
if( mode&AnimationFocus && !_focusData.contains( widget ) ) { _focusData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
if( mode&AnimationEnable && !_enableData.contains( widget ) ) { _enableData.insert( widget, new EnableData( this, widget, duration() ), enabled() ); }
if( mode&AnimationPressed && !_pressedData.contains( widget ) ) { _pressedData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
// connect destruction signal
connect( widget, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterWidget(QObject*)), Qt::UniqueConnection );
@ -76,6 +77,12 @@ namespace Breeze
{ if( value ) out.insert( value.data()->target().data() ); }
}
if( mode&AnimationPressed )
{
foreach( const Value& value, _pressedData )
{ if( value ) out.insert( value.data()->target().data() ); }
}
return out;
}
@ -105,6 +112,7 @@ namespace Breeze
case AnimationHover: return _hoverData.find( object ).data();
case AnimationFocus: return _focusData.find( object ).data();
case AnimationEnable: return _enableData.find( object ).data();
case AnimationPressed: return _pressedData.find( object ).data();
default: return DataMap<WidgetStateData>::Value();
}

@ -126,6 +126,7 @@ namespace Breeze
_hoverData.setDuration( value );
_focusData.setDuration( value );
_enableData.setDuration( value );
_pressedData.setDuration( value/2 );
}
public Q_SLOTS:
@ -138,6 +139,7 @@ namespace Breeze
if( _hoverData.unregisterWidget( object ) ) found = true;
if( _focusData.unregisterWidget( object ) ) found = true;
if( _enableData.unregisterWidget( object ) ) found = true;
if( _pressedData.unregisterWidget( object ) ) found = true;
return found;
}
@ -152,6 +154,7 @@ namespace Breeze
DataMap<WidgetStateData> _hoverData;
DataMap<WidgetStateData> _focusData;
DataMap<WidgetStateData> _enableData;
DataMap<WidgetStateData> _pressedData;
};

@ -193,12 +193,21 @@ namespace Breeze
Q_DECLARE_FLAGS( Corners, Corner );
//! checkbox state (used for checkboxes _and_ radio buttons)
//! checkbox state
enum CheckBoxState
{
CheckOff,
CheckPartial,
CheckOn
CheckOn,
CheckAnimated
};
//! radio button state
enum RadioButtonState
{
RadioOff,
RadioOn,
RadioAnimated
};
//! arrow orientation

@ -643,7 +643,7 @@ namespace Breeze
void Helper::renderCheckBox(
QPainter* painter, const QRect& rect,
const QColor& color, const QColor& shadow,
bool sunken, CheckBoxState state ) const
bool sunken, CheckBoxState state, qreal animation ) const
{
// setup painter
@ -693,7 +693,7 @@ namespace Breeze
pen.setJoinStyle( Qt::MiterJoin );
painter->setPen( pen );
const QRectF markerRect( frameRect.adjusted( 5, 5, -5, -5 ) );
const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
painter->drawRect( markerRect );
painter->setPen( Qt::NoPen );
@ -706,6 +706,20 @@ namespace Breeze
path.lineTo( 5, qreal( Metrics::CheckBox_Size ) - 6 );
painter->drawPath( path.translated( rect.topLeft() ) );
} else if( state == CheckAnimated ) {
const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
QPainterPath path;
path.moveTo( markerRect.topRight() );
path.lineTo( markerRect.center() + animation*( markerRect.topLeft() - markerRect.center() ) );
path.lineTo( markerRect.bottomLeft() );
path.lineTo( markerRect.center() + animation*( markerRect.bottomRight() - markerRect.center() ) );
path.closeSubpath();
painter->setBrush( color );
painter->setPen( Qt::NoPen );
painter->drawPath( path );
}
}
@ -714,7 +728,7 @@ namespace Breeze
void Helper::renderRadioButton(
QPainter* painter, const QRect& rect,
const QColor& color, const QColor& shadow,
bool sunken, bool checked ) const
bool sunken, RadioButtonState state, qreal animation ) const
{
// setup painter
@ -746,7 +760,7 @@ namespace Breeze
}
// mark
if( checked )
if( state == RadioOn )
{
painter->setBrush( color );
@ -755,6 +769,19 @@ namespace Breeze
const QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
painter->drawEllipse( markerRect );
} else if( state == RadioAnimated ) {
painter->setBrush( color );
painter->setPen( Qt::NoPen );
QRectF markerRect( frameRect.adjusted( 4, 4, -4, -4 ) );
painter->translate( markerRect.center() );
painter->rotate( 45 );
markerRect.setWidth( markerRect.width()*animation );
markerRect.translate( -markerRect.center() );
painter->drawEllipse( markerRect );
}
}

@ -159,10 +159,10 @@ namespace Breeze
void renderSeparator( QPainter*, const QRect&, const QColor&, bool vertical = false ) const;
//! checkbox
void renderCheckBox( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, CheckBoxState state ) const;
void renderCheckBox( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, CheckBoxState state, qreal animation = AnimationData::OpacityInvalid ) const;
//! radio button
void renderRadioButton( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, bool checked ) const;
void renderRadioButton( QPainter*, const QRect&, const QColor& color, const QColor& shadow, bool sunken, RadioButtonState state, qreal animation = AnimationData::OpacityInvalid ) const;
//! slider groove
void renderSliderGroove( QPainter*, const QRect&, const QColor& ) const;

@ -3044,14 +3044,17 @@ namespace Breeze
const AnimationMode mode( _animations->widgetStateEngine().isAnimated( widget, AnimationHover ) ? AnimationHover:AnimationNone );
const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) );
_animations->widgetStateEngine().updateState( widget, AnimationPressed, checkBoxState != CheckOff );
if( _animations->widgetStateEngine().isAnimated( widget, AnimationPressed ) ) checkBoxState = CheckAnimated;
const qreal animation( _animations->widgetStateEngine().opacity( widget, AnimationPressed ) );
// colors
const QPalette& palette( option->palette );
const QColor color( _helper->checkBoxIndicatorColor( palette, mouseOver, enabled && active, opacity, mode ) );
const QColor shadow( _helper->shadowColor( palette ) );
// render
_helper->renderCheckBox( painter, option->rect, color, shadow, sunken, checkBoxState );
_helper->renderCheckBox( painter, option->rect, color, shadow, sunken, checkBoxState, animation );
return true;
}
@ -3067,18 +3070,24 @@ namespace Breeze
const bool sunken( state & State_Sunken );
const bool checked( state & State_On );
// update only mouse over
RadioButtonState radioButtonState( state & State_On ? RadioOn:RadioOff );
// animation state
_animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver );
const AnimationMode mode( _animations->widgetStateEngine().isAnimated( widget, AnimationHover ) ? AnimationHover:AnimationNone );
const qreal opacity( _animations->widgetStateEngine().opacity( widget, AnimationHover ) );
_animations->widgetStateEngine().updateState( widget, AnimationPressed, radioButtonState != RadioOff );
if( _animations->widgetStateEngine().isAnimated( widget, AnimationPressed ) ) radioButtonState = RadioAnimated;
const qreal animation( _animations->widgetStateEngine().opacity( widget, AnimationPressed ) );
// colors
const QPalette& palette( option->palette );
const QColor color( _helper->checkBoxIndicatorColor( palette, mouseOver, enabled && checked, opacity, mode ) );
const QColor shadow( _helper->shadowColor( palette ) );
// render
_helper->renderRadioButton( painter, option->rect, color, shadow, sunken, checked );
_helper->renderRadioButton( painter, option->rect, color, shadow, sunken, radioButtonState, animation );
return true;
@ -3717,7 +3726,7 @@ namespace Breeze
const bool active( menuItemOption->checked );
const QColor color( _helper->checkBoxIndicatorColor( palette, enabled && selected, enabled && active ) );
const QColor shadow( _helper->shadowColor( palette ) );
_helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active );
_helper->renderRadioButton( painter, checkBoxRect, color, shadow, sunken, active ? RadioOn:RadioOff );
}

Loading…
Cancel
Save