2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2013-09-30 05:28:31 +00:00
|
|
|
** This file is part of the QtQuick module of the Qt Toolkit.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-20 05:21:40 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 09:38:36 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-20 05:21:40 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-19 09:38:36 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include "qquickanimation_p.h"
|
|
|
|
#include "qquickanimation_p_p.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
#include "qquickanimatorjob_p.h"
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <private/qquickstatechangescript_p.h>
|
|
|
|
#include <private/qqmlcontext_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
#include <qqmlpropertyvaluesource.h>
|
|
|
|
#include <qqml.h>
|
|
|
|
#include <qqmlinfo.h>
|
|
|
|
#include <qqmlexpression.h>
|
|
|
|
#include <private/qqmlstringconverters_p.h>
|
|
|
|
#include <private/qqmlglobal_p.h>
|
|
|
|
#include <private/qqmlmetatype_p.h>
|
|
|
|
#include <private/qqmlvaluetype_p.h>
|
|
|
|
#include <private/qqmlproperty_p.h>
|
|
|
|
#include <private/qqmlengine_p.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include <qvariant.h>
|
|
|
|
#include <qcolor.h>
|
|
|
|
#include <qfile.h>
|
2012-02-03 02:26:37 +00:00
|
|
|
#include "private/qparallelanimationgroupjob_p.h"
|
|
|
|
#include "private/qsequentialanimationgroupjob_p.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtCore/qset.h>
|
|
|
|
#include <QtCore/qrect.h>
|
|
|
|
#include <QtCore/qpoint.h>
|
|
|
|
#include <QtCore/qsize.h>
|
|
|
|
#include <QtCore/qmath.h>
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype Animation
|
|
|
|
\instantiates QQuickAbstractAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Is the base of all QML animations.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
The Animation type cannot be used directly in a QML file. It exists
|
2011-04-27 10:05:43 +00:00
|
|
|
to provide a set of common properties and methods, available across all the
|
|
|
|
other animation types that inherit from it. Attempting to use the Animation
|
2012-07-11 06:29:42 +00:00
|
|
|
type directly will result in an error.
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAbstractAnimation::QQuickAbstractAnimation(QObject *parent)
|
|
|
|
: QObject(*(new QQuickAbstractAnimationPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAbstractAnimation::~QQuickAbstractAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-05-29 01:15:11 +00:00
|
|
|
if (d->group)
|
2018-02-21 09:41:54 +00:00
|
|
|
setGroup(nullptr); //remove from group
|
2012-02-03 02:26:37 +00:00
|
|
|
delete d->animationInstance;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAbstractAnimation::QQuickAbstractAnimation(QQuickAbstractAnimationPrivate &dd, QObject *parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
: QObject(dd, parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickAbstractAnimation::qtAnimation()
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->animationInstance;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty bool QtQuick::Animation::running
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds whether the animation is currently running.
|
|
|
|
|
|
|
|
The \c running property can be set to declaratively control whether or not
|
|
|
|
an animation is running. The following example will animate a rectangle
|
|
|
|
whenever the \l MouseArea is pressed.
|
|
|
|
|
|
|
|
\code
|
|
|
|
Rectangle {
|
|
|
|
width: 100; height: 100
|
|
|
|
NumberAnimation on x {
|
|
|
|
running: myMouse.pressed
|
|
|
|
from: 0; to: 100
|
|
|
|
}
|
|
|
|
MouseArea { id: myMouse }
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
Likewise, the \c running property can be read to determine if the animation
|
2012-07-11 06:29:42 +00:00
|
|
|
is running. In the following example the Text item will indicate whether
|
2011-04-27 10:05:43 +00:00
|
|
|
or not the animation is running.
|
|
|
|
|
|
|
|
\code
|
|
|
|
NumberAnimation { id: myAnimation }
|
|
|
|
Text { text: myAnimation.running ? "Animation is running" : "Animation is not running" }
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
Animations can also be started and stopped imperatively from JavaScript
|
|
|
|
using the \c start() and \c stop() methods.
|
|
|
|
|
|
|
|
By default, animations are not running. Though, when the animations are assigned to properties,
|
|
|
|
as property value sources using the \e on syntax, they are set to running by default.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickAbstractAnimation::isRunning() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->running;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the behavior calls this function
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::notifyRunningChanged(bool running)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->disableUserControl && d->running != running) {
|
|
|
|
d->running = running;
|
|
|
|
emit runningChanged(running);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//commence is called to start an animation when it is used as a
|
|
|
|
//simple animation, and not as part of a transition
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimationPrivate::commence()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_Q(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickStateActions actions;
|
|
|
|
QQmlProperties properties;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
QAbstractAnimationJob *oldInstance = animationInstance;
|
2012-02-16 04:43:03 +00:00
|
|
|
animationInstance = q->transition(actions, properties, QQuickAbstractAnimation::Forward);
|
2012-05-28 06:09:26 +00:00
|
|
|
if (oldInstance && oldInstance != animationInstance)
|
|
|
|
delete oldInstance;
|
|
|
|
|
|
|
|
if (animationInstance) {
|
2013-09-18 18:16:16 +00:00
|
|
|
if (oldInstance != animationInstance) {
|
|
|
|
if (q->threadingModel() == QQuickAbstractAnimation::RenderThread)
|
|
|
|
animationInstance = new QQuickAnimatorProxyJob(animationInstance, q);
|
2012-05-28 06:09:26 +00:00
|
|
|
animationInstance->addAnimationChangeListener(this, QAbstractAnimationJob::Completion);
|
2013-09-18 18:16:16 +00:00
|
|
|
}
|
2012-05-28 06:09:26 +00:00
|
|
|
animationInstance->start();
|
|
|
|
if (animationInstance->isStopped()) {
|
|
|
|
running = false;
|
2012-07-06 01:43:41 +00:00
|
|
|
emit q->stopped();
|
2012-05-28 06:09:26 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-08 11:50:08 +00:00
|
|
|
QQmlProperty QQuickAbstractAnimationPrivate::createProperty(QObject *obj, const QString &str, QObject *infoObj, QString *errorMessage)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlProperty prop(obj, str, qmlContext(infoObj));
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!prop.isValid()) {
|
2015-12-08 11:50:08 +00:00
|
|
|
const QString message = QQuickAbstractAnimation::tr("Cannot animate non-existent property \"%1\"").arg(str);
|
|
|
|
if (errorMessage)
|
|
|
|
*errorMessage = message;
|
|
|
|
else
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(infoObj) << message;
|
2012-02-16 04:43:03 +00:00
|
|
|
return QQmlProperty();
|
2011-04-27 10:05:43 +00:00
|
|
|
} else if (!prop.isWritable()) {
|
2015-12-08 11:50:08 +00:00
|
|
|
const QString message = QQuickAbstractAnimation::tr("Cannot animate read-only property \"%1\"").arg(str);
|
|
|
|
if (errorMessage)
|
|
|
|
*errorMessage = message;
|
|
|
|
else
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(infoObj) << message;
|
2012-02-16 04:43:03 +00:00
|
|
|
return QQmlProperty();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2012-07-06 01:43:41 +00:00
|
|
|
/*!
|
2014-03-14 15:41:01 +00:00
|
|
|
\qmlsignal QtQuick::Animation::started()
|
2012-07-06 01:43:41 +00:00
|
|
|
|
2014-03-14 15:41:01 +00:00
|
|
|
This signal is emitted when the animation begins.
|
2012-07-06 01:43:41 +00:00
|
|
|
|
|
|
|
It is only triggered for top-level, standalone animations. It will not be
|
|
|
|
triggered for animations in a Behavior or Transition, or animations
|
|
|
|
that are part of an animation group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
2014-03-14 15:41:01 +00:00
|
|
|
\qmlsignal QtQuick::Animation::stopped()
|
2012-07-06 01:43:41 +00:00
|
|
|
|
2014-03-14 15:41:01 +00:00
|
|
|
This signal is emitted when the animation ends.
|
2012-07-06 01:43:41 +00:00
|
|
|
|
|
|
|
The animation may have been stopped manually, or may have run to completion.
|
|
|
|
|
|
|
|
It is only triggered for top-level, standalone animations. It will not be
|
|
|
|
triggered for animations in a Behavior or Transition, or animations
|
|
|
|
that are part of an animation group.
|
|
|
|
|
2014-03-14 15:41:01 +00:00
|
|
|
If \l alwaysRunToEnd is true, this signal will not be emitted until the animation
|
2012-07-06 01:43:41 +00:00
|
|
|
has completed its current iteration.
|
|
|
|
*/
|
|
|
|
|
2018-03-07 13:57:29 +00:00
|
|
|
/*!
|
|
|
|
\qmlsignal QtQuick::Animation::finished()
|
|
|
|
\since 5.12
|
|
|
|
|
|
|
|
This signal is emitted when the animation has finished naturally.
|
|
|
|
|
|
|
|
It is not emitted when \l running is set to \c false, nor for animations whose
|
|
|
|
\l loops property is set to \c Animation.Infinite.
|
|
|
|
|
|
|
|
In addition, it is only emitted for top-level, standalone animations. It
|
|
|
|
will not be emitted for animations in a Behavior or Transition, or
|
|
|
|
animations that are part of an animation group.
|
|
|
|
|
|
|
|
If \l alwaysRunToEnd is true, this signal will not be emitted until the
|
|
|
|
animation has completed its current iteration.
|
|
|
|
|
|
|
|
\sa stopped(), started(), running
|
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setRunning(bool r)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!d->componentComplete) {
|
|
|
|
d->running = r;
|
|
|
|
if (r == false)
|
|
|
|
d->avoidPropertyValueSourceStart = true;
|
|
|
|
else if (!d->registered) {
|
|
|
|
d->registered = true;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlEnginePrivate *engPriv = QQmlEnginePrivate::get(qmlEngine(this));
|
2012-02-03 02:26:37 +00:00
|
|
|
static int finalizedIdx = -1;
|
|
|
|
if (finalizedIdx < 0)
|
|
|
|
finalizedIdx = metaObject()->indexOfSlot("componentFinalized()");
|
|
|
|
engPriv->registerFinalizeCallback(this, finalizedIdx);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->running == r)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (d->group || d->disableUserControl) {
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << "setRunning() cannot be used on non-root animation nodes.";
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->running = r;
|
|
|
|
if (d->running) {
|
|
|
|
bool supressStart = false;
|
|
|
|
if (d->alwaysRunToEnd && d->loopCount != 1
|
2012-02-03 02:26:37 +00:00
|
|
|
&& d->animationInstance && d->animationInstance->isRunning()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
//we've restarted before the final loop finished; restore proper loop count
|
|
|
|
if (d->loopCount == -1)
|
2012-02-03 02:26:37 +00:00
|
|
|
d->animationInstance->setLoopCount(d->loopCount);
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
2012-02-03 02:26:37 +00:00
|
|
|
d->animationInstance->setLoopCount(d->animationInstance->currentLoop() + d->loopCount);
|
2011-04-27 10:05:43 +00:00
|
|
|
supressStart = true; //we want the animation to continue, rather than restart
|
|
|
|
}
|
2012-07-06 01:43:41 +00:00
|
|
|
if (!supressStart) {
|
2011-04-27 10:05:43 +00:00
|
|
|
d->commence();
|
2012-07-06 01:43:41 +00:00
|
|
|
emit started();
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2012-03-16 13:15:00 +00:00
|
|
|
if (d->paused) {
|
|
|
|
d->paused = false; //reset paused state to false when stopped
|
|
|
|
emit pausedChanged(d->paused);
|
|
|
|
}
|
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
if (d->animationInstance) {
|
|
|
|
if (d->alwaysRunToEnd) {
|
|
|
|
if (d->loopCount != 1)
|
|
|
|
d->animationInstance->setLoopCount(d->animationInstance->currentLoop()+1); //finish the current loop
|
|
|
|
} else {
|
|
|
|
d->animationInstance->stop();
|
2012-07-06 01:43:41 +00:00
|
|
|
emit stopped();
|
2012-02-03 02:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit runningChanged(d->running);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty bool QtQuick::Animation::paused
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds whether the animation is currently paused.
|
|
|
|
|
|
|
|
The \c paused property can be set to declaratively control whether or not
|
|
|
|
an animation is paused.
|
|
|
|
|
|
|
|
Animations can also be paused and resumed imperatively from JavaScript
|
|
|
|
using the \c pause() and \c resume() methods.
|
|
|
|
|
|
|
|
By default, animations are not paused.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickAbstractAnimation::isPaused() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2012-03-16 13:15:00 +00:00
|
|
|
Q_ASSERT((d->paused && d->running) || !d->paused);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->paused;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setPaused(bool p)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->paused == p)
|
|
|
|
return;
|
|
|
|
|
2012-03-16 13:15:00 +00:00
|
|
|
if (!d->running) {
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << "setPaused() cannot be used when animation isn't running.";
|
2012-03-16 13:15:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->group || d->disableUserControl) {
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << "setPaused() cannot be used on non-root animation nodes.";
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->paused = p;
|
2011-07-29 03:10:25 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
if (!d->componentComplete || !d->animationInstance)
|
2011-07-29 03:10:25 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->paused)
|
2012-02-03 02:26:37 +00:00
|
|
|
d->animationInstance->pause();
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
2012-02-03 02:26:37 +00:00
|
|
|
d->animationInstance->resume();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
emit pausedChanged(d->paused);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::classBegin()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->componentComplete = false;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::componentComplete()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->componentComplete = true;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::componentFinalized()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->running) {
|
|
|
|
d->running = false;
|
|
|
|
setRunning(true);
|
|
|
|
}
|
2011-07-29 03:10:25 +00:00
|
|
|
if (d->paused) {
|
|
|
|
d->paused = false;
|
|
|
|
setPaused(true);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty bool QtQuick::Animation::alwaysRunToEnd
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds whether the animation should run to completion when it is stopped.
|
|
|
|
|
|
|
|
If this true the animation will complete its current iteration when it
|
|
|
|
is stopped - either by setting the \c running property to false, or by
|
|
|
|
calling the \c stop() method. The \c complete() method is not effected
|
|
|
|
by this value.
|
|
|
|
|
2012-08-15 04:30:31 +00:00
|
|
|
This behavior is most useful when the \c loops property is set, as the
|
2011-04-27 10:05:43 +00:00
|
|
|
animation will finish playing normally but not restart.
|
|
|
|
|
|
|
|
By default, the alwaysRunToEnd property is not set.
|
|
|
|
|
|
|
|
\note alwaysRunToEnd has no effect on animations in a Transition.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickAbstractAnimation::alwaysRunToEnd() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->alwaysRunToEnd;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setAlwaysRunToEnd(bool f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->alwaysRunToEnd == f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->alwaysRunToEnd = f;
|
|
|
|
emit alwaysRunToEndChanged(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty int QtQuick::Animation::loops
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the number of times the animation should play.
|
|
|
|
|
|
|
|
By default, \c loops is 1: the animation will play through once and then stop.
|
|
|
|
|
|
|
|
If set to Animation.Infinite, the animation will continuously repeat until it is explicitly
|
|
|
|
stopped - either by setting the \c running property to false, or by calling
|
|
|
|
the \c stop() method.
|
|
|
|
|
|
|
|
In the following example, the rectangle will spin indefinitely.
|
|
|
|
|
|
|
|
\code
|
|
|
|
Rectangle {
|
|
|
|
width: 100; height: 100; color: "green"
|
|
|
|
RotationAnimation on rotation {
|
|
|
|
loops: Animation.Infinite
|
|
|
|
from: 0
|
|
|
|
to: 360
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickAbstractAnimation::loops() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->loopCount;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setLoops(int loops)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (loops < 0)
|
|
|
|
loops = -1;
|
|
|
|
|
|
|
|
if (loops == d->loopCount)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->loopCount = loops;
|
|
|
|
emit loopCountChanged(loops);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickAbstractAnimation::duration() const
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->animationInstance ? d->animationInstance->duration() : 0;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickAbstractAnimation::currentTime()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->animationInstance ? d->animationInstance->currentLoopTime() : 0;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setCurrentTime(int time)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
if (d->animationInstance)
|
|
|
|
d->animationInstance->setCurrentTime(time);
|
|
|
|
//TODO save value for start?
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationGroup *QQuickAbstractAnimation::group() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->group;
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:49:07 +00:00
|
|
|
void QQuickAbstractAnimation::setGroup(QQuickAnimationGroup *g, int index)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->group == g)
|
|
|
|
return;
|
|
|
|
if (d->group)
|
2012-05-29 01:15:11 +00:00
|
|
|
d->group->d_func()->animations.removeAll(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
d->group = g;
|
|
|
|
|
2019-11-25 13:49:07 +00:00
|
|
|
if (d->group && !d->group->d_func()->animations.contains(this)) {
|
|
|
|
if (index >= 0)
|
|
|
|
d->group->d_func()->animations.insert(index, this);
|
|
|
|
else
|
|
|
|
d->group->d_func()->animations.append(this);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::start()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Starts the animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If the animation is already running, calling this method has no effect. The
|
|
|
|
\c running property will be true following a call to \c start().
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::start()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
setRunning(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::pause()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Pauses the animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-16 13:15:00 +00:00
|
|
|
If the animation is already paused or not \c running, calling this method has no effect.
|
|
|
|
The \c paused property will be true following a call to \c pause().
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::pause()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
setPaused(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::resume()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Resumes a paused animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-16 13:15:00 +00:00
|
|
|
If the animation is not paused or not \c running, calling this method has no effect.
|
|
|
|
The \c paused property will be false following a call to \c resume().
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::resume()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
setPaused(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::stop()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Stops the animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-03-16 13:15:00 +00:00
|
|
|
If the animation is not running, calling this method has no effect. Both the
|
|
|
|
\c running and \c paused properties will be false following a call to \c stop().
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Normally \c stop() stops the animation immediately, and the animation has
|
|
|
|
no further influence on property values. In this example animation
|
|
|
|
\code
|
|
|
|
Rectangle {
|
|
|
|
NumberAnimation on x { from: 0; to: 100; duration: 500 }
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
was stopped at time 250ms, the \c x property will have a value of 50.
|
|
|
|
|
|
|
|
However, if the \c alwaysRunToEnd property is set, the animation will
|
|
|
|
continue running until it completes and then stop. The \c running property
|
|
|
|
will still become false immediately.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::stop()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
setRunning(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::restart()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Restarts the animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
This is a convenience method, and is equivalent to calling \c stop() and
|
|
|
|
then \c start().
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::restart()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
stop();
|
|
|
|
start();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlmethod QtQuick::Animation::complete()
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Stops the animation, jumping to the final property values
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
If the animation is not running, calling this method has no effect. The
|
|
|
|
\c running property will be false following a call to \c complete().
|
|
|
|
|
|
|
|
Unlike \c stop(), \c complete() immediately fast-forwards the animation to
|
|
|
|
its end. In the following example,
|
|
|
|
\code
|
|
|
|
Rectangle {
|
|
|
|
NumberAnimation on x { from: 0; to: 100; duration: 500 }
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
calling \c stop() at time 250ms will result in the \c x property having
|
|
|
|
a value of 50, while calling \c complete() will set the \c x property to
|
|
|
|
100, exactly as though the animation had played the whole way through.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::complete()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
if (isRunning() && d->animationInstance) {
|
|
|
|
d->animationInstance->setCurrentTime(d->animationInstance->duration());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setTarget(const QQmlProperty &p)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->defaultProperty = p;
|
|
|
|
|
|
|
|
if (!d->avoidPropertyValueSourceStart)
|
|
|
|
setRunning(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
we rely on setTarget only being called when used as a value source
|
|
|
|
so this function allows us to do the same thing as setTarget without
|
|
|
|
that assumption
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setDefaultTarget(const QQmlProperty &p)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->defaultProperty = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
don't allow start/stop/pause/resume to be manually invoked,
|
|
|
|
because something else (like a Behavior) already has control
|
|
|
|
over the animation.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setDisableUserControl()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->disableUserControl = true;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimation::setEnableUserControl()
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
d->disableUserControl = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
bool QQuickAbstractAnimation::userControlDisabled() const
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->disableUserControl;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickAbstractAnimation::initInstance(QAbstractAnimationJob *animation)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
animation->setLoopCount(d->loopCount);
|
|
|
|
return animation;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickAbstractAnimation::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(actions);
|
|
|
|
Q_UNUSED(modified);
|
|
|
|
Q_UNUSED(direction);
|
2012-02-03 03:18:05 +00:00
|
|
|
Q_UNUSED(defaultTarget);
|
2018-02-21 09:41:54 +00:00
|
|
|
return nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAbstractAnimationPrivate::animationFinished(QAbstractAnimationJob*)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_Q(QQuickAbstractAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
q->setRunning(false);
|
2012-07-06 01:43:41 +00:00
|
|
|
if (alwaysRunToEnd) {
|
|
|
|
emit q->stopped();
|
2011-04-27 10:05:43 +00:00
|
|
|
//restore the proper loopCount for the next run
|
2012-07-06 01:43:41 +00:00
|
|
|
if (loopCount != 1)
|
|
|
|
animationInstance->setLoopCount(loopCount);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2018-03-07 13:57:29 +00:00
|
|
|
emit q->finished();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
QQuickAbstractAnimation::ThreadingModel QQuickAbstractAnimation::threadingModel() const
|
|
|
|
{
|
|
|
|
return GuiThread;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype PauseAnimation
|
|
|
|
\instantiates QQuickPauseAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Provides a pause for an animation.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
When used in a SequentialAnimation, PauseAnimation is a step when
|
|
|
|
nothing happens, for a specified duration.
|
|
|
|
|
|
|
|
A 500ms animation sequence, with a 100ms pause between two animations:
|
|
|
|
\code
|
|
|
|
SequentialAnimation {
|
|
|
|
NumberAnimation { ... duration: 200 }
|
|
|
|
PauseAnimation { duration: 100 }
|
|
|
|
NumberAnimation { ... duration: 200 }
|
|
|
|
}
|
|
|
|
\endcode
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPauseAnimation::QQuickPauseAnimation(QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(*(new QQuickPauseAnimationPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPauseAnimation::~QQuickPauseAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty int QtQuick::PauseAnimation::duration
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the duration of the pause in milliseconds
|
|
|
|
|
|
|
|
The default value is 250.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickPauseAnimation::duration() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPauseAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->duration;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPauseAnimation::setDuration(int duration)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (duration < 0) {
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << tr("Cannot set a duration of < 0");
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPauseAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
if (d->duration == duration)
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
2012-02-03 02:26:37 +00:00
|
|
|
d->duration = duration;
|
2011-04-27 10:05:43 +00:00
|
|
|
emit durationChanged(duration);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickPauseAnimation::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPauseAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
Q_UNUSED(actions);
|
|
|
|
Q_UNUSED(modified);
|
|
|
|
Q_UNUSED(direction);
|
2012-02-03 03:18:05 +00:00
|
|
|
Q_UNUSED(defaultTarget);
|
2012-02-03 02:26:37 +00:00
|
|
|
|
|
|
|
return initInstance(new QPauseAnimationJob(d->duration));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype ColorAnimation
|
|
|
|
\instantiates QQuickColorAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 17:40:02 +00:00
|
|
|
\ingroup qtquick-animation-properties
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits PropertyAnimation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Animates changes in color values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
ColorAnimation is a specialized PropertyAnimation that defines an
|
|
|
|
animation to be applied when a color value changes.
|
|
|
|
|
|
|
|
Here is a ColorAnimation applied to the \c color property of a \l Rectangle
|
|
|
|
as a property value source. It animates the \c color property's value from
|
|
|
|
its current value to a value of "red", over 1000 milliseconds:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/coloranimation.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a ColorAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
|
|
|
For convenience, when a ColorAnimation is used in a \l Transition, it will
|
|
|
|
animate any \c color properties that have been modified during the state
|
|
|
|
change. If a \l{PropertyAnimation::}{property} or
|
|
|
|
\l{PropertyAnimation::}{properties} are explicitly set for the animation,
|
|
|
|
then those are used instead.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickColorAnimation::QQuickColorAnimation(QObject *parent)
|
|
|
|
: QQuickPropertyAnimation(parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->interpolatorType = QMetaType::QColor;
|
|
|
|
d->defaultToInterpolatorType = true;
|
2012-02-03 02:26:37 +00:00
|
|
|
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickColorAnimation::~QQuickColorAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty color QtQuick::ColorAnimation::from
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the color value at which the animation should begin.
|
|
|
|
|
|
|
|
For example, the following animation is not applied until a color value
|
|
|
|
has reached "#c0c0c0":
|
|
|
|
|
|
|
|
\qml
|
|
|
|
Item {
|
|
|
|
states: [
|
|
|
|
// States are defined here...
|
|
|
|
]
|
|
|
|
|
2019-03-27 09:35:33 +00:00
|
|
|
transitions: Transition {
|
2012-02-20 00:07:08 +00:00
|
|
|
ColorAnimation { from: "#c0c0c0"; duration: 2000 }
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
If the ColorAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the starting state of the
|
|
|
|
\l Transition, or the current value of the property at the moment the
|
|
|
|
\l Behavior is triggered.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QColor QQuickColorAnimation::from() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->from.value<QColor>();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickColorAnimation::setFrom(const QColor &f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setFrom(f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty color QtQuick::ColorAnimation::to
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
This property holds the color value at which the animation should end.
|
|
|
|
|
|
|
|
If the ColorAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QColor QQuickColorAnimation::to() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->to.value<QColor>();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickColorAnimation::setTo(const QColor &t)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setTo(t);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
QActionAnimation::QActionAnimation()
|
2018-02-21 09:41:54 +00:00
|
|
|
: QAbstractAnimationJob(), animAction(nullptr)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QActionAnimation::QActionAnimation(QAbstractAnimationAction *action)
|
|
|
|
: QAbstractAnimationJob(), animAction(action)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QActionAnimation::~QActionAnimation()
|
|
|
|
{
|
|
|
|
delete animAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
int QActionAnimation::duration() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QActionAnimation::setAnimAction(QAbstractAnimationAction *action)
|
|
|
|
{
|
|
|
|
if (isRunning())
|
|
|
|
stop();
|
|
|
|
animAction = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QActionAnimation::updateCurrentTime(int)
|
|
|
|
{
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
void QActionAnimation::updateState(State newState, State oldState)
|
|
|
|
{
|
|
|
|
Q_UNUSED(oldState);
|
|
|
|
|
|
|
|
if (newState == Running) {
|
|
|
|
if (animAction) {
|
|
|
|
animAction->doAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-03-28 16:43:47 +00:00
|
|
|
void QActionAnimation::debugAnimation(QDebug d) const
|
|
|
|
{
|
2019-06-26 14:46:23 +00:00
|
|
|
d << "ActionAnimation(" << Qt::hex << (const void *) this << Qt::dec << ")";
|
2014-03-28 16:43:47 +00:00
|
|
|
|
|
|
|
if (animAction) {
|
|
|
|
int indentLevel = 1;
|
|
|
|
const QAbstractAnimationJob *job = this;
|
|
|
|
while ((job = job->group()))
|
|
|
|
++indentLevel;
|
|
|
|
animAction->debugAction(d, indentLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype ScriptAction
|
|
|
|
\instantiates QQuickScriptAction
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Defines scripts to be run during an animation.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
ScriptAction can be used to run a script at a specific point in an animation.
|
|
|
|
|
|
|
|
\qml
|
|
|
|
SequentialAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
ScriptAction { script: doSomething(); }
|
|
|
|
NumberAnimation {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
When used as part of a Transition, you can also target a specific
|
|
|
|
StateChangeScript to run using the \c scriptName property.
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/states/statechangescript.qml state and transition
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\sa StateChangeScript
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickScriptAction::QQuickScriptAction(QObject *parent)
|
|
|
|
:QQuickAbstractAnimation(*(new QQuickScriptActionPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickScriptAction::~QQuickScriptAction()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickScriptActionPrivate::QQuickScriptActionPrivate()
|
|
|
|
: QQuickAbstractAnimationPrivate(), hasRunScriptScript(false), reversing(false){}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty script QtQuick::ScriptAction::script
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the script to run.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlScriptString QQuickScriptAction::script() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->script;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickScriptAction::setScript(const QQmlScriptString &script)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->script = script;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty string QtQuick::ScriptAction::scriptName
|
2013-01-11 11:40:19 +00:00
|
|
|
This property holds the name of the StateChangeScript to run.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
This property is only valid when ScriptAction is used as part of a transition.
|
|
|
|
If both script and scriptName are set, scriptName will be used.
|
|
|
|
|
|
|
|
\note When using scriptName in a reversible transition, the script will only
|
|
|
|
be run when the transition is being run forwards.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QString QQuickScriptAction::stateChangeScriptName() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->name;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickScriptAction::setStateChangeScriptName(const QString &name)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->name = name;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationAction* QQuickScriptActionPrivate::createAction()
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
return new Proxy(this);
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:43:47 +00:00
|
|
|
void QQuickScriptActionPrivate::debugAction(QDebug d, int indentLevel) const
|
|
|
|
{
|
|
|
|
QQmlScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;
|
|
|
|
|
|
|
|
if (!scriptStr.isEmpty()) {
|
|
|
|
QQmlExpression expr(scriptStr);
|
|
|
|
|
|
|
|
QByteArray ind(indentLevel, ' ');
|
|
|
|
QString exprStr = expr.expression();
|
|
|
|
int endOfFirstLine = exprStr.indexOf('\n');
|
2016-04-06 12:23:58 +00:00
|
|
|
d << "\n" << ind.constData() << exprStr.leftRef(endOfFirstLine);
|
2014-03-28 16:43:47 +00:00
|
|
|
if (endOfFirstLine != -1 && endOfFirstLine < exprStr.length())
|
|
|
|
d << "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickScriptActionPrivate::execute()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_Q(QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (hasRunScriptScript && reversing)
|
|
|
|
return;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 03:01:33 +00:00
|
|
|
if (!scriptStr.isEmpty()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlExpression expr(scriptStr);
|
2011-04-27 10:05:43 +00:00
|
|
|
expr.evaluate();
|
|
|
|
if (expr.hasError())
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(q) << expr.error();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickScriptAction::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickScriptAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_UNUSED(modified);
|
2012-02-03 03:18:05 +00:00
|
|
|
Q_UNUSED(defaultTarget);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
d->hasRunScriptScript = false;
|
|
|
|
d->reversing = (direction == Backward);
|
2012-05-09 01:50:01 +00:00
|
|
|
if (!d->name.isEmpty()) {
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2012-05-09 01:50:01 +00:00
|
|
|
|
2013-10-03 15:04:40 +00:00
|
|
|
if (action.event && action.event->type() == QQuickStateActionEvent::Script
|
2012-05-09 01:50:01 +00:00
|
|
|
&& static_cast<QQuickStateChangeScript*>(action.event)->name() == d->name) {
|
|
|
|
d->runScriptScript = static_cast<QQuickStateChangeScript*>(action.event)->script();
|
|
|
|
d->hasRunScriptScript = true;
|
|
|
|
action.actionDone = true;
|
|
|
|
break; //only match one (names should be unique)
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-03 02:26:37 +00:00
|
|
|
return initInstance(new QActionAnimation(d->createAction()));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype PropertyAction
|
|
|
|
\instantiates QQuickPropertyAction
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Specifies immediate property changes during animation.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
PropertyAction is used to specify an immediate property change during an
|
|
|
|
animation. The property change is not animated.
|
|
|
|
|
|
|
|
It is useful for setting non-animated property values during an animation.
|
|
|
|
|
|
|
|
For example, here is a SequentialAnimation that sets the image's
|
2012-07-18 03:53:40 +00:00
|
|
|
\l {Item::}{opacity} property to \c .5, animates the width of the image,
|
|
|
|
then sets \l {Item::}{opacity} back to \c 1:
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyaction.qml standalone
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
PropertyAction is also useful for setting the exact point at which a property
|
|
|
|
change should occur during a \l Transition. For example, if PropertyChanges
|
|
|
|
was used in a \l State to rotate an item around a particular
|
|
|
|
\l {Item::}{transformOrigin}, it might be implemented like this:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyaction.qml transition
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
However, with this code, the \c transformOrigin is not set until \e after
|
|
|
|
the animation, as a \l State is taken to define the values at the \e end of
|
|
|
|
a transition. The animation would rotate at the default \c transformOrigin,
|
|
|
|
then jump to \c Item.BottomRight. To fix this, insert a PropertyAction
|
|
|
|
before the RotationAnimation begins:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyaction-sequential.qml sequential
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
This immediately sets the \c transformOrigin property to the value defined
|
|
|
|
in the end state of the \l Transition (i.e. the value defined in the
|
|
|
|
PropertyAction object) so that the rotation animation begins with the
|
|
|
|
correct transform origin.
|
|
|
|
|
2013-04-17 15:03:16 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt QML}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAction::QQuickPropertyAction(QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(*(new QQuickPropertyActionPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAction::~QQuickPropertyAction()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QObject *QQuickPropertyAction::target() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->target;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAction::setTargetObject(QObject *o)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->target == o)
|
|
|
|
return;
|
|
|
|
d->target = o;
|
|
|
|
emit targetChanged();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QString QQuickPropertyAction::property() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->propertyName;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAction::setProperty(const QString &n)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->propertyName == n)
|
|
|
|
return;
|
|
|
|
d->propertyName = n;
|
|
|
|
emit propertyChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty Object QtQuick::PropertyAction::target
|
|
|
|
\qmlproperty list<Object> QtQuick::PropertyAction::targets
|
|
|
|
\qmlproperty string QtQuick::PropertyAction::property
|
|
|
|
\qmlproperty string QtQuick::PropertyAction::properties
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
These properties determine the items and their properties that are
|
|
|
|
affected by this action.
|
|
|
|
|
|
|
|
The details of how these properties are interpreted in different situations
|
|
|
|
is covered in the \l{PropertyAnimation::properties}{corresponding} PropertyAnimation
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
\sa exclude
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QString QQuickPropertyAction::properties() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->properties;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAction::setProperties(const QString &p)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->properties == p)
|
|
|
|
return;
|
|
|
|
d->properties = p;
|
|
|
|
emit propertiesChanged(p);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QObject> QQuickPropertyAction::targets()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2019-11-25 13:49:07 +00:00
|
|
|
return QQmlListProperty<QObject>(this, &(d->targets));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty list<Object> QtQuick::PropertyAction::exclude
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the objects that should not be affected by this action.
|
|
|
|
|
|
|
|
\sa targets
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QObject> QQuickPropertyAction::exclude()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2019-11-25 13:49:07 +00:00
|
|
|
return QQmlListProperty<QObject>(this, &(d->exclude));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty any QtQuick::PropertyAction::value
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the value to be set on the property.
|
|
|
|
|
|
|
|
If the PropertyAction is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QVariant QQuickPropertyAction::value() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->value;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAction::setValue(const QVariant &v)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->value.isNull || d->value != v) {
|
|
|
|
d->value = v;
|
|
|
|
emit valueChanged(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickPropertyAction::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAction);
|
2011-04-27 10:05:43 +00:00
|
|
|
Q_UNUSED(direction);
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
struct QQuickSetPropertyAnimationAction : public QAbstractAnimationAction
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickStateActions actions;
|
2016-10-07 11:40:12 +00:00
|
|
|
void doAction() override
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
const QQuickStateAction &action = actions.at(ii);
|
2016-07-14 10:09:23 +00:00
|
|
|
QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-07 11:40:12 +00:00
|
|
|
void debugAction(QDebug d, int indentLevel) const override {
|
2014-03-28 16:43:47 +00:00
|
|
|
QByteArray ind(indentLevel, ' ');
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
|
|
|
const QQuickStateAction &action = actions.at(ii);
|
|
|
|
d << "\n" << ind.constData() << "target:" << action.property.object() << "property:" << action.property.name()
|
|
|
|
<< "value:" << action.toValue;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
|
|
|
|
for (int ii = 0; ii < props.count(); ++ii)
|
|
|
|
props[ii] = props.at(ii).trimmed();
|
|
|
|
if (!d->propertyName.isEmpty())
|
|
|
|
props << d->propertyName;
|
|
|
|
|
|
|
|
QList<QObject*> targets = d->targets;
|
|
|
|
if (d->target)
|
|
|
|
targets.append(d->target);
|
|
|
|
|
|
|
|
bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();
|
|
|
|
|
|
|
|
if (d->defaultProperty.isValid() && !hasSelectors) {
|
|
|
|
props << d->defaultProperty.name();
|
|
|
|
targets << d->defaultProperty.object();
|
|
|
|
}
|
|
|
|
|
2012-02-03 03:18:05 +00:00
|
|
|
if (defaultTarget && targets.isEmpty())
|
|
|
|
targets << defaultTarget;
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickSetPropertyAnimationAction *data = new QQuickSetPropertyAnimationAction;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
bool hasExplicit = false;
|
|
|
|
//an explicit animation has been specified
|
|
|
|
if (d->value.isValid()) {
|
|
|
|
for (int i = 0; i < props.count(); ++i) {
|
|
|
|
for (int j = 0; j < targets.count(); ++j) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction myAction;
|
2011-04-27 10:05:43 +00:00
|
|
|
myAction.property = d->createProperty(targets.at(j), props.at(i), this);
|
|
|
|
if (myAction.property.isValid()) {
|
|
|
|
myAction.toValue = d->value;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());
|
2011-04-27 10:05:43 +00:00
|
|
|
data->actions << myAction;
|
|
|
|
hasExplicit = true;
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2011-04-27 10:05:43 +00:00
|
|
|
if (action.property.object() == myAction.property.object() &&
|
|
|
|
myAction.property.name() == action.property.name()) {
|
|
|
|
modified << action.property;
|
|
|
|
break; //### any chance there could be multiples?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasExplicit)
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QObject *obj = action.property.object();
|
|
|
|
QString propertyName = action.property.name();
|
|
|
|
QObject *sObj = action.specifiedObject;
|
|
|
|
QString sPropertyName = action.specifiedProperty;
|
|
|
|
bool same = (obj == sObj);
|
|
|
|
|
|
|
|
if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
|
|
|
|
(!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
|
|
|
|
(props.contains(propertyName) || (!same && props.contains(sPropertyName)))) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction myAction = action;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (d->value.isValid())
|
|
|
|
myAction.toValue = d->value;
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimationPrivate::convertVariant(myAction.toValue, myAction.property.propertyType());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
modified << action.property;
|
|
|
|
data->actions << myAction;
|
|
|
|
action.fromValue = myAction.toValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
QActionAnimation *action = new QActionAnimation;
|
2011-04-27 10:05:43 +00:00
|
|
|
if (data->actions.count()) {
|
2012-02-03 02:26:37 +00:00
|
|
|
action->setAnimAction(data);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
|
|
|
delete data;
|
|
|
|
}
|
2012-02-03 02:26:37 +00:00
|
|
|
return initInstance(action);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype NumberAnimation
|
|
|
|
\instantiates QQuickNumberAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 17:40:02 +00:00
|
|
|
\ingroup qtquick-animation-properties
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits PropertyAnimation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Animates changes in qreal-type values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
NumberAnimation is a specialized PropertyAnimation that defines an
|
|
|
|
animation to be applied when a numerical value changes.
|
|
|
|
|
|
|
|
Here is a NumberAnimation applied to the \c x property of a \l Rectangle
|
|
|
|
as a property value source. It animates the \c x value from its current
|
|
|
|
value to a value of 50, over 1000 milliseconds:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/numberanimation.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a NumberAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
|
|
|
Note that NumberAnimation may not animate smoothly if there are irregular
|
|
|
|
changes in the number value that it is tracking. If this is the case, use
|
|
|
|
SmoothedAnimation instead.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickNumberAnimation::QQuickNumberAnimation(QObject *parent)
|
|
|
|
: QQuickPropertyAnimation(parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickNumberAnimation::QQuickNumberAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent)
|
|
|
|
: QQuickPropertyAnimation(dd, parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickNumberAnimation::~QQuickNumberAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickNumberAnimation::init()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->interpolatorType = QMetaType::QReal;
|
|
|
|
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty real QtQuick::NumberAnimation::from
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the starting value for the animation.
|
|
|
|
|
|
|
|
For example, the following animation is not applied until the \c x value
|
|
|
|
has reached 100:
|
|
|
|
|
|
|
|
\qml
|
|
|
|
Item {
|
|
|
|
states: [
|
|
|
|
// ...
|
|
|
|
]
|
|
|
|
|
|
|
|
transition: Transition {
|
|
|
|
NumberAnimation { properties: "x"; from: 100; duration: 200 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
If the NumberAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the starting state of the
|
|
|
|
\l Transition, or the current value of the property at the moment the
|
|
|
|
\l Behavior is triggered.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
qreal QQuickNumberAnimation::from() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->from.toReal();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickNumberAnimation::setFrom(qreal f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setFrom(f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty real QtQuick::NumberAnimation::to
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the end value for the animation.
|
|
|
|
|
|
|
|
If the NumberAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
qreal QQuickNumberAnimation::to() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->to.toReal();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickNumberAnimation::setTo(qreal t)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setTo(t);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype Vector3dAnimation
|
|
|
|
\instantiates QQuickVector3dAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 17:40:02 +00:00
|
|
|
\ingroup qtquick-animation-properties
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits PropertyAnimation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Animates changes in QVector3d values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Vector3dAnimation is a specialized PropertyAnimation that defines an
|
|
|
|
animation to be applied when a Vector3d value changes.
|
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a Vector3dAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickVector3dAnimation::QQuickVector3dAnimation(QObject *parent)
|
|
|
|
: QQuickPropertyAnimation(parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->interpolatorType = QMetaType::QVector3D;
|
|
|
|
d->defaultToInterpolatorType = true;
|
2012-02-03 02:26:37 +00:00
|
|
|
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickVector3dAnimation::~QQuickVector3dAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2016-03-31 20:13:10 +00:00
|
|
|
\qmlproperty vector3d QtQuick::Vector3dAnimation::from
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the starting value for the animation.
|
|
|
|
|
|
|
|
If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the starting state of the
|
|
|
|
\l Transition, or the current value of the property at the moment the
|
|
|
|
\l Behavior is triggered.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QVector3D QQuickVector3dAnimation::from() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->from.value<QVector3D>();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickVector3dAnimation::setFrom(QVector3D f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setFrom(f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2016-03-31 20:13:10 +00:00
|
|
|
\qmlproperty vector3d QtQuick::Vector3dAnimation::to
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the end value for the animation.
|
|
|
|
|
|
|
|
If the Vector3dAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QVector3D QQuickVector3dAnimation::to() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->to.value<QVector3D>();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickVector3dAnimation::setTo(QVector3D t)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setTo(t);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype RotationAnimation
|
|
|
|
\instantiates QQuickRotationAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 17:40:02 +00:00
|
|
|
\ingroup qtquick-animation-properties
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits PropertyAnimation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Animates changes in rotation values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
RotationAnimation is a specialized PropertyAnimation that gives control
|
|
|
|
over the direction of rotation during an animation.
|
|
|
|
|
|
|
|
By default, it rotates in the direction
|
|
|
|
of the numerical change; a rotation from 0 to 240 will rotate 240 degrees
|
|
|
|
clockwise, while a rotation from 240 to 0 will rotate 240 degrees
|
|
|
|
counterclockwise. The \l direction property can be set to specify the
|
|
|
|
direction in which the rotation should occur.
|
|
|
|
|
|
|
|
In the following example we use RotationAnimation to animate the rotation
|
|
|
|
between states via the shortest path:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/rotationanimation.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-12-30 04:15:09 +00:00
|
|
|
Notice the RotationAnimation did not need to set a \c target
|
2011-04-27 10:05:43 +00:00
|
|
|
value. As a convenience, when used in a transition, RotationAnimation will rotate all
|
|
|
|
properties named "rotation" or "angle". You can override this by providing
|
|
|
|
your own properties via \l {PropertyAnimation::properties}{properties} or
|
|
|
|
\l {PropertyAnimation::property}{property}.
|
|
|
|
|
|
|
|
Also, note the \l Rectangle will be rotated around its default
|
|
|
|
\l {Item::}{transformOrigin} (which is \c Item.Center). To use a different
|
|
|
|
transform origin, set the origin in the PropertyChanges object and apply
|
|
|
|
the change at the start of the animation using PropertyAction. See the
|
|
|
|
PropertyAction documentation for more details.
|
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a RotationAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
QVariant _q_interpolateShortestRotation(qreal &f, qreal &t, qreal progress)
|
|
|
|
{
|
|
|
|
qreal newt = t;
|
|
|
|
qreal diff = t-f;
|
|
|
|
while(diff > 180.0){
|
|
|
|
newt -= 360.0;
|
|
|
|
diff -= 360.0;
|
|
|
|
}
|
|
|
|
while(diff < -180.0){
|
|
|
|
newt += 360.0;
|
|
|
|
diff += 360.0;
|
|
|
|
}
|
|
|
|
return QVariant(f + (newt - f) * progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant _q_interpolateClockwiseRotation(qreal &f, qreal &t, qreal progress)
|
|
|
|
{
|
|
|
|
qreal newt = t;
|
|
|
|
qreal diff = t-f;
|
|
|
|
while(diff < 0.0){
|
|
|
|
newt += 360.0;
|
|
|
|
diff += 360.0;
|
|
|
|
}
|
|
|
|
return QVariant(f + (newt - f) * progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant _q_interpolateCounterclockwiseRotation(qreal &f, qreal &t, qreal progress)
|
|
|
|
{
|
|
|
|
qreal newt = t;
|
|
|
|
qreal diff = t-f;
|
|
|
|
while(diff > 0.0){
|
|
|
|
newt -= 360.0;
|
|
|
|
diff -= 360.0;
|
|
|
|
}
|
|
|
|
return QVariant(f + (newt - f) * progress);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickRotationAnimation::QQuickRotationAnimation(QObject *parent)
|
|
|
|
: QQuickPropertyAnimation(*(new QQuickRotationAnimationPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickRotationAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
d->interpolatorType = QMetaType::QReal;
|
|
|
|
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
|
|
|
|
d->defaultProperties = QLatin1String("rotation,angle");
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickRotationAnimation::~QQuickRotationAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty real QtQuick::RotationAnimation::from
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the starting value for the animation.
|
|
|
|
|
|
|
|
For example, the following animation is not applied until the \c angle value
|
|
|
|
has reached 100:
|
|
|
|
|
|
|
|
\qml
|
|
|
|
Item {
|
|
|
|
states: [
|
|
|
|
// ...
|
|
|
|
]
|
|
|
|
|
|
|
|
transition: Transition {
|
|
|
|
RotationAnimation { properties: "angle"; from: 100; duration: 2000 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
If the RotationAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the starting state of the
|
|
|
|
\l Transition, or the current value of the property at the moment the
|
|
|
|
\l Behavior is triggered.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
qreal QQuickRotationAnimation::from() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickRotationAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->from.toReal();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickRotationAnimation::setFrom(qreal f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setFrom(f);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty real QtQuick::RotationAnimation::to
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the end value for the animation..
|
|
|
|
|
|
|
|
If the RotationAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
qreal QQuickRotationAnimation::to() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickRotationAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->to.toReal();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickRotationAnimation::setTo(qreal t)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::setTo(t);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty enumeration QtQuick::RotationAnimation::direction
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the direction of the rotation.
|
|
|
|
|
|
|
|
Possible values are:
|
|
|
|
|
|
|
|
\list
|
2012-03-01 17:05:16 +00:00
|
|
|
\li RotationAnimation.Numerical (default) - Rotate by linearly interpolating between the two numbers.
|
2011-04-27 10:05:43 +00:00
|
|
|
A rotation from 10 to 350 will rotate 340 degrees clockwise.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li RotationAnimation.Clockwise - Rotate clockwise between the two values
|
|
|
|
\li RotationAnimation.Counterclockwise - Rotate counterclockwise between the two values
|
|
|
|
\li RotationAnimation.Shortest - Rotate in the direction that produces the shortest animation path.
|
2011-04-27 10:05:43 +00:00
|
|
|
A rotation from 10 to 350 will rotate 20 degrees counterclockwise.
|
|
|
|
\endlist
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickRotationAnimation::RotationDirection QQuickRotationAnimation::direction() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickRotationAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->direction;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickRotationAnimation::setDirection(QQuickRotationAnimation::RotationDirection direction)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickRotationAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->direction == direction)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->direction = direction;
|
|
|
|
switch(d->direction) {
|
|
|
|
case Clockwise:
|
2018-02-28 14:26:58 +00:00
|
|
|
d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateClockwiseRotation));
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
case Counterclockwise:
|
2018-02-28 14:26:58 +00:00
|
|
|
d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateCounterclockwiseRotation));
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
case Shortest:
|
2018-02-28 14:26:58 +00:00
|
|
|
d->interpolator = reinterpret_cast<QVariantAnimation::Interpolator>(reinterpret_cast<void *>(&_q_interpolateShortestRotation));
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d->interpolator = QVariantAnimationPrivate::getInterpolator(d->interpolatorType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
emit directionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationGroup::QQuickAnimationGroup(QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(*(new QQuickAnimationGroupPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationGroup::QQuickAnimationGroup(QQuickAnimationGroupPrivate &dd, QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(dd, parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAnimationGroupPrivate::append_animation(QQmlListProperty<QQuickAbstractAnimation> *list, QQuickAbstractAnimation *a)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2013-11-14 16:53:58 +00:00
|
|
|
QQuickAnimationGroup *q = qmlobject_cast<QQuickAnimationGroup *>(list->object);
|
|
|
|
if (q && a)
|
2011-04-27 10:05:43 +00:00
|
|
|
a->setGroup(q);
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:49:07 +00:00
|
|
|
QQuickAbstractAnimation *QQuickAnimationGroupPrivate::at_animation(QQmlListProperty<QQuickAbstractAnimation> *list, int index)
|
|
|
|
{
|
|
|
|
if (auto q = qmlobject_cast<QQuickAnimationGroup *>(list->object))
|
|
|
|
return q->d_func()->animations.at(index);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int QQuickAnimationGroupPrivate::count_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
|
|
|
|
{
|
|
|
|
if (auto q = qmlobject_cast<QQuickAnimationGroup *>(list->object))
|
|
|
|
return q->d_func()->animations.count();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAnimationGroupPrivate::clear_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationGroup *q = qobject_cast<QQuickAnimationGroup *>(list->object);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (q) {
|
2011-05-23 14:44:29 +00:00
|
|
|
while (q->d_func()->animations.count()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAbstractAnimation *firstAnim = q->d_func()->animations.at(0);
|
2018-02-21 09:41:54 +00:00
|
|
|
firstAnim->setGroup(nullptr);
|
2011-05-23 14:44:29 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-25 13:49:07 +00:00
|
|
|
void QQuickAnimationGroupPrivate::replace_animation(QQmlListProperty<QQuickAbstractAnimation> *list,
|
|
|
|
int i, QQuickAbstractAnimation *a)
|
|
|
|
{
|
|
|
|
if (auto *q = qmlobject_cast<QQuickAnimationGroup *>(list->object)) {
|
|
|
|
if (QQuickAbstractAnimation *anim = q->d_func()->animations.at(i))
|
|
|
|
anim->setGroup(nullptr);
|
|
|
|
if (a)
|
|
|
|
a->setGroup(q, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void QQuickAnimationGroupPrivate::removeLast_animation(QQmlListProperty<QQuickAbstractAnimation> *list)
|
|
|
|
{
|
|
|
|
if (auto *q = qobject_cast<QQuickAnimationGroup *>(list->object))
|
|
|
|
q->d_func()->animations.last()->setGroup(nullptr);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationGroup::~QQuickAnimationGroup()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-05-29 01:15:11 +00:00
|
|
|
Q_D(QQuickAnimationGroup);
|
|
|
|
for (int i = 0; i < d->animations.count(); ++i)
|
2018-02-21 09:41:54 +00:00
|
|
|
d->animations.at(i)->d_func()->group = nullptr;
|
2012-05-29 01:15:11 +00:00
|
|
|
d->animations.clear();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QQuickAbstractAnimation> QQuickAnimationGroup::animations()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAnimationGroup);
|
2019-11-25 13:49:07 +00:00
|
|
|
return QQmlListProperty<QQuickAbstractAnimation>(
|
|
|
|
this, &(d->animations),
|
|
|
|
&QQuickAnimationGroupPrivate::append_animation,
|
|
|
|
&QQuickAnimationGroupPrivate::count_animation,
|
|
|
|
&QQuickAnimationGroupPrivate::at_animation,
|
|
|
|
&QQuickAnimationGroupPrivate::clear_animation,
|
|
|
|
&QQuickAnimationGroupPrivate::replace_animation,
|
|
|
|
&QQuickAnimationGroupPrivate::removeLast_animation);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype SequentialAnimation
|
|
|
|
\instantiates QQuickSequentialAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Allows animations to be run sequentially.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
The SequentialAnimation and ParallelAnimation types allow multiple
|
2011-04-27 10:05:43 +00:00
|
|
|
animations to be run together. Animations defined in a SequentialAnimation
|
|
|
|
are run one after the other, while animations defined in a ParallelAnimation
|
|
|
|
are run at the same time.
|
|
|
|
|
|
|
|
The following example runs two number animations in a sequence. The \l Rectangle
|
|
|
|
animates to a \c x position of 50, then to a \c y position of 50.
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/sequentialanimation.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
Animations defined within a \l Transition are automatically run in parallel,
|
|
|
|
so SequentialAnimation can be used to enclose the animations in a \l Transition
|
|
|
|
if this is the preferred behavior.
|
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a SequentialAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
|
|
|
\note Once an animation has been grouped into a SequentialAnimation or
|
|
|
|
ParallelAnimation, it cannot be individually started and stopped; the
|
|
|
|
SequentialAnimation or ParallelAnimation must be started and stopped as a group.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa ParallelAnimation, {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickSequentialAnimation::QQuickSequentialAnimation(QObject *parent) :
|
|
|
|
QQuickAnimationGroup(parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickSequentialAnimation::~QQuickSequentialAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
QQuickAbstractAnimation::ThreadingModel QQuickSequentialAnimation::threadingModel() const
|
|
|
|
{
|
|
|
|
Q_D(const QQuickAnimationGroup);
|
|
|
|
|
|
|
|
ThreadingModel style = AnyThread;
|
|
|
|
for (int i=0; i<d->animations.size(); ++i) {
|
|
|
|
ThreadingModel ces = d->animations.at(i)->threadingModel();
|
|
|
|
if (ces == GuiThread)
|
|
|
|
return GuiThread;
|
|
|
|
else if (ces == RenderThread)
|
|
|
|
style = RenderThread;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickSequentialAnimation::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAnimationGroup);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
QSequentialAnimationGroupJob *ag = new QSequentialAnimationGroupJob;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
int inc = 1;
|
|
|
|
int from = 0;
|
|
|
|
if (direction == Backward) {
|
|
|
|
inc = -1;
|
|
|
|
from = d->animations.count() - 1;
|
|
|
|
}
|
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
ThreadingModel execution = threadingModel();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool valid = d->defaultProperty.isValid();
|
2012-02-03 02:26:37 +00:00
|
|
|
QAbstractAnimationJob* anim;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) {
|
|
|
|
if (valid)
|
|
|
|
d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
|
2012-02-03 03:18:05 +00:00
|
|
|
anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget);
|
2013-09-18 18:16:16 +00:00
|
|
|
if (anim) {
|
|
|
|
if (d->animations.at(ii)->threadingModel() == RenderThread && execution != RenderThread)
|
|
|
|
anim = new QQuickAnimatorProxyJob(anim, this);
|
2012-05-28 06:09:26 +00:00
|
|
|
inc == -1 ? ag->prependAnimation(anim) : ag->appendAnimation(anim);
|
2013-09-18 18:16:16 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-02-03 02:26:37 +00:00
|
|
|
|
|
|
|
return initInstance(ag);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype ParallelAnimation
|
|
|
|
\instantiates QQuickParallelAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 07:12:56 +00:00
|
|
|
\ingroup qtquick-transitions-animations
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Enables animations to be run in parallel.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
The SequentialAnimation and ParallelAnimation types allow multiple
|
2011-04-27 10:05:43 +00:00
|
|
|
animations to be run together. Animations defined in a SequentialAnimation
|
|
|
|
are run one after the other, while animations defined in a ParallelAnimation
|
|
|
|
are run at the same time.
|
|
|
|
|
|
|
|
The following animation runs two number animations in parallel. The \l Rectangle
|
|
|
|
moves to (50,50) by animating its \c x and \c y properties at the same time.
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/parallelanimation.qml 0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Like any other animation type, a ParallelAnimation can be applied in a
|
2011-04-27 10:05:43 +00:00
|
|
|
number of ways, including transitions, behaviors and property value
|
2012-08-02 03:06:09 +00:00
|
|
|
sources. The \l {Animation and Transitions in Qt Quick} documentation shows a
|
2011-04-27 10:05:43 +00:00
|
|
|
variety of methods for creating animations.
|
|
|
|
|
|
|
|
\note Once an animation has been grouped into a SequentialAnimation or
|
|
|
|
ParallelAnimation, it cannot be individually started and stopped; the
|
|
|
|
SequentialAnimation or ParallelAnimation must be started and stopped as a group.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa SequentialAnimation, {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickParallelAnimation::QQuickParallelAnimation(QObject *parent) :
|
|
|
|
QQuickAnimationGroup(parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickParallelAnimation::~QQuickParallelAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
QQuickAbstractAnimation::ThreadingModel QQuickParallelAnimation::threadingModel() const
|
|
|
|
{
|
|
|
|
Q_D(const QQuickAnimationGroup);
|
|
|
|
|
|
|
|
ThreadingModel style = AnyThread;
|
|
|
|
for (int i=0; i<d->animations.size(); ++i) {
|
|
|
|
ThreadingModel ces = d->animations.at(i)->threadingModel();
|
|
|
|
if (ces == GuiThread)
|
|
|
|
return GuiThread;
|
|
|
|
else if (ces == RenderThread)
|
|
|
|
style = RenderThread;
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickParallelAnimation::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickAnimationGroup);
|
2012-02-03 02:26:37 +00:00
|
|
|
QParallelAnimationGroupJob *ag = new QParallelAnimationGroupJob;
|
|
|
|
|
2013-09-18 18:16:16 +00:00
|
|
|
ThreadingModel style = threadingModel();
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool valid = d->defaultProperty.isValid();
|
2012-02-03 02:26:37 +00:00
|
|
|
QAbstractAnimationJob* anim;
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int ii = 0; ii < d->animations.count(); ++ii) {
|
|
|
|
if (valid)
|
|
|
|
d->animations.at(ii)->setDefaultTarget(d->defaultProperty);
|
2012-02-03 03:18:05 +00:00
|
|
|
anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget);
|
2013-09-18 18:16:16 +00:00
|
|
|
if (anim) {
|
|
|
|
if (d->animations.at(ii)->threadingModel() == RenderThread && style != RenderThread)
|
|
|
|
anim = new QQuickAnimatorProxyJob(anim, this);
|
2012-05-28 06:09:26 +00:00
|
|
|
ag->appendAnimation(anim);
|
2013-09-18 18:16:16 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-02-03 02:26:37 +00:00
|
|
|
return initInstance(ag);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//convert a variant from string type to another animatable type
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimationPrivate::convertVariant(QVariant &variant, int type)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2019-12-03 19:24:38 +00:00
|
|
|
if (variant.userType() != QMetaType::QString) {
|
2012-05-18 15:30:03 +00:00
|
|
|
variant.convert(type);
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2019-12-03 19:24:38 +00:00
|
|
|
case QMetaType::QRect:
|
|
|
|
case QMetaType::QRectF:
|
|
|
|
case QMetaType::QPoint:
|
|
|
|
case QMetaType::QPointF:
|
|
|
|
case QMetaType::QSize:
|
|
|
|
case QMetaType::QSizeF:
|
|
|
|
case QMetaType::QColor:
|
|
|
|
case QMetaType::QVector3D:
|
2012-03-01 22:25:43 +00:00
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
variant = QQmlStringConverters::variantFromString(variant.toString(), type, &ok);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-02-16 04:43:03 +00:00
|
|
|
if (QQmlValueTypeFactory::isValueType((uint)type)) {
|
2012-05-18 15:30:03 +00:00
|
|
|
variant.convert(type);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlMetaType::StringConverter converter = QQmlMetaType::customStringConverter(type);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (converter)
|
|
|
|
variant = converter(variant.toString());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickBulkValueAnimator::QQuickBulkValueAnimator()
|
2018-02-21 09:41:54 +00:00
|
|
|
: QAbstractAnimationJob(), animValue(nullptr), fromSourced(nullptr), m_duration(250)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickBulkValueAnimator::~QQuickBulkValueAnimator()
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
delete animValue;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickBulkValueAnimator::setAnimValue(QQuickBulkValueUpdater *value)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
if (isRunning())
|
|
|
|
stop();
|
|
|
|
animValue = value;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickBulkValueAnimator::updateCurrentTime(int currentTime)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
if (isStopped())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const qreal progress = easing.valueForProgress(((m_duration == 0) ? qreal(1) : qreal(currentTime) / qreal(m_duration)));
|
|
|
|
|
|
|
|
if (animValue)
|
|
|
|
animValue->setValue(progress);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickBulkValueAnimator::topLevelAnimationLoopChanged()
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
|
|
|
//check for new from every top-level loop (when the top level animation is started and all subsequent loops)
|
|
|
|
if (fromSourced)
|
|
|
|
*fromSourced = false;
|
2013-09-20 13:26:03 +00:00
|
|
|
QAbstractAnimationJob::topLevelAnimationLoopChanged();
|
2012-02-03 02:26:37 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 16:43:47 +00:00
|
|
|
void QQuickBulkValueAnimator::debugAnimation(QDebug d) const
|
|
|
|
{
|
2019-06-26 14:46:23 +00:00
|
|
|
d << "BulkValueAnimation(" << Qt::hex << (const void *) this << Qt::dec << ")" << "duration:" << duration();
|
2014-03-28 16:43:47 +00:00
|
|
|
|
|
|
|
if (animValue) {
|
|
|
|
int indentLevel = 1;
|
|
|
|
const QAbstractAnimationJob *job = this;
|
|
|
|
while ((job = job->group()))
|
|
|
|
++indentLevel;
|
|
|
|
animValue->debugUpdater(d, indentLevel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
/*!
|
2012-07-27 15:18:12 +00:00
|
|
|
\qmltype PropertyAnimation
|
|
|
|
\instantiates QQuickPropertyAnimation
|
2013-09-24 14:41:12 +00:00
|
|
|
\inqmlmodule QtQuick
|
2012-05-28 17:40:02 +00:00
|
|
|
\ingroup qtquick-animation-properties
|
2011-04-27 10:05:43 +00:00
|
|
|
\inherits Animation
|
2018-06-18 13:09:56 +00:00
|
|
|
\brief Animates changes in property values.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
PropertyAnimation provides a way to animate changes to a property's value.
|
|
|
|
|
|
|
|
It can be used to define animations in a number of ways:
|
|
|
|
|
|
|
|
\list
|
2012-03-01 17:05:16 +00:00
|
|
|
\li In a \l Transition
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
For example, to animate any objects that have changed their \c x or \c y properties
|
|
|
|
as a result of a state change, using an \c InOutQuad easing curve:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyanimation.qml transition
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
2012-03-01 17:05:16 +00:00
|
|
|
\li In a \l Behavior
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
For example, to animate all changes to a rectangle's \c x property:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyanimation.qml behavior
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
2012-03-01 17:05:16 +00:00
|
|
|
\li As a property value source
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
For example, to repeatedly animate the rectangle's \c x property:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyanimation.qml propertyvaluesource
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
|
2012-03-01 17:05:16 +00:00
|
|
|
\li In a signal handler
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
For example, to fade out \c theObject when clicked:
|
|
|
|
\qml
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: theObject
|
|
|
|
onClicked: PropertyAnimation { target: theObject; property: "opacity"; to: 0 }
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
|
2012-03-01 17:05:16 +00:00
|
|
|
\li Standalone
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
For example, to animate \c rect's \c width property over 500ms, from its current width to 30:
|
|
|
|
|
2012-05-28 01:56:24 +00:00
|
|
|
\snippet qml/propertyanimation.qml standalone
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
Depending on how the animation is used, the set of properties normally used will be
|
|
|
|
different. For more information see the individual property documentation, as well
|
2012-08-02 03:06:09 +00:00
|
|
|
as the \l{Animation and Transitions in Qt Quick} introduction.
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-07-11 06:29:42 +00:00
|
|
|
Note that PropertyAnimation inherits the abstract \l Animation type.
|
2011-04-27 10:05:43 +00:00
|
|
|
This includes additional properties and methods for controlling the animation.
|
|
|
|
|
2013-11-05 12:17:06 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}, {Qt Quick Examples - Animation}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::QQuickPropertyAnimation(QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(*(new QQuickPropertyAnimationPrivate), parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::QQuickPropertyAnimation(QQuickPropertyAnimationPrivate &dd, QObject *parent)
|
|
|
|
: QQuickAbstractAnimation(dd, parent)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimation::~QQuickPropertyAnimation()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty int QtQuick::PropertyAnimation::duration
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the duration of the animation, in milliseconds.
|
|
|
|
|
|
|
|
The default value is 250.
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
int QQuickPropertyAnimation::duration() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->duration;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setDuration(int duration)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
if (duration < 0) {
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << tr("Cannot set a duration of < 0");
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
if (d->duration == duration)
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
2012-02-03 02:26:37 +00:00
|
|
|
d->duration = duration;
|
2011-04-27 10:05:43 +00:00
|
|
|
emit durationChanged(duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty variant QtQuick::PropertyAnimation::from
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the starting value for the animation.
|
|
|
|
|
|
|
|
If the PropertyAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the starting state of the
|
|
|
|
\l Transition, or the current value of the property at the moment the
|
|
|
|
\l Behavior is triggered.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QVariant QQuickPropertyAnimation::from() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->from;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setFrom(const QVariant &f)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->fromIsDefined && f == d->from)
|
|
|
|
return;
|
|
|
|
d->from = f;
|
|
|
|
d->fromIsDefined = f.isValid();
|
2017-09-15 10:43:58 +00:00
|
|
|
emit fromChanged();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty variant QtQuick::PropertyAnimation::to
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the end value for the animation.
|
|
|
|
|
|
|
|
If the PropertyAnimation is defined within a \l Transition or \l Behavior,
|
|
|
|
this value defaults to the value defined in the end state of the
|
|
|
|
\l Transition, or the value of the property change that triggered the
|
|
|
|
\l Behavior.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QVariant QQuickPropertyAnimation::to() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->to;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setTo(const QVariant &t)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->toIsDefined && t == d->to)
|
|
|
|
return;
|
|
|
|
d->to = t;
|
|
|
|
d->toIsDefined = t.isValid();
|
2017-09-15 10:43:58 +00:00
|
|
|
emit toChanged();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-12-18 16:45:52 +00:00
|
|
|
\qmlpropertygroup QtQuick::PropertyAnimation::easing
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty enumeration QtQuick::PropertyAnimation::easing.type
|
|
|
|
\qmlproperty real QtQuick::PropertyAnimation::easing.amplitude
|
|
|
|
\qmlproperty real QtQuick::PropertyAnimation::easing.overshoot
|
|
|
|
\qmlproperty real QtQuick::PropertyAnimation::easing.period
|
|
|
|
\qmlproperty list<real> QtQuick::PropertyAnimation::easing.bezierCurve
|
2013-09-18 18:16:16 +00:00
|
|
|
|
|
|
|
//! propertyanimation.easing
|
2012-05-18 13:19:55 +00:00
|
|
|
\brief Specifies the easing curve used for the animation
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
To specify an easing curve you need to specify at least the type. For some curves you can also specify
|
|
|
|
amplitude, period and/or overshoot (more details provided after the table). The default easing curve is
|
|
|
|
\c Easing.Linear.
|
|
|
|
|
|
|
|
\qml
|
2015-06-04 10:41:56 +00:00
|
|
|
PropertyAnimation { properties: "y";
|
|
|
|
easing.type: Easing.InOutElastic;
|
|
|
|
easing.amplitude: 2.0;
|
|
|
|
easing.period: 1.5 }
|
2011-04-27 10:05:43 +00:00
|
|
|
\endqml
|
|
|
|
|
|
|
|
Available types are:
|
|
|
|
|
|
|
|
\table
|
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.Linear
|
|
|
|
\li Easing curve for a linear (t) function: velocity is constant.
|
|
|
|
\li \inlineimage qeasingcurve-linear.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InQuad
|
|
|
|
\li Easing curve for a quadratic (t^2) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inquad.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutQuad
|
|
|
|
\li Easing curve for a quadratic (t^2) function: decelerating to zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-outquad.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutQuad
|
|
|
|
\li Easing curve for a quadratic (t^2) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutquad.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInQuad
|
|
|
|
\li Easing curve for a quadratic (t^2) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinquad.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InCubic
|
|
|
|
\li Easing curve for a cubic (t^3) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-incubic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutCubic
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a cubic (t^3) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outcubic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutCubic
|
|
|
|
\li Easing curve for a cubic (t^3) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutcubic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInCubic
|
|
|
|
\li Easing curve for a cubic (t^3) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outincubic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InQuart
|
|
|
|
\li Easing curve for a quartic (t^4) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inquart.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutQuart
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a quartic (t^4) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outquart.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutQuart
|
|
|
|
\li Easing curve for a quartic (t^4) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutquart.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInQuart
|
|
|
|
\li Easing curve for a quartic (t^4) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinquart.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InQuint
|
|
|
|
\li Easing curve for a quintic (t^5) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inquint.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutQuint
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a quintic (t^5) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outquint.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutQuint
|
|
|
|
\li Easing curve for a quintic (t^5) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutquint.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInQuint
|
|
|
|
\li Easing curve for a quintic (t^5) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinquint.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InSine
|
|
|
|
\li Easing curve for a sinusoidal (sin(t)) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-insine.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutSine
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a sinusoidal (sin(t)) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outsine.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutSine
|
|
|
|
\li Easing curve for a sinusoidal (sin(t)) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutsine.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInSine
|
|
|
|
\li Easing curve for a sinusoidal (sin(t)) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinsine.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InExpo
|
|
|
|
\li Easing curve for an exponential (2^t) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inexpo.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutExpo
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for an exponential (2^t) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outexpo.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutExpo
|
|
|
|
\li Easing curve for an exponential (2^t) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutexpo.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInExpo
|
|
|
|
\li Easing curve for an exponential (2^t) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinexpo.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InCirc
|
|
|
|
\li Easing curve for a circular (sqrt(1-t^2)) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-incirc.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutCirc
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a circular (sqrt(1-t^2)) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outcirc.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutCirc
|
|
|
|
\li Easing curve for a circular (sqrt(1-t^2)) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutcirc.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInCirc
|
|
|
|
\li Easing curve for a circular (sqrt(1-t^2)) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outincirc.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InElastic
|
|
|
|
\li Easing curve for an elastic (exponentially decaying sine wave) function: accelerating from zero velocity.
|
2011-04-27 10:05:43 +00:00
|
|
|
\br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-inelastic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutElastic
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for an elastic (exponentially decaying sine wave) function: decelerating to zero velocity.
|
2011-04-27 10:05:43 +00:00
|
|
|
\br The peak amplitude can be set with the \e amplitude parameter, and the period of decay by the \e period parameter.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outelastic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutElastic
|
|
|
|
\li Easing curve for an elastic (exponentially decaying sine wave) function: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutelastic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInElastic
|
|
|
|
\li Easing curve for an elastic (exponentially decaying sine wave) function: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinelastic.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InBack
|
|
|
|
\li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inback.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutBack
|
|
|
|
\li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing out: decelerating to zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-outback.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutBack
|
|
|
|
\li Easing curve for a back (overshooting cubic function: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutback.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInBack
|
|
|
|
\li Easing curve for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinback.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InBounce
|
|
|
|
\li Easing curve for a bounce (exponentially decaying parabolic bounce) function: accelerating from zero velocity.
|
|
|
|
\li \inlineimage qeasingcurve-inbounce.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutBounce
|
2015-10-09 07:50:22 +00:00
|
|
|
\li Easing curve for a bounce (exponentially decaying parabolic bounce) function: decelerating to zero velocity.
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \inlineimage qeasingcurve-outbounce.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.InOutBounce
|
|
|
|
\li Easing curve for a bounce (exponentially decaying parabolic bounce) function easing in/out: acceleration until halfway, then deceleration.
|
|
|
|
\li \inlineimage qeasingcurve-inoutbounce.png
|
2011-04-27 10:05:43 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.OutInBounce
|
|
|
|
\li Easing curve for a bounce (exponentially decaying parabolic bounce) function easing out/in: deceleration until halfway, then acceleration.
|
|
|
|
\li \inlineimage qeasingcurve-outinbounce.png
|
2011-12-08 00:36:44 +00:00
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li \c Easing.Bezier
|
|
|
|
\li Custom easing curve defined by the easing.bezierCurve property.
|
|
|
|
\li
|
2011-04-27 10:05:43 +00:00
|
|
|
\endtable
|
|
|
|
|
|
|
|
\c easing.amplitude is only applicable for bounce and elastic curves (curves of type
|
|
|
|
\c Easing.InBounce, \c Easing.OutBounce, \c Easing.InOutBounce, \c Easing.OutInBounce, \c Easing.InElastic,
|
|
|
|
\c Easing.OutElastic, \c Easing.InOutElastic or \c Easing.OutInElastic).
|
|
|
|
|
|
|
|
\c easing.overshoot is only applicable if \c easing.type is: \c Easing.InBack, \c Easing.OutBack,
|
|
|
|
\c Easing.InOutBack or \c Easing.OutInBack.
|
|
|
|
|
|
|
|
\c easing.period is only applicable if easing.type is: \c Easing.InElastic, \c Easing.OutElastic,
|
|
|
|
\c Easing.InOutElastic or \c Easing.OutInElastic.
|
|
|
|
|
2011-12-08 00:36:44 +00:00
|
|
|
\c easing.bezierCurve is only applicable if easing.type is: \c Easing.Bezier. This property is a list<real> containing
|
|
|
|
groups of three points defining a curve from 0,0 to 1,1 - control1, control2,
|
|
|
|
end point: [cx1, cy1, cx2, cy2, endx, endy, ...]. The last point must be 1,1.
|
|
|
|
|
2014-04-08 11:24:42 +00:00
|
|
|
See the \l {Qt Quick Examples - Animation#Easing Curves}{Easing Curves} for a demonstration of the different easing settings.
|
2013-09-18 18:16:16 +00:00
|
|
|
//! propertyanimation.easing
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QEasingCurve QQuickPropertyAnimation::easing() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
return d->easing;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setEasing(const QEasingCurve &e)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2012-02-03 02:26:37 +00:00
|
|
|
if (d->easing == e)
|
2011-04-27 10:05:43 +00:00
|
|
|
return;
|
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
d->easing = e;
|
2011-04-27 10:05:43 +00:00
|
|
|
emit easingChanged(e);
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QObject *QQuickPropertyAnimation::target() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->target;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setTargetObject(QObject *o)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->target == o)
|
|
|
|
return;
|
|
|
|
d->target = o;
|
|
|
|
emit targetChanged();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QString QQuickPropertyAnimation::property() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->propertyName;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setProperty(const QString &n)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->propertyName == n)
|
|
|
|
return;
|
|
|
|
d->propertyName = n;
|
|
|
|
emit propertyChanged();
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QString QQuickPropertyAnimation::properties() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(const QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
return d->properties;
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickPropertyAnimation::setProperties(const QString &prop)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->properties == prop)
|
|
|
|
return;
|
|
|
|
|
|
|
|
d->properties = prop;
|
|
|
|
emit propertiesChanged(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty string QtQuick::PropertyAnimation::properties
|
|
|
|
\qmlproperty list<Object> QtQuick::PropertyAnimation::targets
|
|
|
|
\qmlproperty string QtQuick::PropertyAnimation::property
|
|
|
|
\qmlproperty Object QtQuick::PropertyAnimation::target
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
These properties are used as a set to determine which properties should be animated.
|
|
|
|
The singular and plural forms are functionally identical, e.g.
|
|
|
|
\qml
|
|
|
|
NumberAnimation { target: theItem; property: "x"; to: 500 }
|
|
|
|
\endqml
|
|
|
|
has the same meaning as
|
|
|
|
\qml
|
|
|
|
NumberAnimation { targets: theItem; properties: "x"; to: 500 }
|
|
|
|
\endqml
|
|
|
|
The singular forms are slightly optimized, so if you do have only a single target/property
|
|
|
|
to animate you should try to use them.
|
|
|
|
|
|
|
|
The \c targets property allows multiple targets to be set. For example, this animates the
|
|
|
|
\c x property of both \c itemA and \c itemB:
|
|
|
|
|
|
|
|
\qml
|
|
|
|
NumberAnimation { targets: [itemA, itemB]; properties: "x"; to: 500 }
|
|
|
|
\endqml
|
|
|
|
|
|
|
|
In many cases these properties do not need to be explicitly specified, as they can be
|
|
|
|
inferred from the animation framework:
|
|
|
|
|
|
|
|
\table 80%
|
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li Value Source / Behavior
|
|
|
|
\li When an animation is used as a value source or in a Behavior, the default target and property
|
2011-04-27 10:05:43 +00:00
|
|
|
name to be animated can both be inferred.
|
|
|
|
\qml
|
|
|
|
Rectangle {
|
|
|
|
id: theRect
|
|
|
|
width: 100; height: 100
|
|
|
|
color: Qt.rgba(0,0,1)
|
|
|
|
NumberAnimation on x { to: 500; loops: Animation.Infinite } //animate theRect's x property
|
|
|
|
Behavior on y { NumberAnimation {} } //animate theRect's y property
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li Transition
|
|
|
|
\li When used in a transition, a property animation is assumed to match \e all targets
|
2011-04-27 10:05:43 +00:00
|
|
|
but \e no properties. In practice, that means you need to specify at least the properties
|
|
|
|
in order for the animation to do anything.
|
|
|
|
\qml
|
|
|
|
Rectangle {
|
|
|
|
id: theRect
|
|
|
|
width: 100; height: 100
|
|
|
|
color: Qt.rgba(0,0,1)
|
|
|
|
Item { id: uselessItem }
|
|
|
|
states: State {
|
|
|
|
name: "state1"
|
|
|
|
PropertyChanges { target: theRect; x: 200; y: 200; z: 4 }
|
|
|
|
PropertyChanges { target: uselessItem; x: 10; y: 10; z: 2 }
|
|
|
|
}
|
|
|
|
transitions: Transition {
|
|
|
|
//animate both theRect's and uselessItem's x and y to their final values
|
|
|
|
NumberAnimation { properties: "x,y" }
|
|
|
|
|
|
|
|
//animate theRect's z to its final value
|
|
|
|
NumberAnimation { target: theRect; property: "z" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
\row
|
2012-03-01 17:05:16 +00:00
|
|
|
\li Standalone
|
|
|
|
\li When an animation is used standalone, both the target and property need to be
|
2011-04-27 10:05:43 +00:00
|
|
|
explicitly specified.
|
|
|
|
\qml
|
|
|
|
Rectangle {
|
|
|
|
id: theRect
|
|
|
|
width: 100; height: 100
|
|
|
|
color: Qt.rgba(0,0,1)
|
|
|
|
//need to explicitly specify target and property
|
|
|
|
NumberAnimation { id: theAnim; target: theRect; property: "x"; to: 500 }
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: theAnim.start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
\endqml
|
|
|
|
\endtable
|
|
|
|
|
|
|
|
As seen in the above example, properties is specified as a comma-separated string of property names to animate.
|
|
|
|
|
2012-08-02 03:06:09 +00:00
|
|
|
\sa exclude, {Animation and Transitions in Qt Quick}
|
2011-04-27 10:05:43 +00:00
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QObject> QQuickPropertyAnimation::targets()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2019-11-25 13:49:07 +00:00
|
|
|
return QQmlListProperty<QObject>(this, &(d->targets));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-10-01 11:03:28 +00:00
|
|
|
\qmlproperty list<Object> QtQuick::PropertyAnimation::exclude
|
2011-04-27 10:05:43 +00:00
|
|
|
This property holds the items not to be affected by this animation.
|
|
|
|
\sa PropertyAnimation::targets
|
|
|
|
*/
|
2012-02-16 04:43:03 +00:00
|
|
|
QQmlListProperty<QObject> QQuickPropertyAnimation::exclude()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2019-11-25 13:49:07 +00:00
|
|
|
return QQmlListProperty<QObject>(this, &(d->exclude));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
void QQuickAnimationPropertyUpdater::setValue(qreal v)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
bool deleted = false;
|
|
|
|
wasDeleted = &deleted;
|
2012-02-03 02:26:37 +00:00
|
|
|
if (reverse)
|
2011-04-27 10:05:43 +00:00
|
|
|
v = 1 - v;
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
if (v == 1.) {
|
2016-07-14 10:09:23 +00:00
|
|
|
QQmlPropertyPrivate::write(action.property, action.toValue, QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
|
2012-02-03 02:26:37 +00:00
|
|
|
} else {
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!fromSourced && !fromDefined) {
|
|
|
|
action.fromValue = action.property.read();
|
2012-02-03 02:26:37 +00:00
|
|
|
if (interpolatorType) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickPropertyAnimationPrivate::convertVariant(action.fromValue, interpolatorType);
|
2012-02-03 02:26:37 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
if (!interpolatorType) {
|
|
|
|
int propType = action.property.propertyType();
|
|
|
|
if (!prevInterpolatorType || prevInterpolatorType != propType) {
|
|
|
|
prevInterpolatorType = propType;
|
|
|
|
interpolator = QVariantAnimationPrivate::getInterpolator(prevInterpolatorType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (interpolator)
|
2016-07-14 10:09:23 +00:00
|
|
|
QQmlPropertyPrivate::write(action.property, interpolator(action.fromValue.constData(), action.toValue.constData(), v), QQmlPropertyData::BypassInterceptor | QQmlPropertyData::DontRemoveBinding);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
if (deleted)
|
|
|
|
return;
|
|
|
|
}
|
2018-02-21 09:41:54 +00:00
|
|
|
wasDeleted = nullptr;
|
2011-04-27 10:05:43 +00:00
|
|
|
fromSourced = true;
|
|
|
|
}
|
|
|
|
|
2014-03-28 16:43:47 +00:00
|
|
|
void QQuickAnimationPropertyUpdater::debugUpdater(QDebug d, int indentLevel) const
|
|
|
|
{
|
|
|
|
QByteArray ind(indentLevel, ' ');
|
|
|
|
for (int i = 0; i < actions.count(); ++i) {
|
|
|
|
const QQuickStateAction &action = actions.at(i);
|
|
|
|
d << "\n" << ind.constData() << "target:" << action.property.object() << "property:" << action.property.name()
|
|
|
|
<< "from:" << action.fromValue << "to:" << action.toValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickStateActions QQuickPropertyAnimation::createTransitionActions(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
QObject *defaultTarget)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
|
|
|
QQuickStateActions newActions;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QStringList props = d->properties.isEmpty() ? QStringList() : d->properties.split(QLatin1Char(','));
|
|
|
|
for (int ii = 0; ii < props.count(); ++ii)
|
|
|
|
props[ii] = props.at(ii).trimmed();
|
|
|
|
if (!d->propertyName.isEmpty())
|
|
|
|
props << d->propertyName;
|
|
|
|
|
|
|
|
QList<QObject*> targets = d->targets;
|
|
|
|
if (d->target)
|
|
|
|
targets.append(d->target);
|
|
|
|
|
|
|
|
bool hasSelectors = !props.isEmpty() || !targets.isEmpty() || !d->exclude.isEmpty();
|
|
|
|
bool useType = (props.isEmpty() && d->defaultToInterpolatorType) ? true : false;
|
|
|
|
|
|
|
|
if (d->defaultProperty.isValid() && !hasSelectors) {
|
|
|
|
props << d->defaultProperty.name();
|
|
|
|
targets << d->defaultProperty.object();
|
|
|
|
}
|
|
|
|
|
2012-02-03 03:18:05 +00:00
|
|
|
if (defaultTarget && targets.isEmpty())
|
|
|
|
targets << defaultTarget;
|
|
|
|
|
2015-12-08 11:50:08 +00:00
|
|
|
bool usingDefaultProperties = false;
|
2011-04-27 10:05:43 +00:00
|
|
|
if (props.isEmpty() && !d->defaultProperties.isEmpty()) {
|
|
|
|
props << d->defaultProperties.split(QLatin1Char(','));
|
2015-12-08 11:50:08 +00:00
|
|
|
usingDefaultProperties = true;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hasExplicit = false;
|
|
|
|
//an explicit animation has been specified
|
|
|
|
if (d->toIsDefined) {
|
2015-12-08 11:50:08 +00:00
|
|
|
QVector<QString> errorMessages;
|
|
|
|
bool successfullyCreatedDefaultProperty = false;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
for (int i = 0; i < props.count(); ++i) {
|
|
|
|
for (int j = 0; j < targets.count(); ++j) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction myAction;
|
2015-12-08 11:50:08 +00:00
|
|
|
QString errorMessage;
|
2019-10-04 12:13:36 +00:00
|
|
|
const QString &propertyName = props.at(i);
|
2015-12-08 11:50:08 +00:00
|
|
|
myAction.property = d->createProperty(targets.at(j), propertyName, this, &errorMessage);
|
2011-04-27 10:05:43 +00:00
|
|
|
if (myAction.property.isValid()) {
|
2015-12-08 11:50:08 +00:00
|
|
|
if (usingDefaultProperties)
|
|
|
|
successfullyCreatedDefaultProperty = true;
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (d->fromIsDefined) {
|
|
|
|
myAction.fromValue = d->from;
|
|
|
|
d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
|
|
|
|
}
|
|
|
|
myAction.toValue = d->to;
|
|
|
|
d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
|
2012-02-03 02:26:37 +00:00
|
|
|
newActions << myAction;
|
2011-04-27 10:05:43 +00:00
|
|
|
hasExplicit = true;
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2011-04-27 10:05:43 +00:00
|
|
|
if (action.property.object() == myAction.property.object() &&
|
|
|
|
myAction.property.name() == action.property.name()) {
|
|
|
|
modified << action.property;
|
|
|
|
break; //### any chance there could be multiples?
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 11:50:08 +00:00
|
|
|
} else {
|
|
|
|
errorMessages.append(errorMessage);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-12-08 11:50:08 +00:00
|
|
|
|
|
|
|
if (!successfullyCreatedDefaultProperty) {
|
2016-08-09 13:41:33 +00:00
|
|
|
for (const QString &errorMessage : qAsConst(errorMessages))
|
2017-01-05 19:27:53 +00:00
|
|
|
qmlWarning(this) << errorMessage;
|
2015-12-08 11:50:08 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasExplicit)
|
|
|
|
for (int ii = 0; ii < actions.count(); ++ii) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction &action = actions[ii];
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
QObject *obj = action.property.object();
|
|
|
|
QString propertyName = action.property.name();
|
|
|
|
QObject *sObj = action.specifiedObject;
|
|
|
|
QString sPropertyName = action.specifiedProperty;
|
|
|
|
bool same = (obj == sObj);
|
|
|
|
|
|
|
|
if ((targets.isEmpty() || targets.contains(obj) || (!same && targets.contains(sObj))) &&
|
|
|
|
(!d->exclude.contains(obj)) && (same || (!d->exclude.contains(sObj))) &&
|
|
|
|
(props.contains(propertyName) || (!same && props.contains(sPropertyName))
|
|
|
|
|| (useType && action.property.propertyType() == d->interpolatorType))) {
|
2013-10-03 15:04:40 +00:00
|
|
|
QQuickStateAction myAction = action;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (d->fromIsDefined)
|
|
|
|
myAction.fromValue = d->from;
|
|
|
|
else
|
|
|
|
myAction.fromValue = QVariant();
|
|
|
|
if (d->toIsDefined)
|
|
|
|
myAction.toValue = d->to;
|
|
|
|
|
|
|
|
d->convertVariant(myAction.fromValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
|
|
|
|
d->convertVariant(myAction.toValue, d->interpolatorType ? d->interpolatorType : myAction.property.propertyType());
|
|
|
|
|
|
|
|
modified << action.property;
|
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
newActions << myAction;
|
2011-04-27 10:05:43 +00:00
|
|
|
action.fromValue = myAction.toValue;
|
|
|
|
}
|
|
|
|
}
|
2012-02-03 02:26:37 +00:00
|
|
|
return newActions;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QAbstractAnimationJob* QQuickPropertyAnimation::transition(QQuickStateActions &actions,
|
|
|
|
QQmlProperties &modified,
|
2012-02-03 03:18:05 +00:00
|
|
|
TransitionDirection direction,
|
|
|
|
QObject *defaultTarget)
|
2012-02-03 02:26:37 +00:00
|
|
|
{
|
2012-02-16 04:43:03 +00:00
|
|
|
Q_D(QQuickPropertyAnimation);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickStateActions dataActions = createTransitionActions(actions, modified, defaultTarget);
|
2012-02-03 02:26:37 +00:00
|
|
|
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickBulkValueAnimator *animator = new QQuickBulkValueAnimator;
|
2012-02-03 02:26:37 +00:00
|
|
|
animator->setDuration(d->duration);
|
|
|
|
animator->setEasingCurve(d->easing);
|
|
|
|
|
|
|
|
if (!dataActions.isEmpty()) {
|
2012-02-16 04:43:03 +00:00
|
|
|
QQuickAnimationPropertyUpdater *data = new QQuickAnimationPropertyUpdater;
|
2012-02-03 02:26:37 +00:00
|
|
|
data->interpolatorType = d->interpolatorType;
|
|
|
|
data->interpolator = d->interpolator;
|
|
|
|
data->reverse = direction == Backward ? true : false;
|
|
|
|
data->fromSourced = false;
|
|
|
|
data->fromDefined = d->fromIsDefined;
|
|
|
|
data->actions = dataActions;
|
|
|
|
animator->setAnimValue(data);
|
|
|
|
animator->setFromSourcedValue(&data->fromSourced);
|
|
|
|
d->actions = &data->actions; //remove this?
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-02-03 02:26:37 +00:00
|
|
|
return initInstance(animator);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2013-04-02 05:45:28 +00:00
|
|
|
QQuickAnimationPropertyUpdater::~QQuickAnimationPropertyUpdater()
|
|
|
|
{
|
|
|
|
if (wasDeleted) *wasDeleted = true;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QT_END_NAMESPACE
|
2017-04-25 21:08:46 +00:00
|
|
|
|
|
|
|
#include "moc_qquickanimation_p.cpp"
|