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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/animations/oxygendockseparatordata.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 oxygendockseparator_datah
 
2
#define oxygendockseparator_datah
 
3
 
 
4
//////////////////////////////////////////////////////////////////////////////
 
5
// oxygendockseparatordata.h
 
6
// generic data container for widgetstate 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 "oxygengenericdata.h"
 
31
#include "oxygenanimation.h"
 
32
 
 
33
namespace Oxygen
 
34
{
 
35
 
 
36
    //! dock widget splitters hover effect
 
37
    class DockSeparatorData: public AnimationData
 
38
    {
 
39
 
 
40
        Q_OBJECT
 
41
 
 
42
        //! declare opacity property
 
43
        Q_PROPERTY( qreal verticalOpacity READ verticalOpacity WRITE setVerticalOpacity )
 
44
        Q_PROPERTY( qreal horizontalOpacity READ horizontalOpacity WRITE setHorizontalOpacity )
 
45
 
 
46
        public:
 
47
 
 
48
        //! constructor
 
49
        DockSeparatorData( QObject* parent, QWidget* target, int duration );
 
50
 
 
51
        //! destructor
 
52
        virtual ~DockSeparatorData( void )
 
53
        {}
 
54
 
 
55
        //@}
 
56
 
 
57
        /*!
 
58
        returns true if hover has Changed
 
59
        and starts timer accordingly
 
60
        */
 
61
        virtual void updateRect( const QRect&, const Qt::Orientation&, bool hovered );
 
62
 
 
63
        //! returns true if current splitter is animated
 
64
        virtual bool isAnimated( QRect r, const Qt::Orientation& orientation ) const
 
65
        { return orientation == Qt::Vertical ? _verticalData.isAnimated( r ):_horizontalData.isAnimated( r ); }
 
66
 
 
67
        //! opacity for given orientation
 
68
        qreal opacity( const Qt::Orientation& orientation ) const
 
69
        { return orientation == Qt::Vertical ? verticalOpacity():horizontalOpacity(); }
 
70
 
 
71
        //! duration
 
72
        virtual void setDuration( int duration )
 
73
        {
 
74
            horizontalAnimation().data()->setDuration( duration );
 
75
            verticalAnimation().data()->setDuration( duration );
 
76
        }
 
77
 
 
78
        //!@name horizontal splitter data
 
79
        //@{
 
80
 
 
81
        Animation::Pointer horizontalAnimation( void ) const
 
82
        { return _horizontalData._animation; }
 
83
 
 
84
        const QRect& horizontalRect( void ) const
 
85
        { return _horizontalData._rect; }
 
86
 
 
87
        void setHorizontalRect( const QRect& r )
 
88
        { _horizontalData._rect = r; }
 
89
 
 
90
        qreal horizontalOpacity( void ) const
 
91
        { return _horizontalData._opacity; }
 
92
 
 
93
        void setHorizontalOpacity( qreal value )
 
94
        {
 
95
 
 
96
            value = digitize( value );
 
97
            if( _horizontalData._opacity == value ) return;
 
98
            _horizontalData._opacity = value;
 
99
            if( target() && !horizontalRect().isEmpty() ) target().data()->update( horizontalRect() );
 
100
 
 
101
        }
 
102
 
 
103
        //@}
 
104
 
 
105
 
 
106
        //!@name vertical splitter data
 
107
        //@{
 
108
 
 
109
        Animation::Pointer verticalAnimation( void ) const
 
110
        { return _verticalData._animation; }
 
111
 
 
112
        const QRect& verticalRect( void ) const
 
113
        { return _verticalData._rect; }
 
114
 
 
115
        void setVerticalRect( const QRect& r )
 
116
        { _verticalData._rect = r; }
 
117
 
 
118
        qreal verticalOpacity( void ) const
 
119
        { return _verticalData._opacity; }
 
120
 
 
121
        void setVerticalOpacity( qreal value )
 
122
        {
 
123
            value = digitize( value );
 
124
            if( _verticalData._opacity == value ) return;
 
125
            _verticalData._opacity = value;
 
126
            if( target() && !verticalRect().isEmpty() ) target().data()->update( verticalRect() );
 
127
        }
 
128
 
 
129
        //@}
 
130
 
 
131
 
 
132
        private:
 
133
 
 
134
        //! stores data needed for animation
 
135
        class Data
 
136
        {
 
137
 
 
138
            public:
 
139
 
 
140
            //! constructor
 
141
            Data( void ):
 
142
                _opacity( AnimationData::OpacityInvalid )
 
143
                {}
 
144
 
 
145
            //! true if is animated
 
146
            bool isAnimated( QRect r ) const
 
147
            { return r == _rect && _animation.data()->isRunning(); }
 
148
 
 
149
            //! animation pointer
 
150
            Animation::Pointer _animation;
 
151
 
 
152
            //! opacity variable
 
153
            qreal _opacity;
 
154
 
 
155
            //! stores active separator rect
 
156
            QRect _rect;
 
157
 
 
158
        };
 
159
 
 
160
        //! horizontal
 
161
        Data _horizontalData;
 
162
 
 
163
        //! vertical
 
164
        Data _verticalData;
 
165
 
 
166
    };
 
167
 
 
168
}
 
169
 
 
170
#endif