1
#ifndef oxygentransitionwidget_h
2
#define oxygentransitionwidget_h
3
//////////////////////////////////////////////////////////////////////////////
4
// oxygentransitionwidget.h
5
// stores event filters and maps widgets to transitions for transitions
8
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
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:
17
// The above copyright notice and this permission notice shall be included in
18
// all copies or substantial portions of the Software.
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
27
//////////////////////////////////////////////////////////////////////////////
29
#include "oxygenanimation.h"
31
#include <QtCore/QWeakPointer>
32
#include <QtGui/QWidget>
39
//! temporary widget used to perform smooth transition between one widget state and another
40
class TransitionWidget: public QWidget
45
//! declare opacity property
46
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
50
//! shortcut to painter
51
typedef QWeakPointer<TransitionWidget> Pointer;
54
TransitionWidget( QWidget* parent, int duration );
57
virtual ~TransitionWidget( void )
65
GrabFromWindow = 1<<0,
70
Q_DECLARE_FLAGS(Flags, Flag)
72
void setFlags( Flags value )
75
void setFlag( Flag flag, bool value = true )
77
if( value ) _flags |= flag;
78
else _flags &= (~flag);
81
bool testFlag( Flag flag ) const
82
{ return _flags.testFlag( flag ); }
87
void setDuration( int duration )
90
{ _animation.data()->setDuration( duration ); }
94
int duration( void ) const
95
{ return ( _animation ) ? _animation.data()->duration() : 0; }
98
static void setSteps( int value )
104
virtual qreal opacity( void ) const
107
virtual void setOpacity( qreal value )
109
value = digitize( value );
110
if( _opacity == value ) return;
117
//@name pixmaps handling
121
void resetStartPixmap( void )
122
{ setStartPixmap( QPixmap() ); }
125
void setStartPixmap( QPixmap pixmap )
126
{ _startPixmap = pixmap; }
129
const QPixmap& startPixmap( void ) const
130
{ return _startPixmap; }
133
void resetEndPixmap( void )
134
{ setEndPixmap( QPixmap() ); }
137
void setEndPixmap( QPixmap pixmap )
140
_currentPixmap = pixmap;
144
const QPixmap& endPixmap( void ) const
145
{ return _endPixmap; }
148
const QPixmap& currentPixmap( void ) const
149
{ return _currentPixmap; }
154
QPixmap grab( QWidget* = 0, QRect = QRect() );
157
virtual bool isAnimated( void ) const
158
{ return _animation.data()->isRunning(); }
161
virtual void endAnimation( void )
162
{ if( _animation.data()->isRunning() ) _animation.data()->stop(); }
164
//! animate transition
165
virtual void animate( void )
168
_animation.data()->start();
171
//! true if paint is enabled
172
static bool paintEnabled( void );
176
//! emmitted when animation is finished/aborder
177
void finished( void );
182
virtual void paintEvent( QPaintEvent* );
184
//! grab widget background
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>
190
virtual void grabBackground( QPixmap&, QWidget*, QRect& ) const;
193
virtual void grabWidget( QPixmap&, QWidget*, QRect& ) const;
196
virtual void fade( const QPixmap& source, QPixmap& target, qreal opacity, const QRect& ) const;
199
virtual qreal digitize( const qreal& value ) const
201
if( _steps > 0 ) return std::floor( value*_steps )/_steps;
211
static bool _paintEnabled;
213
//! internal transition animation
214
Animation::Pointer _animation;
216
//! animation starting pixmap
217
QPixmap _startPixmap;
219
//! animation starting pixmap
220
QPixmap _localStartPixmap;
222
//! animation starting pixmap
226
QPixmap _currentPixmap;
228
//! current state opacity