~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenprogressbarengine.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygenprogressbarengine.cpp
 
3
// handle progress bar animations
 
4
// -------------------
 
5
//
 
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
7
//
 
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:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
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
 
24
// IN THE SOFTWARE.
 
25
//////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#include "oxygenprogressbarengine.h"
 
28
#include "oxygenprogressbarengine.moc"
 
29
 
 
30
namespace Oxygen
 
31
{
 
32
 
 
33
    //_______________________________________________
 
34
    const char* const ProgressBarEngine::busyValuePropertyName = "_kde_oxygen_busy_value";
 
35
 
 
36
    //_______________________________________________
 
37
    bool ProgressBarEngine::registerWidget( QWidget* widget )
 
38
    {
 
39
 
 
40
        // check enability
 
41
        if( !widget ) return false;
 
42
 
 
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 ) )
 
46
        {
 
47
            widget->setProperty( busyValuePropertyName, 0 );
 
48
            _dataSet.insert( widget );
 
49
        }
 
50
 
 
51
        // connect destruction signal
 
52
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
53
 
 
54
        return true;
 
55
 
 
56
    }
 
57
 
 
58
    //____________________________________________________________
 
59
    bool ProgressBarEngine::isAnimated( const QObject* object )
 
60
    {
 
61
 
 
62
        DataMap<ProgressBarData>::Value data( ProgressBarEngine::data( object ) );
 
63
        return ( data && data.data()->animation() && data.data()->animation().data()->isRunning() );
 
64
 
 
65
    }
 
66
 
 
67
    //____________________________________________________________
 
68
    void ProgressBarEngine::setBusyStepDuration( int value )
 
69
    {
 
70
        if( _busyStepDuration == value ) return;
 
71
        _busyStepDuration = value;
 
72
 
 
73
        // restart timer with specified time
 
74
        if( _timer.isActive() )
 
75
        {
 
76
            _timer.stop();
 
77
            _timer.start( busyStepDuration(), this );
 
78
        }
 
79
 
 
80
    }
 
81
 
 
82
    //_______________________________________________
 
83
    void ProgressBarEngine::timerEvent( QTimerEvent* event )
 
84
    {
 
85
 
 
86
        // check enability and timer
 
87
        if( !(busyIndicatorEnabled() && event->timerId() == _timer.timerId() ) )
 
88
        { return BaseEngine::timerEvent( event ); }
 
89
 
 
90
        bool animated( false );
 
91
 
 
92
        // loop over objects in map
 
93
        for( ProgressBarSet::iterator iter = _dataSet.begin(); iter != _dataSet.end(); ++iter )
 
94
        {
 
95
 
 
96
            // cast to progressbar
 
97
            QProgressBar* progressBar( qobject_cast<QProgressBar*>( *iter ) );
 
98
 
 
99
            // check cast, visibility and range
 
100
            if( progressBar && progressBar->isVisible() && progressBar->minimum() == 0 && progressBar->maximum() == 0  )
 
101
            {
 
102
 
 
103
                // update animation flag
 
104
                animated = true;
 
105
 
 
106
                // update value
 
107
                progressBar->setProperty( busyValuePropertyName, progressBar->property( busyValuePropertyName ).toInt()+1 );
 
108
                progressBar->update();
 
109
 
 
110
            } else if( *iter ) { (*iter)->setProperty( busyValuePropertyName, 0 ); }
 
111
 
 
112
        }
 
113
 
 
114
        if( !animated ) _timer.stop();
 
115
 
 
116
    }
 
117
 
 
118
    //____________________________________________________________
 
119
    DataMap<ProgressBarData>::Value ProgressBarEngine::data( const QObject* object )
 
120
    { return _data.find( object ).data(); }
 
121
 
 
122
}