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
4/*!
5 \class QPauseAnimation
6 \inmodule QtCore
7 \brief The QPauseAnimation class provides a pause for QSequentialAnimationGroup.
8 \since 4.6
9 \ingroup animation
10
11 If you wish to introduce a delay between animations in a
12 QSequentialAnimationGroup, you can insert a QPauseAnimation. This
13 class does not animate anything, but does not
14 \l{QAbstractAnimation::finished()}{finish} before a specified
15 number of milliseconds have elapsed from when it was started. You
16 specify the duration of the pause in the constructor. It can also
17 be set directly with setDuration().
18
19 It is not necessary to construct a QPauseAnimation yourself.
20 QSequentialAnimationGroup provides the convenience functions
21 \l{QSequentialAnimationGroup::}{addPause()} and
22 \l{QSequentialAnimationGroup::}{insertPause()}. These functions
23 simply take the number of milliseconds the pause should last.
24
25 \sa QSequentialAnimationGroup
26*/
27
28#include "qpauseanimation.h"
29#include "qabstractanimation_p.h"
30#include "private/qproperty_p.h"
31
32QT_BEGIN_NAMESPACE
33
34class QPauseAnimationPrivate : public QAbstractAnimationPrivate
35{
36 Q_DECLARE_PUBLIC(QPauseAnimation)
37public:
38 QPauseAnimationPrivate() : QAbstractAnimationPrivate(), duration(250)
39 {
40 isPause = true;
41 }
42
43 void setDuration(int msecs) { q_func()->setDuration(msecs); }
44 Q_OBJECT_COMPAT_PROPERTY(QPauseAnimationPrivate, int, duration,
45 &QPauseAnimationPrivate::setDuration)
46};
47
48/*!
49 Constructs a QPauseAnimation.
50 \a parent is passed to QObject's constructor.
51 The default duration is 0.
52*/
53
54QPauseAnimation::QPauseAnimation(QObject *parent) : QAbstractAnimation(*new QPauseAnimationPrivate, parent)
55{
56}
57
58/*!
59 Constructs a QPauseAnimation.
60 \a msecs is the duration of the pause.
61 \a parent is passed to QObject's constructor.
62*/
63
64QPauseAnimation::QPauseAnimation(int msecs, QObject *parent) : QAbstractAnimation(*new QPauseAnimationPrivate, parent)
65{
66 setDuration(msecs);
67}
68
69/*!
70 Destroys the pause animation.
71*/
72QPauseAnimation::~QPauseAnimation()
73{
74}
75
76/*!
77 \property QPauseAnimation::duration
78 \brief the duration of the pause.
79
80 The duration of the pause. The duration should not be negative.
81 The default duration is 250 milliseconds.
82*/
83int QPauseAnimation::duration() const
84{
85 Q_D(const QPauseAnimation);
86 return d->duration;
87}
88
89void QPauseAnimation::setDuration(int msecs)
90{
91 if (msecs < 0) {
92 qWarning(msg: "QPauseAnimation::setDuration: cannot set a negative duration");
93 return;
94 }
95 Q_D(QPauseAnimation);
96
97 d->duration.removeBindingUnlessInWrapper();
98 if (msecs != d->duration.valueBypassingBindings()) {
99 d->duration.setValueBypassingBindings(msecs);
100 d->duration.notify();
101 }
102}
103
104QBindable<int> QPauseAnimation::bindableDuration()
105{
106 Q_D(QPauseAnimation);
107 return &d->duration;
108}
109
110/*!
111 \reimp
112 */
113bool QPauseAnimation::event(QEvent *e)
114{
115 return QAbstractAnimation::event(event: e);
116}
117
118/*!
119 \reimp
120 */
121void QPauseAnimation::updateCurrentTime(int)
122{
123}
124
125
126QT_END_NAMESPACE
127
128#include "moc_qpauseanimation.cpp"
129

source code of qtbase/src/corelib/animation/qpauseanimation.cpp