~ubuntu-branches/ubuntu/trusty/tomahawk/trusty-proposed

« back to all changes in this revision

Viewing changes to src/sourcetree/AnimationHelper.cpp

  • Committer: Package Import Robot
  • Author(s): Harald Sitter
  • Date: 2013-03-07 21:50:13 UTC
  • Revision ID: package-import@ubuntu.com-20130307215013-6gdjkdds7i9uenvs
Tags: upstream-0.6.0+dfsg
ImportĀ upstreamĀ versionĀ 0.6.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 
2
 *
 
3
 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 
4
 *   Copyright 2011, Michael Zanetti <mzanetti@kde.org>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include "AnimationHelper.h"
 
21
 
 
22
#include <QDebug>
 
23
 
 
24
AnimationHelper::AnimationHelper( const QModelIndex& index, QObject *parent )
 
25
    :QObject( parent )
 
26
    , m_index( index )
 
27
    , m_fullyExpanded( false )
 
28
    , m_expandAnimation( 0 )
 
29
{
 
30
    m_expandTimer.setSingleShot( true );
 
31
    m_expandTimer.setInterval( 600 );
 
32
    connect( &m_expandTimer, SIGNAL( timeout() ), SLOT(expandTimeout() ) );
 
33
 
 
34
    m_collapseTimer.setSingleShot( true );
 
35
    m_collapseTimer.setInterval( 600 );
 
36
    connect( &m_collapseTimer, SIGNAL( timeout() ), SLOT(collapseTimeout() ) );
 
37
}
 
38
 
 
39
 
 
40
bool
 
41
AnimationHelper::initialized() const
 
42
{
 
43
    return m_expandAnimation != 0;
 
44
}
 
45
 
 
46
 
 
47
void
 
48
AnimationHelper::initialize( const QSize& startValue, const QSize& endValue, int duration )
 
49
{
 
50
    m_size = startValue;
 
51
    m_targetSize = endValue;
 
52
    m_startSize = startValue;
 
53
 
 
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() ) );
 
61
 
 
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() ) );
 
68
 
 
69
}
 
70
 
 
71
 
 
72
void
 
73
AnimationHelper::setSize( const QSize& size )
 
74
{
 
75
    m_size = size;
 
76
    emit sizeChanged();
 
77
    //qDebug() << "animaton setting size to" << size;
 
78
}
 
79
 
 
80
 
 
81
void
 
82
AnimationHelper::expand()
 
83
{
 
84
    m_collapseTimer.stop();
 
85
    m_expandTimer.start();
 
86
}
 
87
 
 
88
 
 
89
void
 
90
AnimationHelper::collapse( bool immediately )
 
91
{
 
92
    if ( m_expandTimer.isActive() )
 
93
    {
 
94
        m_expandTimer.stop();
 
95
        emit finished( m_index );
 
96
        return;
 
97
    }
 
98
 
 
99
    if ( immediately )
 
100
    {
 
101
        m_fullyExpanded = false;
 
102
        m_collapseAnimation->start();
 
103
    }
 
104
    else
 
105
        m_collapseTimer.start();
 
106
}
 
107
 
 
108
 
 
109
bool
 
110
AnimationHelper::partlyExpanded()
 
111
{
 
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 );
 
116
}
 
117
 
 
118
 
 
119
bool
 
120
AnimationHelper::fullyExpanded()
 
121
{
 
122
    return m_fullyExpanded;
 
123
}
 
124
 
 
125
 
 
126
void
 
127
AnimationHelper::expandTimeout()
 
128
{
 
129
    m_expandAnimation->start();
 
130
}
 
131
 
 
132
 
 
133
void
 
134
AnimationHelper::collapseTimeout()
 
135
{
 
136
    m_fullyExpanded = false;
 
137
    m_collapseAnimation->start();
 
138
}
 
139
 
 
140
 
 
141
void
 
142
AnimationHelper::expandAnimationFinished()
 
143
{
 
144
    m_fullyExpanded = true;
 
145
}
 
146
 
 
147
 
 
148
void
 
149
AnimationHelper::collapseAnimationFinished()
 
150
{
 
151
    emit finished( m_index );
 
152
}
 
153
 
 
154
 
 
155
QSize
 
156
AnimationHelper::originalSize() const
 
157
{
 
158
    return m_startSize;
 
159
}
 
160
 
 
161
 
 
162
QSize
 
163
AnimationHelper::size() const
 
164
{
 
165
    return m_size;
 
166
}