CopperSpice API  1.9.2
QVariantAnimation Class Referenceabstract

Provides an abstract base class for animations. More...

Inheritance diagram for QVariantAnimation:
QAbstractAnimation QObject QPropertyAnimation

Public Typedefs

using ValuePair = QPair< double, QVariant >
 

Public Signals

void valueChanged (const QVariant &value)
 
- Public Signals inherited from QAbstractAnimation
void currentLoopChanged (int currentLoop)
 
void directionChanged (QAbstractAnimation::Direction newDirection)
 
void finished ()
 
void stateChanged (QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QVariantAnimation (QObject *parent=nullptr)
 
 ~QVariantAnimation ()
 
QVariant currentValue () const
 
int duration () const override
 
QEasingCurve easingCurve () const
 
QVariant endValue () const
 
QVariant keyValueAt (double step) const
 
QVector< QVariantAnimation::ValuePairkeyValues () const
 
void setDuration (int msecs)
 
void setEasingCurve (const QEasingCurve &easing)
 
void setEndValue (const QVariant &value)
 
void setKeyValueAt (double step, const QVariant &value)
 
void setKeyValues (const QVector< QVariantAnimation::ValuePair > &keyValues)
 
void setStartValue (const QVariant &value)
 
QVariant startValue () const
 
- Public Methods inherited from QAbstractAnimation
 QAbstractAnimation (QObject *parent=nullptr)
 
virtual ~QAbstractAnimation ()
 
int currentLoop () const
 
int currentLoopTime () const
 
int currentTime () const
 
Direction direction () const
 
QAnimationGroupgroup () const
 
int loopCount () const
 
void setDirection (Direction direction)
 
void setLoopCount (int loopCount)
 
State state () const
 
int totalDuration () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

bool event (QEvent *event) override
 
virtual QVariant interpolated (const QVariant &from, const QVariant &to, double progress) const
 
void updateCurrentTime (int) override
 
virtual void updateCurrentValue (const QVariant &value) = 0
 
void updateState (QAbstractAnimation::State newState, QAbstractAnimation::State oldState) override
 
- Protected Methods inherited from QAbstractAnimation
virtual void updateDirection (QAbstractAnimation::Direction direction)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 currentValue
 
 duration
 
 easingCurve
 
 endValue
 
 startValue
 
- Properties inherited from QAbstractAnimation
 currentLoop
 
 currentTime
 
 direction
 
 duration
 
 loopCount
 
 state
 
- Properties inherited from QObject
 objectName
 

Related Functions

These are not member functions

void qRegisterAnimationInterpolator (QVariant (*)(const T &from, const T &to, qreal progress) func)
 

Additional Inherited Members

- Public Types inherited from QAbstractAnimation
enum  DeletionPolicy
 
enum  Direction
 
enum  State
 
- Public Slots inherited from QAbstractAnimation
void pause ()
 
void resume ()
 
void setCurrentTime (int msecs)
 
void setPaused (bool paused)
 
void start (QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
 
void stop ()
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Detailed Description

This class is part of the Animation System. It serves as a base class for property and item animations with methods for shared functionality.

QVariantAnimation can not be used directly since it is an abstract class. The class performs interpolation over QVariants, but leaves using the interpolated values to its subclasses. Refer to the QPropertyAnimation class description for more information about animations.

You can then set start and end values for the property by calling setStartValue() and setEndValue(), and finally call start() to start the animation. QVariantAnimation will interpolate the property of the target object and emit valueChanged(). To react to a change in the current value you have to reimplement the updateCurrentValue() virtual function.

It is also possible to set values at specified steps situated between the start and end value. The interpolation will then touch these points at the specified steps. The start and end values are defined as the key values at 0.0 and 1.0.

There are two ways to affect how QVariantAnimation interpolates the values. You can set an easing curve by calling setEasingCurve(), and configure the duration by calling setDuration(). You can change how the QVariants are interpolated by creating a subclass of QVariantAnimation, and reimplementing the virtual interpolated() function.

Subclassing QVariantAnimation can be an alternative if you have QVariants that you do not wish to declare as properties. Note, however, that you in most cases will be better off declaring your QVariant as a property.

Not all of the QVariant types are supported. The list below shows the currently supported QVariant types in the Animation System.

If you need to interpolate other variant types, including custom types, you have to implement interpolation for these yourself. To do this, you can register an interpolator function for a given type. This function takes 3 parameters: the start value, the end value and the current progress.

QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) {
// ...
return QColor(...);
}
qRegisterAnimationInterpolator<QColor>(myColorInterpolator);

Another option is to reimplement interpolated(), which returns interpolation values for the value being interpolated.

See also
QPropertyAnimation, QAbstractAnimation, Animation Technology

Member Typedef Documentation

Constructor & Destructor Documentation

QVariantAnimation::QVariantAnimation ( QObject parent = nullptr)

Construct a QVariantAnimation object. The parent object is passed to the QAbstractAnimation constructor.

QVariantAnimation::~QVariantAnimation ( )

Destroys the animation.

Method Documentation

QVariant QVariantAnimation::currentValue ( ) const

Returns the value of the property currentvalue.

int QVariantAnimation::duration ( ) const
overridevirtual

Returns the value of the Duration property.

Implements QAbstractAnimation::duration()

QEasingCurve QVariantAnimation::easingCurve ( ) const

Returns the value of the easingCurve property.

QVariant QVariantAnimation::endValue ( ) const

Returns the value of the endValue property.

bool QVariantAnimation::event ( QEvent event)
overrideprotectedvirtual

Reimplemented from QAbstractAnimation::event()

QVariant QVariantAnimation::interpolated ( const QVariant from,
const QVariant to,
double  progress 
) const
protectedvirtual

This virtual function returns the linear interpolation between variants from and to, at progress, usually a value between 0 and 1. You can reimplement this function in a subclass of QVariantAnimation to provide your own interpolation algorithm.

In order for the interpolation to work with a QEasingCurve that return a value smaller than 0 or larger than 1 (such as QEasingCurve::InBack) you should make sure that it can extrapolate. If the semantic of the datatype does not allow extrapolation this function should handle that gracefully.

You should call the QVariantAnimation implementation of this function if you want your class to handle the types already supported by CopperSpice (see class QVariantAnimation description for a list of supported types).

See also
QEasingCurve
QVariant QVariantAnimation::keyValueAt ( double  step) const

Returns the key frame value for the given step. The given step must be in the range 0 to 1. If there is no KeyValue for step it returns an invalid QVariant.

See also
keyValues(), setKeyValueAt()
QVector< QVariantAnimation::ValuePair > QVariantAnimation::keyValues ( ) const

Returns the key frames of this animation.

See also
keyValueAt(), setKeyValues()
void QVariantAnimation::setDuration ( int  msecs)

Sets the value of the property to msecs.

void QVariantAnimation::setEasingCurve ( const QEasingCurve easing)

Sets the value of the property to easing.

void QVariantAnimation::setEndValue ( const QVariant value)

Sets the value of the property to value.

void QVariantAnimation::setKeyValueAt ( double  step,
const QVariant value 
)

Creates a key frame at the given step with the given value. The given step must be in the range 0 to 1.

See also
setKeyValues(), keyValueAt()
void QVariantAnimation::setKeyValues ( const QVector< QVariantAnimation::ValuePair > &  keyValues)

Replaces the current set of key frames with the given keyValues. the step of the key frames must be in the range 0 to 1.

See also
keyValues(), keyValueAt()
void QVariantAnimation::setStartValue ( const QVariant value)

Sets the value of the property to value.

QVariant QVariantAnimation::startValue ( ) const

Returns the value of the startValue property.

void QVariantAnimation::updateCurrentTime ( int  )
overrideprotectedvirtual
void QVariantAnimation::updateCurrentValue ( const QVariant value)
protectedpure virtual

This method is called every time the animation's current value changes. The value argument is the new current value.

See also
currentValue

Implemented in QPropertyAnimation::updateCurrentValue()

void QVariantAnimation::updateState ( QAbstractAnimation::State  newState,
QAbstractAnimation::State  oldState 
)
overrideprotectedvirtual
void QVariantAnimation::valueChanged ( const QVariant value)
signal

QVariantAnimation emits this signal whenever the current value changes.

See also
currentValue, startValue, endValue

Friends And Related Function Documentation

void qRegisterAnimationInterpolator ( QVariant (*)(const T &from, const T &to, qreal progress)  func)
related

Registers a custom interpolator func for the template type T. The interpolator has to be registered before the animation is constructed. To unregister (and use the default interpolator) set func to 0.

This method is thread-safe.

Property Documentation

QVariantAnimation::currentValue

This property holds the current value of the animation. The current value is an interpolated value starting at the start value and proceeding towards the end value. The value itself is obtained from interpolated(), which is called repeatedly as the animation is running.

QVariantAnimation calls updateCurrentValue() when the current value changes. This is particularly useful for subclasses that need to track updates. For example, QPropertyAnimation uses this function to animate CopperSpice properties.

See also
startValue, endValue
PropertiesClass Methods
read currentValue
notify valueChanged
QVariantAnimation::duration

This property holds the duration of the animation and describes the duration in milliseconds of the animation. The default duration is 250 milliseconds.

See also
QAbstractAnimation::duration()
PropertiesClass Methods
read duration
write setDuration
QVariantAnimation::easingCurve

This property holds the easing curve of the animation. By default, a linear easing curve is used, resulting in linear interpolation. Other curves are provided, for instance, QEasingCurve::InCirc, which provides a circular entry curve. Another example is QEasingCurve::InOutElastic, which provides an elastic effect on the values of the interpolated variant.

QVariantAnimation will use the QEasingCurve::valueForProgress() to transform the "normalized progress" (currentTime / totalDuration) of the animation into the effective progress actually used by the animation. It is this effective progress that will be the progress when interpolated() is called. Also, the steps in the keyValues are referring to this effective progress.

The easing curve is used with the interpolator, the interpolated() virtual function, the animation's duration, and iterationCount, to control how the current value changes as the animation progresses.

PropertiesClass Methods
read easingCurve
write setEasingCurve
QVariantAnimation::endValue

This property holds the end value of the animation.

See also
startValue
PropertiesClass Methods
read endValue
write setEndValue
QVariantAnimation::startValue

This property holds the optional start value of the animation. If omitted, or if a null QVariant is assigned as the start value, the animation will use the current position of the end when the animation is started.

See also
endValue
PropertiesClass Methods
read startValue
write setStartValue