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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenwidgetstateengine.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
//////////////////////////////////////////////////////////////////////////////
 
3
// oxygenwidgetstateengine.h
 
4
// stores event filters and maps widgets to timelines for animations
 
5
// -------------------
 
6
//
 
7
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to
 
11
// deal in the Software without restriction, including without limitation the
 
12
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
13
// sell copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
//
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
//
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
24
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
25
// IN THE SOFTWARE.
 
26
//////////////////////////////////////////////////////////////////////////////
 
27
 
 
28
#include "oxygenwidgetstateengine.h"
 
29
#include "oxygenwidgetstateengine.moc"
 
30
 
 
31
#include "oxygenenabledata.h"
 
32
 
 
33
namespace Oxygen
 
34
{
 
35
 
 
36
    //____________________________________________________________
 
37
    bool WidgetStateEngine::registerWidget( QWidget* widget, AnimationModes mode )
 
38
    {
 
39
 
 
40
        if( !widget ) return false;
 
41
        if( mode&AnimationHover && !_hoverData.contains( widget ) ) { _hoverData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
 
42
        if( mode&AnimationFocus && !_focusData.contains( widget ) ) { _focusData.insert( widget, new WidgetStateData( this, widget, duration() ), enabled() ); }
 
43
        if( mode&AnimationEnable && !_enableData.contains( widget ) ) { _enableData.insert( widget, new EnableData( this, widget, duration() ), enabled() ); }
 
44
 
 
45
        // connect destruction signal
 
46
        connect( widget, SIGNAL( destroyed( QObject* ) ), this, SLOT( unregisterWidget( QObject* ) ), Qt::UniqueConnection );
 
47
 
 
48
        return true;
 
49
 
 
50
    }
 
51
 
 
52
    //____________________________________________________________
 
53
    BaseEngine::WidgetList WidgetStateEngine::registeredWidgets( AnimationModes mode ) const
 
54
    {
 
55
 
 
56
        WidgetList out;
 
57
 
 
58
        // the typedef is needed to make Krazy happy
 
59
        typedef DataMap<WidgetStateData>::Value Value;
 
60
 
 
61
        if( mode&AnimationHover )
 
62
        {
 
63
            foreach( const Value& value, _hoverData )
 
64
            { if( value ) out.insert( value.data()->target().data() ); }
 
65
        }
 
66
 
 
67
        if( mode&AnimationFocus )
 
68
        {
 
69
            foreach( const Value& value, _focusData )
 
70
            { if( value ) out.insert( value.data()->target().data() ); }
 
71
        }
 
72
 
 
73
        if( mode&AnimationEnable )
 
74
        {
 
75
            foreach( const Value& value, _enableData )
 
76
            { if( value ) out.insert( value.data()->target().data() ); }
 
77
        }
 
78
 
 
79
        return out;
 
80
 
 
81
    }
 
82
 
 
83
    //____________________________________________________________
 
84
    bool WidgetStateEngine::updateState( const QObject* object, AnimationMode mode, bool value )
 
85
    {
 
86
        DataMap<WidgetStateData>::Value data( WidgetStateEngine::data( object, mode ) );
 
87
        return ( data && data.data()->updateState( value ) );
 
88
    }
 
89
 
 
90
    //____________________________________________________________
 
91
    bool WidgetStateEngine::isAnimated( const QObject* object, AnimationMode mode )
 
92
    {
 
93
 
 
94
        DataMap<WidgetStateData>::Value data( WidgetStateEngine::data( object, mode ) );
 
95
        return ( data && data.data()->animation() && data.data()->animation().data()->isRunning() );
 
96
 
 
97
    }
 
98
 
 
99
    //____________________________________________________________
 
100
    DataMap<WidgetStateData>::Value WidgetStateEngine::data( const QObject* object, AnimationMode mode )
 
101
    {
 
102
 
 
103
        switch( mode )
 
104
        {
 
105
            case AnimationHover: return _hoverData.find( object ).data();
 
106
            case AnimationFocus: return _focusData.find( object ).data();
 
107
            case AnimationEnable: return _enableData.find( object ).data();
 
108
            default: return DataMap<WidgetStateData>::Value();
 
109
        }
 
110
 
 
111
    }
 
112
 
 
113
}
 
114