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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/transitions/oxygentransitions.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
// krazy:excludeall=qclasses
 
2
 
 
3
//////////////////////////////////////////////////////////////////////////////
 
4
// oxygentransitions.cpp
 
5
// container for all transition engines
 
6
// -------------------
 
7
//
 
8
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
9
//
 
10
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
11
// of this software and associated documentation files (the "Software"), to
 
12
// deal in the Software without restriction, including without limitation the
 
13
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
14
// sell copies of the Software, and to permit persons to whom the Software is
 
15
// furnished to do so, subject to the following conditions:
 
16
//
 
17
// The above copyright notice and this permission notice shall be included in
 
18
// all copies or substantial portions of the Software.
 
19
//
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
21
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
22
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
23
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
24
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
25
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
26
// IN THE SOFTWARE.
 
27
//////////////////////////////////////////////////////////////////////////////
 
28
 
 
29
#include "oxygentransitions.h"
 
30
#include "oxygentransitions.moc"
 
31
#include "oxygenpropertynames.h"
 
32
#include "oxygenstyleconfigdata.h"
 
33
 
 
34
namespace Oxygen
 
35
{
 
36
 
 
37
    //________________________________________________________--
 
38
    Transitions::Transitions( QObject* parent ):
 
39
        QObject( parent )
 
40
    {
 
41
 
 
42
        registerEngine( _comboBoxEngine = new ComboBoxEngine( this ) );
 
43
        registerEngine( _labelEngine = new LabelEngine( this ) );
 
44
        registerEngine( _lineEditEngine = new LineEditEngine( this ) );
 
45
        registerEngine( _stackedWidgetEngine = new StackedWidgetEngine( this ) );
 
46
 
 
47
    }
 
48
 
 
49
    //________________________________________________________--
 
50
    void Transitions::setupEngines( void )
 
51
    {
 
52
 
 
53
        // animation steps
 
54
        TransitionWidget::setSteps( StyleConfigData::animationSteps() );
 
55
 
 
56
        // default enability, duration and maxFrame
 
57
        bool animationsEnabled( StyleConfigData::animationsEnabled() );
 
58
 
 
59
        // enability
 
60
        comboBoxEngine().setEnabled( animationsEnabled && StyleConfigData::comboBoxTransitionsEnabled() );
 
61
        labelEngine().setEnabled( animationsEnabled && StyleConfigData::labelTransitionsEnabled() );
 
62
        lineEditEngine().setEnabled( animationsEnabled && StyleConfigData::lineEditTransitionsEnabled() );
 
63
        stackedWidgetEngine().setEnabled( animationsEnabled && StyleConfigData::stackedWidgetTransitionsEnabled() );
 
64
 
 
65
        // durations
 
66
        comboBoxEngine().setDuration( StyleConfigData::comboBoxTransitionsDuration() );
 
67
        labelEngine().setDuration( StyleConfigData::labelTransitionsDuration() );
 
68
        lineEditEngine().setDuration( StyleConfigData::lineEditTransitionsDuration() );
 
69
        stackedWidgetEngine().setDuration( StyleConfigData::stackedWidgetTransitionsDuration() );
 
70
 
 
71
    }
 
72
 
 
73
    //____________________________________________________________
 
74
    void Transitions::registerWidget( QWidget* widget ) const
 
75
    {
 
76
 
 
77
        if( !widget ) return;
 
78
 
 
79
        // check against noAnimations propery
 
80
        QVariant propertyValue( widget->property( PropertyNames::noAnimations ) );
 
81
        if( propertyValue.isValid() && propertyValue.toBool() ) return;
 
82
 
 
83
 
 
84
        if( QLabel* label = qobject_cast<QLabel*>( widget ) ) {
 
85
 
 
86
            // do not animate labels from tooltips
 
87
            if( widget->window() && widget->window()->windowFlags().testFlag( Qt::ToolTip ) ) return;
 
88
            else if( widget->window() && widget->window()->inherits( "KWin::GeometryTip" ) ) return;
 
89
            else labelEngine().registerWidget( label );
 
90
 
 
91
        } else if( QComboBox* comboBox = qobject_cast<QComboBox*>( widget ) ) {
 
92
 
 
93
            comboBoxEngine().registerWidget( comboBox );
 
94
 
 
95
        } else if( QLineEdit* lineEdit = qobject_cast<QLineEdit*>( widget ) ) {
 
96
 
 
97
            lineEditEngine().registerWidget( lineEdit );
 
98
 
 
99
        } else if( QStackedWidget* stack = qobject_cast<QStackedWidget*>( widget ) ) {
 
100
 
 
101
            stackedWidgetEngine().registerWidget( stack );
 
102
 
 
103
        }
 
104
 
 
105
    }
 
106
 
 
107
    //____________________________________________________________
 
108
    void Transitions::unregisterWidget( QWidget* widget ) const
 
109
    {
 
110
 
 
111
        if( !widget ) return;
 
112
 
 
113
        // the following allows some optimization of widget unregistration
 
114
        // it assumes that a widget can be registered atmost in one of the
 
115
        // engines stored in the list.
 
116
        foreach( const BaseEngine::Pointer& engine, _engines )
 
117
        { if( engine && engine.data()->unregisterWidget( widget ) ) break; }
 
118
 
 
119
    }
 
120
 
 
121
}