Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
5
6#include <QtQuick/qquickitem.h>
7#include <QtQuick/qquickwindow.h>
8
9// based on qtdeclarative/examples/quick/scenegraph/threadedanimation
10
12
17
19{
20 return m_running;
21}
22
24{
25 int time = m_currentTime;
26 if (m_running)
27 time += m_timer.elapsed();
28 return time;
29}
30
32{
33 m_currentTime = time;
34 m_timer.restart();
35}
36
38{
39 return m_duration;
40}
41
43{
44 m_duration = duration;
45}
46
48{
49 return m_loopCount;
50}
51
53{
54 m_loopCount = count;
55}
56
61
63{
64 return m_window;
65}
66
67void QQuickAnimatedNode::start(int duration)
68{
69 if (m_running)
70 return;
71
72 m_running = true;
73 m_currentLoop = 0;
74 m_timer.restart();
75 if (duration > 0)
76 m_duration = duration;
77
78 connect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance, Qt::DirectConnection);
79 connect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update, Qt::DirectConnection);
80
81 // If we're inside a QQuickWidget, this call is necessary to ensure the widget
82 // gets updated for the first time.
83 m_window->update();
84
85 emit started();
86}
87
89{
90 stop();
91 start();
92}
93
95{
96 if (!m_running)
97 return;
98
99 m_running = false;
100 disconnect(m_window, &QQuickWindow::beforeRendering, this, &QQuickAnimatedNode::advance);
101 disconnect(m_window, &QQuickWindow::frameSwapped, this, &QQuickAnimatedNode::update);
102 emit stopped();
103}
104
109
110void QQuickAnimatedNode::advance()
111{
112 int time = currentTime();
113 if (time > m_duration) {
114 time = 0;
116
117 if (m_loopCount > 0 && ++m_currentLoop >= m_loopCount) {
118 time = m_duration; // complete
119 stop();
120 }
121 }
123
124 // If we're inside a QQuickWidget, this call is necessary to ensure the widget gets updated.
125 m_window->update();
126}
127
128void QQuickAnimatedNode::update()
129{
130 if (m_running)
131 m_window->update();
132}
133
135
136#include "moc_qquickanimatednode_p.cpp"
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
qint64 restart() noexcept
Restarts the timer and returns the number of milliseconds elapsed since the previous start.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QQuickWindow * window() const
void setLoopCount(int count)
QQuickAnimatedNode(QQuickItem *target)
void setCurrentTime(int time)
void setDuration(int duration)
virtual void updateCurrentTime(int time)
void start(int duration=0)
virtual void sync(QQuickItem *target)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
void frameSwapped()
This signal is emitted when a frame has been queued for presenting.
void update()
Schedules the window to render another frame.
void beforeRendering()
\qmlsignal QtQuick::Window::afterSynchronizing()
Combined button and popup list for selecting options.
@ DirectConnection
GLenum GLenum GLsizei count
GLenum target
GLuint start
#define emit
#define Q_UNUSED(x)
myObject disconnect()
[26]
aWidget window() -> setWindowTitle("New Window Title")
[2]