Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickanimator.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <private/qquickitem_p.h>
8
10
53
58
68{
69 Q_D(QQuickAnimator);
70 if (target == d->target)
71 return;
72 d->target = target;
73 Q_EMIT targetItemChanged(d->target);
74}
75
77{
78 Q_D(const QQuickAnimator);
79 return d->target;
80}
81
89{
90 Q_D(QQuickAnimator);
91 if (duration == d->duration)
92 return;
93 d->duration = duration;
95}
96
98{
99 Q_D(const QQuickAnimator);
100 return d->duration;
101}
102
114{
115 Q_D(QQuickAnimator);
116 if (easing == d->easing)
117 return;
118 d->easing = easing;
119 Q_EMIT easingChanged(d->easing);
120}
121
123{
124 Q_D(const QQuickAnimator);
125 return d->easing;
126}
127
139{
140 Q_D(QQuickAnimator);
141 if (to == d->to)
142 return;
143 d->toIsDefined = true;
144 d->to = to;
145 Q_EMIT toChanged(d->to);
146}
147
149{
150 Q_D(const QQuickAnimator);
151 return d->to;
152}
153
167{
168 Q_D(QQuickAnimator);
169 d->fromIsDefined = true;
170 if (from == d->from)
171 return;
172 d->from = from;
173 Q_EMIT fromChanged(d->from);
174}
175
177{
178 Q_D(const QQuickAnimator);
179 return d->from;
180}
181
183 const QString &propertyName,
184 QQuickStateActions &actions,
185 QQmlProperties &modified,
186 QObject *defaultTarget)
187{
188
189 if (actions.size()) {
190 for (int i=0; i<actions.size(); ++i) {
191 QQuickStateAction &action = actions[i];
192 if (action.property.name() != propertyName)
193 continue;
194 modified << action.property;
195
196 job->setTarget(qobject_cast<QQuickItem *>(action.property.object()));
197
198 if (fromIsDefined)
199 job->setFrom(from);
200 else if (action.fromValue.isValid())
201 job->setFrom(action.fromValue.toReal());
202 else
203 job->setFrom(action.property.read().toReal());
204
205 if (toIsDefined)
206 job->setTo(to);
207 else if (action.toValue.isValid())
208 job->setTo(action.toValue.toReal());
209 else
210 job->setTo(action.property.read().toReal());
211
212 // This magic line is in sync with what PropertyAnimation does
213 // and prevents the animation to end up in the "completeList"
214 // which forces action.toValue to be written directly to
215 // the item when a transition is cancelled.
216 action.fromValue = action.toValue;
217 }
218 }
219
220 if (modified.isEmpty()) {
221 job->setTarget(target);
222 if (fromIsDefined)
223 job->setFrom(from);
224 job->setTo(to);
225 }
226
227 if (!job->target()) {
229 job->setTarget(qobject_cast<QQuickItem *>(defaultProperty.object()));
230 else
231 job->setTarget(qobject_cast<QQuickItem *>(defaultTarget));
232 }
233
234 if (modified.isEmpty() && !fromIsDefined && job->target())
235 job->setFrom(job->target()->property(propertyName.toLatin1()).toReal());
236
237 job->setDuration(duration);
240}
241
243 QQmlProperties &modified,
245 QObject *defaultTarget)
246{
247 Q_D(QQuickAnimator);
248
249 if (d->defaultProperty.isValid() && propertyName() != d->defaultProperty.name()) {
250 qmlWarning(this) << "property name conflict: \""
251 << propertyName() << "\" != \"" << d->defaultProperty.name() << "\"";
252 return nullptr;
253 }
254
255 // The animation system cannot handle backwards uncontrolled animations.
256 if (direction == Backward)
257 return nullptr;
258
260 if (!job)
261 return nullptr;
262
263 d->apply(job, propertyName(), actions, modified, defaultTarget);
264
265 if (!job->target()) {
266 delete job;
267 return nullptr;
268 }
269
270 return job;
271}
272
303
305
336
338
369
371
401
403
438
440 Q_D(const QQuickRotationAnimator);
442 job->setDirection(d->direction);
443 return job;
444}
445
464{
466 if (d->direction == dir)
467 return;
468 d->direction = dir;
469 Q_EMIT directionChanged(d->direction);
470}
471
477
478#if QT_CONFIG(quick_shadereffect)
510QQuickUniformAnimator::QQuickUniformAnimator(QObject *parent)
511 : QQuickAnimator(*new QQuickUniformAnimatorPrivate, parent)
512{
513}
514
523void QQuickUniformAnimator::setUniform(const QString &uniform)
524{
525 Q_D(QQuickUniformAnimator);
526 if (d->uniform == uniform)
527 return;
528 d->uniform = uniform;
529 Q_EMIT uniformChanged(d->uniform);
530}
531
532QString QQuickUniformAnimator::uniform() const
533{
534 Q_D(const QQuickUniformAnimator);
535 return d->uniform;
536}
537
538QString QQuickUniformAnimator::propertyName() const
539{
540 Q_D(const QQuickUniformAnimator);
541 if (!d->uniform.isEmpty())
542 return d->uniform;
543 return d->defaultProperty.name();
544}
545
546QQuickAnimatorJob *QQuickUniformAnimator::createJob() const
547{
548 QString u = propertyName();
549 if (u.isEmpty())
550 return nullptr;
551
552 QQuickUniformAnimatorJob *job = new QQuickUniformAnimatorJob();
553 job->setUniform(u.toLatin1());
554 return job;
555}
556#endif
557
559
560#include "moc_qquickanimator_p.cpp"
void setLoopCount(int loopCount)
\inmodule QtCore
qsizetype size() const noexcept
Definition qlist.h:397
bool isEmpty() const noexcept
Definition qlist.h:401
\inmodule QtCore
Definition qobject.h:103
QVariant property(const char *name) const
Returns the value of the object's name property.
Definition qobject.cpp:4323
QVariant read() const
Returns the property value.
QML_ANONYMOUSQObject * object
QQuickItem * target() const
void setFrom(qreal from)
void setDuration(int duration)
virtual void setTarget(QQuickItem *target)
void setEasingCurve(const QEasingCurve &curve)
void apply(QQuickAnimatorJob *job, const QString &propertyName, QQuickStateActions &actions, QQmlProperties &modified, QObject *defaultTarget)
void setTo(qreal to)
\qmlproperty real QtQuick::Animator::to This property holds the end value for the animation.
void toChanged(qreal to)
virtual QString propertyName() const =0
void setFrom(qreal from)
\qmlproperty real QtQuick::Animator::from This property holds the starting value for the animation.
QAbstractAnimationJob * transition(QQuickStateActions &actions, QQmlProperties &modified, TransitionDirection, QObject *) override
void easingChanged(const QEasingCurve &curve)
void setDuration(int duration)
\qmlproperty int QtQuick::Animator::duration This property holds the duration of the animation in mil...
QQuickAnimator(QQuickAnimatorPrivate &dd, QObject *parent=nullptr)
\qmltype Animator \instantiates QQuickAnimator \inqmlmodule QtQuick
void setTargetItem(QQuickItem *target)
\qmlproperty QtQuick::Item QtQuick::Animator::target
QEasingCurve easing
void setEasing(const QEasingCurve &easing)
\qmlpropertygroup QtQuick::Animator::easing \qmlproperty enumeration QtQuick::Animator::easing....
void targetItemChanged(QQuickItem *)
void fromChanged(qreal from)
virtual QQuickAnimatorJob * createJob() const =0
QQuickItem * target
QQuickItem * targetItem() const
void durationChanged(int duration)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickOpacityAnimator(QObject *parent=nullptr)
\qmltype OpacityAnimator \instantiates QQuickOpacityAnimator \inqmlmodule QtQuick
QQuickAnimatorJob * createJob() const override
void setDirection(QQuickRotationAnimator::RotationDirection direction)
void setDirection(RotationDirection dir)
\qmlproperty enumeration QtQuick::RotationAnimator::direction This property holds the direction of th...
QQuickAnimatorJob * createJob() const override
void directionChanged(RotationDirection dir)
RotationDirection direction
QQuickRotationAnimator(QObject *parent=nullptr)
\qmltype RotationAnimator \instantiates QQuickRotationAnimator \inqmlmodule QtQuick
QQuickAnimatorJob * createJob() const override
QQuickScaleAnimator(QObject *parent=nullptr)
\qmltype ScaleAnimator \instantiates QQuickScaleAnimator \inqmlmodule QtQuick
QQmlProperty property
QQuickAnimatorJob * createJob() const override
QQuickXAnimator(QObject *parent=nullptr)
\qmltype XAnimator \instantiates QQuickXAnimator \inqmlmodule QtQuick
QQuickYAnimator(QObject *parent=nullptr)
\qmltype YAnimator \instantiates QQuickYAnimator \inqmlmodule QtQuick
QQuickAnimatorJob * createJob() const override
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QByteArray toLatin1() const &
Definition qstring.h:630
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
qreal toReal(bool *ok=nullptr) const
Returns the variant as a qreal if the variant has userType() \l QMetaType::Double,...
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
Definition qvariant.h:714
direction
Combined button and popup list for selecting options.
GLenum target
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define Q_EMIT
double qreal
Definition qtypes.h:187
QEasingCurve easing(QEasingCurve::InOutQuad)
[typedef]
QString dir
[11]