-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepped_animation.cpp
84 lines (71 loc) · 1.49 KB
/
stepped_animation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "stdafx.h"
#include <cmath>
#include "stepped_animation.h"
namespace fv
{
stepped_animation::stepped_animation(QObject* parent) :
QObject(parent),
animation_(this, "animation_value"),
running_(false),
value_(0.),
forward_(true)
{
animation_.setDuration(200);
animation_.setEasingCurve(QEasingCurve::Linear);
}
stepped_animation::~stepped_animation()
{
}
void stepped_animation::start(bool forward)
{
Q_ASSERT(!running_);
running_ = true;
forward_ = forward;
value_ = 0.;
animation_.setLoopCount(-1);
animation_.setStartValue(value_);
animation_.setEndValue(forward ? 1 : -1);
animation_.start();
}
void stepped_animation::stop()
{
running_ = false;
// Do not really stop here, wait until cycle finishes
}
void stepped_animation::interrupt()
{
running_ = false;
set_animation_value(0.);
animation_.stop();
}
bool stepped_animation::stopped() const
{
return animation_.state() == QAbstractAnimation::Stopped;
}
bool stepped_animation::forward() const
{
Q_ASSERT(!stopped());
return forward_;
}
qreal stepped_animation::animation_value() const
{
return value_;
}
void stepped_animation::set_animation_value(qreal value)
{
if (std::abs(value) < std::abs(value_))
{
// Next loop started
// We don't use currentLoopChanged animation's signal because it generates this signal only
// after first value of the next cycle already emitted
emit step(forward_);
if (!running_)
{
animation_.stop();
return;
}
}
value_ = value;
emit value_changed(value_);
}
}