1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenprogressbar.cpp
3
// data container for progressbar animations
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
27
#include "oxygenprogressbardata.h"
28
#include "oxygenprogressbardata.moc"
30
#include <QtGui/QProgressBar>
36
//______________________________________________
37
ProgressBarData::ProgressBarData( QObject* parent, QWidget* target, int duration ):
38
GenericData( parent, target, duration ),
43
target->installEventFilter( this );
45
// set animation curve shape
46
animation().data()->setEasingCurve( QEasingCurve::InOutQuad );
48
// make sure target is a progressbar and store relevant values
49
QProgressBar* progress = qobject_cast<QProgressBar*>( target );
51
setStartValue( progress->value() );
52
setEndValue( progress->value() );
55
connect( target, SIGNAL( valueChanged( int ) ), SLOT( valueChanged( int ) ) );
59
//______________________________________________
60
bool ProgressBarData::eventFilter( QObject* object, QEvent* event )
63
if( !( enabled() && object && object == target().data() ) ) return AnimationData::eventFilter( object, event );
64
switch( event->type() )
69
// reset start and end value
70
QProgressBar* progress = static_cast<QProgressBar*>( target().data() );
71
setStartValue( progress->value() );
72
setEndValue( progress->value() );
79
if( animation().data()->isRunning() )
80
{ animation().data()->stop(); }
88
return AnimationData::eventFilter( object, event );
92
//______________________________________________
93
void ProgressBarData::valueChanged( int value )
96
// do nothing if not enabled
97
if( !enabled() ) return;
99
// do nothing if progress is invalid
100
QProgressBar* progress = static_cast<QProgressBar*>( target().data() );
101
if( !( progress && progress->maximum() != progress->minimum() ) ) return;
103
// update start and end values
104
bool isRunning( animation().data()->isRunning() );
108
// in case next value arrives while animation is running,
109
// end animation, set value immediately
110
// and trigger target update. This increases responsiveness of progressbars
111
setStartValue( value );
112
setEndValue( value );
113
animation().data()->stop();
116
if( target() ) target().data()->update();
122
setStartValue( endValue() );
123
setEndValue( value );
125
// start animation only if target is enabled, visible, not running,
126
// and if end and start values are different enough
127
// (with end value being larger than start value)
128
if( !(target() && target().data()->isEnabled() && target().data()->isVisible()) ) return;
129
if( isRunning || endValue()-startValue() < 2 ) return;
131
animation().data()->start();