1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
4
* Copyright 2011, Michael Zanetti <mzanetti@kde.org>
6
* Tomahawk is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* Tomahawk is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20
#include "AnimationHelper.h"
24
AnimationHelper::AnimationHelper( const QModelIndex& index, QObject *parent )
27
, m_fullyExpanded( false )
28
, m_expandAnimation( 0 )
30
m_expandTimer.setSingleShot( true );
31
m_expandTimer.setInterval( 600 );
32
connect( &m_expandTimer, SIGNAL( timeout() ), SLOT(expandTimeout() ) );
34
m_collapseTimer.setSingleShot( true );
35
m_collapseTimer.setInterval( 600 );
36
connect( &m_collapseTimer, SIGNAL( timeout() ), SLOT(collapseTimeout() ) );
41
AnimationHelper::initialized() const
43
return m_expandAnimation != 0;
48
AnimationHelper::initialize( const QSize& startValue, const QSize& endValue, int duration )
51
m_targetSize = endValue;
52
m_startSize = startValue;
54
m_expandAnimation = new QPropertyAnimation( this, "size", this );
55
m_expandAnimation->setStartValue( startValue );
56
m_expandAnimation->setEndValue( endValue );
57
m_expandAnimation->setDuration( duration );
58
m_expandAnimation->setEasingCurve( QEasingCurve::OutExpo );
59
qDebug() << "starting animation" << startValue << endValue << duration;
60
connect( m_expandAnimation, SIGNAL( finished() ), SLOT( expandAnimationFinished() ) );
62
m_collapseAnimation= new QPropertyAnimation( this, "size", this );
63
m_collapseAnimation->setStartValue( endValue );
64
m_collapseAnimation->setEndValue( startValue );
65
m_collapseAnimation->setDuration( duration );
66
m_collapseAnimation->setEasingCurve( QEasingCurve::InExpo );
67
connect( m_collapseAnimation, SIGNAL( finished() ), SLOT( collapseAnimationFinished() ) );
73
AnimationHelper::setSize( const QSize& size )
77
//qDebug() << "animaton setting size to" << size;
82
AnimationHelper::expand()
84
m_collapseTimer.stop();
85
m_expandTimer.start();
90
AnimationHelper::collapse( bool immediately )
92
if ( m_expandTimer.isActive() )
95
emit finished( m_index );
101
m_fullyExpanded = false;
102
m_collapseAnimation->start();
105
m_collapseTimer.start();
110
AnimationHelper::partlyExpanded()
112
return m_size != m_startSize;
113
// return m_fullyExpanded
114
// || ( m_expandAnimation->state() == QPropertyAnimation::Running && m_expandAnimation->currentTime() > 250 )
115
// || ( m_collapseAnimation->state() == QPropertyAnimation::Running && m_collapseAnimation->currentTime() < 100 );
120
AnimationHelper::fullyExpanded()
122
return m_fullyExpanded;
127
AnimationHelper::expandTimeout()
129
m_expandAnimation->start();
134
AnimationHelper::collapseTimeout()
136
m_fullyExpanded = false;
137
m_collapseAnimation->start();
142
AnimationHelper::expandAnimationFinished()
144
m_fullyExpanded = true;
149
AnimationHelper::collapseAnimationFinished()
151
emit finished( m_index );
156
AnimationHelper::originalSize() const
163
AnimationHelper::size() const