2009-12-18 15:20:04 +00:00
|
|
|
#ifndef oxygentitleanimationdata_h
|
|
|
|
#define oxygentitleanimationdata_h
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// oxygentitleanimationdata.h
|
2010-05-22 05:40:39 +00:00
|
|
|
// handles transition when window title is changed
|
2009-12-18 15:20:04 +00:00
|
|
|
// -------------------
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to
|
|
|
|
// deal in the Software without restriction, including without limitation the
|
|
|
|
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
// sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
// IN THE SOFTWARE.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-03-02 03:40:34 +00:00
|
|
|
#include "oxygenanimation.h"
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2013-02-26 08:00:51 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QWeakPointer>
|
|
|
|
#include <QBasicTimer>
|
|
|
|
#include <QTimerEvent>
|
2009-12-18 15:20:04 +00:00
|
|
|
#include <QtGui/QPixmap>
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
namespace Oxygen
|
|
|
|
{
|
|
|
|
|
|
|
|
class TitleAnimationData: public QObject
|
|
|
|
{
|
|
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
//! declare title opacity
|
|
|
|
Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity )
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-01-04 17:00:21 +00:00
|
|
|
typedef QWeakPointer<TitleAnimationData> Pointer;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! constructor
|
2012-12-29 06:34:38 +00:00
|
|
|
explicit TitleAnimationData( QObject* );
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! reset
|
|
|
|
void reset( void )
|
|
|
|
{
|
|
|
|
setOpacity(0);
|
2011-02-24 16:37:04 +00:00
|
|
|
_contrastPixmap.reset();
|
|
|
|
_pixmap.reset();
|
2009-12-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! initialize
|
|
|
|
void initialize( void );
|
|
|
|
|
|
|
|
// reset
|
|
|
|
void reset( QRect rect, QPixmap pixmap, QPixmap contrast )
|
|
|
|
{
|
|
|
|
setOpacity(0);
|
2011-02-24 16:37:04 +00:00
|
|
|
_contrastPixmap.reset( rect, contrast );
|
|
|
|
_pixmap.reset( rect, pixmap );
|
2009-12-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! set pixmaps
|
|
|
|
void setPixmaps( QRect, QPixmap pixmap, QPixmap contrast );
|
|
|
|
|
|
|
|
//! duration
|
|
|
|
void setDuration( int duration )
|
|
|
|
{
|
|
|
|
assert( animation() );
|
|
|
|
animation().data()->setDuration( duration );
|
|
|
|
}
|
|
|
|
|
|
|
|
//! retrieve contrast pixmap
|
|
|
|
QPixmap contrastPixmap( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _contrastPixmap.currentPixmap(); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! pixmap
|
|
|
|
QPixmap pixmap( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _pixmap.currentPixmap(); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//!@name animation
|
|
|
|
//@{
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! returns true if animations are locked
|
|
|
|
bool isLocked( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _animationLockTimer.isActive(); }
|
2010-02-12 00:42:25 +00:00
|
|
|
|
|
|
|
//! returns true if title transition animation is currently running
|
2009-12-18 15:20:04 +00:00
|
|
|
bool isAnimated( void ) const
|
|
|
|
{ return animation().data()->isRunning(); }
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! start lock animation timer
|
|
|
|
void lockAnimations( void )
|
2011-02-24 16:37:04 +00:00
|
|
|
{ _animationLockTimer.start( _lockTime, this ); }
|
2010-02-12 00:42:25 +00:00
|
|
|
|
2010-06-04 16:59:09 +00:00
|
|
|
//! start lock animation timer
|
|
|
|
void unlockAnimations( void )
|
2011-02-24 16:37:04 +00:00
|
|
|
{ _animationLockTimer.stop(); }
|
2010-06-04 16:59:09 +00:00
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! start title transition animation
|
2009-12-18 15:20:04 +00:00
|
|
|
void startAnimation( void )
|
|
|
|
{
|
|
|
|
assert( !isAnimated() );
|
|
|
|
animation().data()->start();
|
|
|
|
}
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! finish title transition animation
|
|
|
|
void finishAnimation( void )
|
|
|
|
{
|
|
|
|
assert( isAnimated() );
|
|
|
|
animation().data()->stop();
|
|
|
|
}
|
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//!@name opacity
|
|
|
|
//@{
|
|
|
|
|
|
|
|
qreal opacity( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _opacity; }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
void setOpacity( qreal value )
|
2010-08-28 02:52:26 +00:00
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
if( _opacity == value ) return;
|
|
|
|
_opacity = value;
|
2010-08-28 02:52:26 +00:00
|
|
|
updatePixmaps();
|
|
|
|
}
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//@}
|
|
|
|
|
|
|
|
//! validity
|
|
|
|
bool isValid( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _pixmap.isValid(); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! dirty flag
|
|
|
|
void setDirty( bool value )
|
2011-02-24 16:37:04 +00:00
|
|
|
{ _dirty = value; }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! dirty flag
|
|
|
|
bool isDirty( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _dirty; }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2013-07-30 04:47:50 +00:00
|
|
|
Q_SIGNALS:
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2010-01-17 08:07:13 +00:00
|
|
|
void pixmapsChanged( void );
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2010-08-28 02:52:26 +00:00
|
|
|
protected:
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! update pixmaps
|
|
|
|
virtual void updatePixmaps( void );
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! timer event
|
|
|
|
void timerEvent( QTimerEvent* );
|
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
//! animation object
|
|
|
|
const Animation::Pointer& animation( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _animation; }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
//! used to blend pixmap
|
|
|
|
class BlendedPixmap
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// reset everything
|
|
|
|
void reset( void )
|
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
_startRect = _endRect = QRect();
|
|
|
|
_startPixmap = _endPixmap = _currentPixmap = QPixmap();
|
2009-12-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! reset
|
|
|
|
void reset( const QRect& rect, QPixmap pixmap )
|
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
_startRect = _endRect = rect;
|
|
|
|
_startPixmap = _endPixmap = _currentPixmap = pixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// update pixmaps
|
|
|
|
void initialize( const QRect& rect, QPixmap pixmap )
|
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
_startRect = _endRect;
|
|
|
|
_endRect = rect;
|
|
|
|
_startPixmap = _currentPixmap;
|
|
|
|
_endPixmap = pixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! update currentPixmap by blending start and end pixmap
|
|
|
|
void blend( qreal opacity );
|
|
|
|
|
|
|
|
//! current pixmap
|
|
|
|
QPixmap currentPixmap( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return _currentPixmap; }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! validity
|
|
|
|
bool isValid( void ) const
|
2011-02-24 16:37:04 +00:00
|
|
|
{ return !(_endRect.isNull() || _endPixmap.isNull() ); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// fade pixmap by some amount
|
|
|
|
QPixmap fade( QPixmap, qreal ) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
//! animation starting pixmap
|
2011-02-24 16:37:04 +00:00
|
|
|
QPixmap _startPixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! animation ending pixmap
|
2011-02-24 16:37:04 +00:00
|
|
|
QPixmap _endPixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! animation current pixmap
|
2011-02-24 16:37:04 +00:00
|
|
|
QPixmap _currentPixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
QRect _startRect;
|
|
|
|
QRect _endRect;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
bool _dirty;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
BlendedPixmap _contrastPixmap;
|
|
|
|
BlendedPixmap _pixmap;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//! lock time (milliseconds
|
2011-02-24 16:37:04 +00:00
|
|
|
static const int _lockTime;
|
2010-02-12 00:42:25 +00:00
|
|
|
|
|
|
|
//! timer used to disable animations when triggered too early
|
2011-02-24 16:37:04 +00:00
|
|
|
QBasicTimer _animationLockTimer;
|
2010-02-12 00:42:25 +00:00
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
//! title animation
|
2011-02-24 16:37:04 +00:00
|
|
|
Animation::Pointer _animation;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
//! title opacity
|
2011-02-24 16:37:04 +00:00
|
|
|
qreal _opacity;
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|