-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimatedwidget.cpp
74 lines (62 loc) · 1.83 KB
/
animatedwidget.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
#include "animatedwidget.h"
AnimatedWidget::AnimatedWidget(int x, int y, Background *parent) : RegularMove(x, y, parent)
{
machine = new QStateMachine(this);
first_state = nullptr;
}
void AnimatedWidget::add_animation(int start, int end, int loop, int duration, QString pattern, int fillwidth)
{
add_animation(new QState(machine), start, end, loop, duration, pattern, fillwidth);
}
void AnimatedWidget::add_animation(QState* state, int start, int end, int loop, int duration, QString pattern, int fillwidth)
{
if (!first_state)
{
first_state = state;
}
connect(state, SIGNAL(entered()), &animation, SLOT(stop()));
connect(state, SIGNAL(entered()), &animation, SLOT(start()));
state->assignProperty(&animation, "startValue", start);
state->assignProperty(&animation, "endValue", end+1);
state->assignProperty(&animation, "loopCount", loop);
state->assignProperty(&animation, "duration", duration);
state->assignProperty(this, "basename", pattern);
state->assignProperty(this, "fillwidth", fillwidth);
}
void AnimatedWidget::start_animation(QState *initial)
{
if (!initial)
{
initial = first_state;
}
animation.setPropertyName("frame");
animation.setTargetObject(this);
machine->setInitialState(initial);
machine->start();
animation.start();
}
int AnimatedWidget::frame()
{
return m_frame;
}
void AnimatedWidget::setFrame(int frame)
{
m_frame = frame;
set_background_image(m_basename.arg(m_frame, m_fillwidth, 10, QChar('0')).toStdString());
}
QString AnimatedWidget::basename() const
{
return m_basename;
}
void AnimatedWidget::setBasename(QString basename)
{
this->m_basename = basename;
}
int AnimatedWidget::fillwidth() const
{
return m_fillwidth;
}
void AnimatedWidget::setFillwidth(int fillwidth)
{
m_fillwidth = fillwidth;
}