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

« back to all changes in this revision

Viewing changes to kstyles/oxygen/transitions/oxygentransitionwidget.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 oxygentransitionwidget_h
 
2
#define oxygentransitionwidget_h
 
3
//////////////////////////////////////////////////////////////////////////////
 
4
// oxygentransitionwidget.h
 
5
// stores event filters and maps widgets to transitions for transitions
 
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 "oxygenanimation.h"
 
30
 
 
31
#include <QtCore/QWeakPointer>
 
32
#include <QtGui/QWidget>
 
33
 
 
34
#include <cmath>
 
35
 
 
36
namespace Oxygen
 
37
{
 
38
 
 
39
    //! temporary widget used to perform smooth transition between one widget state and another
 
40
    class TransitionWidget: public QWidget
 
41
    {
 
42
 
 
43
        Q_OBJECT
 
44
 
 
45
        //! declare opacity property
 
46
        Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
 
47
 
 
48
        public:
 
49
 
 
50
        //! shortcut to painter
 
51
        typedef QWeakPointer<TransitionWidget> Pointer;
 
52
 
 
53
        //! constructor
 
54
        TransitionWidget( QWidget* parent, int duration );
 
55
 
 
56
        //! destructor
 
57
        virtual ~TransitionWidget( void )
 
58
        {}
 
59
 
 
60
        //!@name flags
 
61
        //@{
 
62
        enum Flag
 
63
        {
 
64
            None = 0,
 
65
            GrabFromWindow = 1<<0,
 
66
            Transparent = 1<<1,
 
67
            PaintOnWidget = 1<<2
 
68
        };
 
69
 
 
70
        Q_DECLARE_FLAGS(Flags, Flag)
 
71
 
 
72
        void setFlags( Flags value )
 
73
        { _flags = value; }
 
74
 
 
75
        void setFlag( Flag flag, bool value = true )
 
76
        {
 
77
            if( value ) _flags |= flag;
 
78
            else _flags &= (~flag);
 
79
        }
 
80
 
 
81
        bool testFlag( Flag flag ) const
 
82
        { return _flags.testFlag( flag ); }
 
83
 
 
84
        //@}
 
85
 
 
86
        //! duration
 
87
        void setDuration( int duration )
 
88
        {
 
89
            if( _animation )
 
90
            { _animation.data()->setDuration( duration ); }
 
91
        }
 
92
 
 
93
        //! duration
 
94
        int duration( void ) const
 
95
        { return ( _animation ) ? _animation.data()->duration() : 0; }
 
96
 
 
97
        //! steps
 
98
        static void setSteps( int value )
 
99
        { _steps = value; }
 
100
 
 
101
        //!@name opacity
 
102
        //@{
 
103
 
 
104
        virtual qreal opacity( void ) const
 
105
        { return _opacity; }
 
106
 
 
107
        virtual void setOpacity( qreal value )
 
108
        {
 
109
            value = digitize( value );
 
110
            if( _opacity == value ) return;
 
111
            _opacity = value;
 
112
            update();
 
113
        }
 
114
 
 
115
        //@}
 
116
 
 
117
        //@name pixmaps handling
 
118
        //@{
 
119
 
 
120
        //! start
 
121
        void resetStartPixmap( void )
 
122
        { setStartPixmap( QPixmap() ); }
 
123
 
 
124
        //! start
 
125
        void setStartPixmap( QPixmap pixmap )
 
126
        { _startPixmap = pixmap; }
 
127
 
 
128
        //! start
 
129
        const QPixmap& startPixmap( void ) const
 
130
        { return _startPixmap; }
 
131
 
 
132
        //! end
 
133
        void resetEndPixmap( void )
 
134
        { setEndPixmap( QPixmap() ); }
 
135
 
 
136
        //! end
 
137
        void setEndPixmap( QPixmap pixmap )
 
138
        {
 
139
            _endPixmap = pixmap;
 
140
            _currentPixmap = pixmap;
 
141
        }
 
142
 
 
143
        //! start
 
144
        const QPixmap& endPixmap( void ) const
 
145
        { return _endPixmap; }
 
146
 
 
147
        //! current
 
148
        const QPixmap& currentPixmap( void ) const
 
149
        { return _currentPixmap; }
 
150
 
 
151
        //@}
 
152
 
 
153
        //! grap pixmap
 
154
        QPixmap grab( QWidget* = 0, QRect = QRect() );
 
155
 
 
156
        //! true if animated
 
157
        virtual bool isAnimated( void ) const
 
158
        { return _animation.data()->isRunning(); }
 
159
 
 
160
        //! end animation
 
161
        virtual void endAnimation( void )
 
162
        { if( _animation.data()->isRunning() ) _animation.data()->stop(); }
 
163
 
 
164
        //! animate transition
 
165
        virtual void animate( void )
 
166
        {
 
167
            endAnimation();
 
168
            _animation.data()->start();
 
169
        }
 
170
 
 
171
        //! true if paint is enabled
 
172
        static bool paintEnabled( void );
 
173
 
 
174
        signals:
 
175
 
 
176
        //! emmitted when animation is finished/aborder
 
177
        void finished( void );
 
178
 
 
179
        protected:
 
180
 
 
181
        //! paint event
 
182
        virtual void paintEvent( QPaintEvent* );
 
183
 
 
184
        //! grab widget background
 
185
        /*!
 
186
        Background is not rendered properly using QWidget::render.
 
187
        Use home-made grabber instead. This is directly inspired from bespin.
 
188
        Copyright (C) 2007 Thomas Luebking <thomas.luebking@web.de>
 
189
        */
 
190
        virtual void grabBackground( QPixmap&, QWidget*, QRect& ) const;
 
191
 
 
192
        //! grab widget
 
193
        virtual void grabWidget( QPixmap&, QWidget*, QRect& ) const;
 
194
 
 
195
        //! fade pixmap
 
196
        virtual void fade( const QPixmap& source, QPixmap& target, qreal opacity, const QRect& ) const;
 
197
 
 
198
        //! apply step
 
199
        virtual qreal digitize( const qreal& value ) const
 
200
        {
 
201
            if( _steps > 0 ) return std::floor( value*_steps )/_steps;
 
202
            else return value;
 
203
        }
 
204
 
 
205
        private:
 
206
 
 
207
        //! Flags
 
208
        Flags _flags;
 
209
 
 
210
        //! paint enabled
 
211
        static bool _paintEnabled;
 
212
 
 
213
        //! internal transition animation
 
214
        Animation::Pointer _animation;
 
215
 
 
216
        //! animation starting pixmap
 
217
        QPixmap _startPixmap;
 
218
 
 
219
        //! animation starting pixmap
 
220
        QPixmap _localStartPixmap;
 
221
 
 
222
        //! animation starting pixmap
 
223
        QPixmap _endPixmap;
 
224
 
 
225
        //! current pixmap
 
226
        QPixmap _currentPixmap;
 
227
 
 
228
        //! current state opacity
 
229
        qreal _opacity;
 
230
 
 
231
        //! steps
 
232
        static int _steps;
 
233
 
 
234
    };
 
235
 
 
236
}
 
237
 
 
238
#endif