2009-12-18 15:20:04 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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.
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "oxygentitleanimationdata.h"
|
|
|
|
#include "oxygentitleanimationdata.moc"
|
|
|
|
|
2013-08-02 07:39:09 +00:00
|
|
|
#include <QPainter>
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
namespace Oxygen
|
|
|
|
{
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
// use 300 milliseconds for animation lock
|
2011-02-24 16:37:04 +00:00
|
|
|
const int TitleAnimationData::_lockTime = 300;
|
2010-02-12 00:42:25 +00:00
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
TitleAnimationData::TitleAnimationData( QObject* parent ):
|
|
|
|
QObject( parent ),
|
2011-02-24 16:37:04 +00:00
|
|
|
_dirty( false ),
|
|
|
|
_animation( new Animation( 200, this ) ),
|
|
|
|
_opacity(0)
|
2009-12-18 15:20:04 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
void TitleAnimationData::initialize( void )
|
|
|
|
{
|
|
|
|
|
|
|
|
// setup title animation
|
|
|
|
animation().data()->setStartValue( 0 );
|
|
|
|
animation().data()->setEndValue( 1 );
|
|
|
|
animation().data()->setTargetObject( this );
|
|
|
|
animation().data()->setPropertyName( "opacity" );
|
2010-01-04 16:42:46 +00:00
|
|
|
animation().data()->setEasingCurve( QEasingCurve::InOutQuad );
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
void TitleAnimationData::setPixmaps( QRect rect, QPixmap pixmap, QPixmap contrast )
|
|
|
|
{
|
|
|
|
|
|
|
|
// stop animation
|
|
|
|
if( isAnimated() ) animation().data()->stop();
|
|
|
|
|
|
|
|
// update pixmaps
|
2011-02-24 16:37:04 +00:00
|
|
|
_contrastPixmap.initialize( rect, contrast );
|
|
|
|
_pixmap.initialize( rect, pixmap );
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
setOpacity(0);
|
|
|
|
updatePixmaps();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
void TitleAnimationData::updatePixmaps( void )
|
|
|
|
{
|
2011-02-24 16:37:04 +00:00
|
|
|
_contrastPixmap.blend( opacity() );
|
|
|
|
_pixmap.blend( opacity() );
|
2009-12-18 15:20:04 +00:00
|
|
|
emit pixmapsChanged();
|
|
|
|
}
|
|
|
|
|
2010-02-12 00:42:25 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
void TitleAnimationData::timerEvent( QTimerEvent* e )
|
|
|
|
{
|
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
if( e->timerId() != _animationLockTimer.timerId() )
|
2010-02-12 00:42:25 +00:00
|
|
|
{ return QObject::timerEvent( e ); }
|
|
|
|
|
2010-06-04 16:59:09 +00:00
|
|
|
// unlock
|
|
|
|
unlockAnimations();
|
2010-02-12 00:42:25 +00:00
|
|
|
|
|
|
|
if( !isAnimated() )
|
|
|
|
{
|
|
|
|
// triggers pixmap updates
|
|
|
|
reset();
|
|
|
|
emit pixmapsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-18 15:20:04 +00:00
|
|
|
//_________________________________________________________
|
|
|
|
void TitleAnimationData::BlendedPixmap::blend( qreal opacity )
|
|
|
|
{
|
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
_currentPixmap = QPixmap( _endRect.size() );
|
|
|
|
_currentPixmap.fill( Qt::transparent );
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
QPainter painter( &_currentPixmap );
|
|
|
|
if( opacity < 1 && !_startPixmap.isNull() )
|
|
|
|
{ painter.drawPixmap( _startRect.topLeft() - _endRect.topLeft(), fade( _startPixmap, 1.0 - opacity ) ); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
2011-02-24 16:37:04 +00:00
|
|
|
if( opacity > 0 && !_endPixmap.isNull() )
|
|
|
|
{ painter.drawPixmap( QPoint(0,0), fade( _endPixmap, opacity ) ); }
|
2009-12-18 15:20:04 +00:00
|
|
|
|
|
|
|
painter.end();
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//_________________________________________________________
|
|
|
|
QPixmap TitleAnimationData::BlendedPixmap::fade( QPixmap source, qreal opacity ) const
|
|
|
|
{
|
|
|
|
|
|
|
|
if( source.isNull() ) return QPixmap();
|
|
|
|
|
|
|
|
QPixmap out( source.size() );
|
|
|
|
out.fill( Qt::transparent );
|
|
|
|
|
|
|
|
// do nothing if opacity is too small
|
|
|
|
if( opacity*255 < 1 ) return out;
|
|
|
|
|
|
|
|
// draw pixmap
|
|
|
|
QPainter p( &out );
|
|
|
|
p.drawPixmap( QPoint(0,0), source );
|
|
|
|
|
|
|
|
// opacity mask
|
|
|
|
if( opacity*255 <= 254 )
|
|
|
|
{
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
QColor color( Qt::black );
|
|
|
|
color.setAlphaF( opacity );
|
|
|
|
p.fillRect(out.rect(), color );
|
|
|
|
}
|
|
|
|
|
|
|
|
p.end();
|
|
|
|
return out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|