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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygenspinboxdata.h

  • 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
#ifndef oxygenspinbox_datah
 
2
#define oxygenspinbox_datah
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygenspinboxdata.h
 
6
// spinbox data container for up/down arrow hover (mouse-over) animations
 
7
// -------------------
 
8
//
 
9
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
12
// of this software and associated documentation files (the "Software"), to
 
13
// deal in the Software without restriction, including without limitation the
 
14
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
15
// sell copies of the Software, and to permit persons to whom the Software is
 
16
// furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included in
 
19
// all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 
27
// IN THE SOFTWARE.
 
28
//////////////////////////////////////////////////////////////////////////////
 
29
 
 
30
#include "oxygenanimationdata.h"
 
31
 
 
32
#include <QtGui/QStyle>
 
33
 
 
34
namespace Oxygen
 
35
{
 
36
 
 
37
    //! handles spinbox arrows hover
 
38
    class SpinBoxData: public AnimationData
 
39
    {
 
40
 
 
41
        Q_OBJECT
 
42
 
 
43
        //! declare opacity property
 
44
        Q_PROPERTY( qreal upArrowOpacity READ upArrowOpacity WRITE setUpArrowOpacity )
 
45
        Q_PROPERTY( qreal downArrowOpacity READ downArrowOpacity WRITE setDownArrowOpacity )
 
46
 
 
47
        public:
 
48
 
 
49
        //! constructor
 
50
        SpinBoxData( QObject*, QWidget*, int );
 
51
 
 
52
        //! destructor
 
53
        virtual ~SpinBoxData( void )
 
54
        {}
 
55
 
 
56
        //! animation state
 
57
        virtual bool updateState( QStyle::SubControl subControl, bool value )
 
58
        {
 
59
            if( subControl == QStyle::SC_SpinBoxUp ) return _upArrowData.updateState( value );
 
60
            else if( subControl == QStyle::SC_SpinBoxDown ) return _downArrowData.updateState( value );
 
61
            else return false;
 
62
        }
 
63
 
 
64
        //! animation state
 
65
        virtual bool isAnimated( QStyle::SubControl subControl ) const
 
66
        {
 
67
            return(
 
68
                ( subControl == QStyle::SC_SpinBoxUp && upArrowAnimation().data()->isRunning() ) ||
 
69
                ( subControl == QStyle::SC_SpinBoxDown && downArrowAnimation().data()->isRunning() ) );
 
70
        }
 
71
 
 
72
        //! opacity
 
73
        virtual qreal opacity( QStyle::SubControl subControl ) const
 
74
        {
 
75
            if( subControl == QStyle::SC_SpinBoxUp ) return upArrowOpacity();
 
76
            else if( subControl == QStyle::SC_SpinBoxDown ) return downArrowOpacity();
 
77
            else return OpacityInvalid;
 
78
        }
 
79
 
 
80
        //! duration
 
81
        virtual void setDuration( int duration )
 
82
        {
 
83
            upArrowAnimation().data()->setDuration( duration );
 
84
            downArrowAnimation().data()->setDuration( duration );
 
85
        }
 
86
 
 
87
        //!@name up arrow animation
 
88
        //@{
 
89
 
 
90
        //! opacity
 
91
        qreal upArrowOpacity( void ) const
 
92
        { return _upArrowData._opacity; }
 
93
 
 
94
        //! opacity
 
95
        void setUpArrowOpacity( qreal value )
 
96
        {
 
97
            value = digitize( value );
 
98
            if( _upArrowData._opacity == value ) return;
 
99
            _upArrowData._opacity = value;
 
100
            setDirty();
 
101
        }
 
102
 
 
103
        //! animation
 
104
        Animation::Pointer upArrowAnimation( void ) const
 
105
        { return _upArrowData._animation; }
 
106
 
 
107
        //@}
 
108
 
 
109
        //!@name down arrow animation
 
110
        //@{
 
111
 
 
112
        //! opacity
 
113
        qreal downArrowOpacity( void ) const
 
114
        { return _downArrowData._opacity; }
 
115
 
 
116
        //! opacity
 
117
        void setDownArrowOpacity( qreal value )
 
118
        {
 
119
            value = digitize( value );
 
120
            if( _downArrowData._opacity == value ) return;
 
121
            _downArrowData._opacity = value;
 
122
            setDirty();
 
123
        }
 
124
 
 
125
        //! animation
 
126
        Animation::Pointer downArrowAnimation( void ) const
 
127
        { return _downArrowData._animation; }
 
128
 
 
129
        //@}
 
130
 
 
131
        private:
 
132
 
 
133
        //! container for needed animation data
 
134
        class Data
 
135
        {
 
136
 
 
137
            public:
 
138
 
 
139
            //! default constructor
 
140
            Data( void ):
 
141
                _state( false ),
 
142
                _opacity(0)
 
143
                {}
 
144
 
 
145
            //! state
 
146
            bool updateState( bool );
 
147
 
 
148
            //! arrow state
 
149
            bool _state;
 
150
 
 
151
            //! animation
 
152
            Animation::Pointer _animation;
 
153
 
 
154
            //! opacity
 
155
            qreal _opacity;
 
156
 
 
157
        };
 
158
 
 
159
        //! up arrow data
 
160
        Data _upArrowData;
 
161
 
 
162
        //! down arrow data
 
163
        Data _downArrowData;
 
164
 
 
165
    };
 
166
 
 
167
 
 
168
}
 
169
 
 
170
#endif