1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenprogressbarengine.cpp
3
// handle progress bar animations
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
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 "oxygenprogressbarengine.h"
28
#include "oxygenprogressbarengine.moc"
33
//_______________________________________________
34
const char* const ProgressBarEngine::busyValuePropertyName = "_kde_oxygen_busy_value";
36
//_______________________________________________
37
bool ProgressBarEngine::registerWidget( QWidget* widget )
41
if( !widget ) return false;
43
// create new data class
44
if( !_data.contains( widget ) ) _data.insert( widget, new ProgressBarData( this, widget, duration() ), enabled() );
45
if( busyIndicatorEnabled() && !_dataSet.contains( widget ) )
47
widget->setProperty( busyValuePropertyName, 0 );
48
_dataSet.insert( widget );
51
// connect destruction signal
52
connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
58
//____________________________________________________________
59
bool ProgressBarEngine::isAnimated( const QObject* object )
62
DataMap<ProgressBarData>::Value data( ProgressBarEngine::data( object ) );
63
return ( data && data.data()->animation() && data.data()->animation().data()->isRunning() );
67
//____________________________________________________________
68
void ProgressBarEngine::setBusyStepDuration( int value )
70
if( _busyStepDuration == value ) return;
71
_busyStepDuration = value;
73
// restart timer with specified time
74
if( _timer.isActive() )
77
_timer.start( busyStepDuration(), this );
82
//_______________________________________________
83
void ProgressBarEngine::timerEvent( QTimerEvent* event )
86
// check enability and timer
87
if( !(busyIndicatorEnabled() && event->timerId() == _timer.timerId() ) )
88
{ return BaseEngine::timerEvent( event ); }
90
bool animated( false );
92
// loop over objects in map
93
for( ProgressBarSet::iterator iter = _dataSet.begin(); iter != _dataSet.end(); ++iter )
96
// cast to progressbar
97
QProgressBar* progressBar( qobject_cast<QProgressBar*>( *iter ) );
99
// check cast, visibility and range
100
if( progressBar && progressBar->isVisible() && progressBar->minimum() == 0 && progressBar->maximum() == 0 )
103
// update animation flag
107
progressBar->setProperty( busyValuePropertyName, progressBar->property( busyValuePropertyName ).toInt()+1 );
108
progressBar->update();
110
} else if( *iter ) { (*iter)->setProperty( busyValuePropertyName, 0 ); }
114
if( !animated ) _timer.stop();
118
//____________________________________________________________
119
DataMap<ProgressBarData>::Value ProgressBarEngine::data( const QObject* object )
120
{ return _data.find( object ).data(); }