Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qquickanimatednode.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qquickanimatednode_p.h"
6
7
#
include
<
QtQuick
/
qquickitem
.
h
>
8
#
include
<
QtQuick
/
qquickwindow
.
h
>
9
10
// based on qtdeclarative/examples/quick/scenegraph/threadedanimation
11
12
QT_BEGIN_NAMESPACE
13
14
QQuickAnimatedNode::QQuickAnimatedNode(QQuickItem *target)
15
: m_window(target->window())
16
{
17
}
18
19
bool
QQuickAnimatedNode::isRunning()
const
20
{
21
return
m_running;
22
}
23
24
int
QQuickAnimatedNode::currentTime()
const
25
{
26
int
time = m_currentTime;
27
if
(m_running)
28
time += m_timer.elapsed();
29
return
time;
30
}
31
32
void
QQuickAnimatedNode::setCurrentTime(
int
time)
33
{
34
m_currentTime = time;
35
m_timer.start();
36
}
37
38
int
QQuickAnimatedNode::duration()
const
39
{
40
return
m_duration;
41
}
42
43
void
QQuickAnimatedNode::setDuration(
int
duration)
44
{
45
m_duration = duration;
46
}
47
48
int
QQuickAnimatedNode::loopCount()
const
49
{
50
return
m_loopCount;
51
}
52
53
void
QQuickAnimatedNode::setLoopCount(
int
count)
54
{
55
m_loopCount = count;
56
}
57
58
void
QQuickAnimatedNode::sync(QQuickItem *target)
59
{
60
Q_UNUSED(target);
61
}
62
63
QQuickWindow *QQuickAnimatedNode::window()
const
64
{
65
return
m_window;
66
}
67
68
void
QQuickAnimatedNode::start(
int
duration)
69
{
70
if
(m_running)
71
return
;
72
73
m_running =
true
;
74
m_currentLoop = 0;
75
m_timer.start();
76
if
(duration > 0)
77
m_duration = duration;
78
79
connect(m_window, &QQuickWindow::beforeRendering,
this
, &QQuickAnimatedNode::advance, Qt::DirectConnection);
80
connect(m_window, &QQuickWindow::frameSwapped,
this
, &QQuickAnimatedNode::update, Qt::DirectConnection);
81
82
// If we're inside a QQuickWidget, this call is necessary to ensure the widget
83
// gets updated for the first time.
84
m_window->update();
85
86
emit started();
87
}
88
89
void
QQuickAnimatedNode::restart()
90
{
91
stop();
92
start();
93
}
94
95
void
QQuickAnimatedNode::stop()
96
{
97
if
(!m_running)
98
return
;
99
100
m_running =
false
;
101
disconnect(m_window, &QQuickWindow::beforeRendering,
this
, &QQuickAnimatedNode::advance);
102
disconnect(m_window, &QQuickWindow::frameSwapped,
this
, &QQuickAnimatedNode::update);
103
emit stopped();
104
}
105
106
void
QQuickAnimatedNode::updateCurrentTime(
int
time)
107
{
108
Q_UNUSED(time);
109
}
110
111
void
QQuickAnimatedNode::advance()
112
{
113
int
time = currentTime();
114
if
(time > m_duration) {
115
time = 0;
116
setCurrentTime(0);
117
118
if
(m_loopCount > 0 && ++m_currentLoop >= m_loopCount) {
119
time = m_duration;
// complete
120
stop();
121
}
122
}
123
updateCurrentTime(time);
124
125
// If we're inside a QQuickWidget, this call is necessary to ensure the widget gets updated.
126
m_window->update();
127
}
128
129
void
QQuickAnimatedNode::update()
130
{
131
if
(m_running)
132
m_window->update();
133
}
134
135
QT_END_NAMESPACE
136
137
#
include
"moc_qquickanimatednode_p.cpp"
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
quickcontrolsimpl
qquickanimatednode.cpp
Generated on
for Qt by
1.18.0