1
//////////////////////////////////////////////////////////////////////////////
2
// oxygentitleanimationdata.h
3
// handles transition when window title is changed
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
7
// Copyright (c) 2015 David Edmundson <davidedmundson@kde.org>
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to
11
// deal in the Software without restriction, including without limitation the
12
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13
// sell copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26
//////////////////////////////////////////////////////////////////////////////
28
#include "oxygentitleanimationdata.h"
29
#include "oxygentitleanimationdata.moc"
36
// use 300 milliseconds for animation lock
37
const int TitleAnimationData::_lockTime = 300;
39
//_________________________________________________________
40
TitleAnimationData::TitleAnimationData( QObject* parent ):
43
_animation( new Animation( 200, this ) ),
47
//_________________________________________________________
48
void TitleAnimationData::initialize( void )
51
// setup title animation
52
animation().data()->setStartValue( 0 );
53
animation().data()->setEndValue( 1 );
54
animation().data()->setTargetObject( this );
55
animation().data()->setPropertyName( "opacity" );
56
animation().data()->setEasingCurve( QEasingCurve::InOutQuad );
61
//_________________________________________________________
62
void TitleAnimationData::setPixmaps( QRect rect, QPixmap pixmap, QPixmap contrast )
66
if( isAnimated() ) animation().data()->stop();
69
_contrastPixmap.initialize( rect, contrast );
70
_pixmap.initialize( rect, pixmap );
77
//_________________________________________________________
78
void TitleAnimationData::updatePixmaps( void )
80
_contrastPixmap.blend( opacity() );
81
_pixmap.blend( opacity() );
82
emit pixmapsChanged();
85
//_________________________________________________________
86
void TitleAnimationData::timerEvent( QTimerEvent* e )
89
if( e->timerId() != _animationLockTimer.timerId() )
90
{ return QObject::timerEvent( e ); }
97
// triggers pixmap updates
99
emit pixmapsChanged();
104
//_________________________________________________________
105
void TitleAnimationData::BlendedPixmap::blend( qreal opacity )
108
_currentPixmap = QPixmap( _endRect.size() );
109
_currentPixmap.fill( Qt::transparent );
111
QPainter painter( &_currentPixmap );
112
if( opacity < 1 && !_startPixmap.isNull() )
113
{ painter.drawPixmap( _startRect.topLeft() - _endRect.topLeft(), fade( _startPixmap, 1.0 - opacity ) ); }
115
if( opacity > 0 && !_endPixmap.isNull() )
116
{ painter.drawPixmap( QPoint(0,0), fade( _endPixmap, opacity ) ); }
123
//_________________________________________________________
124
QPixmap TitleAnimationData::BlendedPixmap::fade( QPixmap source, qreal opacity ) const
127
if( source.isNull() ) return QPixmap();
129
QPixmap out( source.size() );
130
out.fill( Qt::transparent );
132
// do nothing if opacity is too small
133
if( opacity*255 < 1 ) return out;
137
p.drawPixmap( QPoint(0,0), source );
140
if( opacity*255 <= 254 )
142
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
143
QColor color( Qt::black );
144
color.setAlphaF( opacity );
145
p.fillRect(out.rect(), color );