| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/animation/qvariantanimation.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qvariantanimation.h" | - | ||||||||||||||||||
| 41 | #include "qvariantanimation_p.h" | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | #include <QtCore/qrect.h> | - | ||||||||||||||||||
| 44 | #include <QtCore/qline.h> | - | ||||||||||||||||||
| 45 | #include <QtCore/qmutex.h> | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | #include <algorithm> | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | #ifndef QT_NO_ANIMATION | - | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | /*! | - | ||||||||||||||||||
| 54 | \class QVariantAnimation | - | ||||||||||||||||||
| 55 | \inmodule QtCore | - | ||||||||||||||||||
| 56 | \ingroup animation | - | ||||||||||||||||||
| 57 | \brief The QVariantAnimation class provides a base class for animations. | - | ||||||||||||||||||
| 58 | \since 4.6 | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | This class is part of \l{The Animation Framework}. It serves as a | - | ||||||||||||||||||
| 61 | base class for property and item animations, with functions for | - | ||||||||||||||||||
| 62 | shared functionality. | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | The class performs interpolation over | - | ||||||||||||||||||
| 65 | \l{QVariant}s, but leaves using the interpolated values to its | - | ||||||||||||||||||
| 66 | subclasses. Currently, Qt provides QPropertyAnimation, which | - | ||||||||||||||||||
| 67 | animates Qt \l{Qt's Property System}{properties}. See the | - | ||||||||||||||||||
| 68 | QPropertyAnimation class description if you wish to animate such | - | ||||||||||||||||||
| 69 | properties. | - | ||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | You can then set start and end values for the property by calling | - | ||||||||||||||||||
| 72 | setStartValue() and setEndValue(), and finally call start() to | - | ||||||||||||||||||
| 73 | start the animation. QVariantAnimation will interpolate the | - | ||||||||||||||||||
| 74 | property of the target object and emit valueChanged(). To react to | - | ||||||||||||||||||
| 75 | a change in the current value you have to reimplement the | - | ||||||||||||||||||
| 76 | updateCurrentValue() virtual function or connect to said signal. | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | It is also possible to set values at specified steps situated | - | ||||||||||||||||||
| 79 | between the start and end value. The interpolation will then | - | ||||||||||||||||||
| 80 | touch these points at the specified steps. Note that the start and | - | ||||||||||||||||||
| 81 | end values are defined as the key values at 0.0 and 1.0. | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | There are two ways to affect how QVariantAnimation interpolates | - | ||||||||||||||||||
| 84 | the values. You can set an easing curve by calling | - | ||||||||||||||||||
| 85 | setEasingCurve(), and configure the duration by calling | - | ||||||||||||||||||
| 86 | setDuration(). You can change how the \l{QVariant}s are interpolated | - | ||||||||||||||||||
| 87 | by creating a subclass of QVariantAnimation, and reimplementing | - | ||||||||||||||||||
| 88 | the virtual interpolated() function. | - | ||||||||||||||||||
| 89 | - | |||||||||||||||||||
| 90 | Subclassing QVariantAnimation can be an alternative if you have | - | ||||||||||||||||||
| 91 | \l{QVariant}s that you do not wish to declare as Qt properties. | - | ||||||||||||||||||
| 92 | Note, however, that you in most cases will be better off declaring | - | ||||||||||||||||||
| 93 | your QVariant as a property. | - | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | Not all QVariant types are supported. Below is a list of currently | - | ||||||||||||||||||
| 96 | supported QVariant types: | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | \list | - | ||||||||||||||||||
| 99 | \li \l{QMetaType::}{Int} | - | ||||||||||||||||||
| 100 | \li \l{QMetaType::}{UInt} | - | ||||||||||||||||||
| 101 | \li \l{QMetaType::}{Double} | - | ||||||||||||||||||
| 102 | \li \l{QMetaType::}{Float} | - | ||||||||||||||||||
| 103 | \li \l{QMetaType::}{QLine} | - | ||||||||||||||||||
| 104 | \li \l{QMetaType::}{QLineF} | - | ||||||||||||||||||
| 105 | \li \l{QMetaType::}{QPoint} | - | ||||||||||||||||||
| 106 | \li \l{QMetaType::}{QPointF} | - | ||||||||||||||||||
| 107 | \li \l{QMetaType::}{QSize} | - | ||||||||||||||||||
| 108 | \li \l{QMetaType::}{QSizeF} | - | ||||||||||||||||||
| 109 | \li \l{QMetaType::}{QRect} | - | ||||||||||||||||||
| 110 | \li \l{QMetaType::}{QRectF} | - | ||||||||||||||||||
| 111 | \li \l{QMetaType::}{QColor} | - | ||||||||||||||||||
| 112 | \endlist | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | If you need to interpolate other variant types, including custom | - | ||||||||||||||||||
| 115 | types, you have to implement interpolation for these yourself. | - | ||||||||||||||||||
| 116 | To do this, you can register an interpolator function for a given | - | ||||||||||||||||||
| 117 | type. This function takes 3 parameters: the start value, the end value, | - | ||||||||||||||||||
| 118 | and the current progress. | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | Example: | - | ||||||||||||||||||
| 121 | \code | - | ||||||||||||||||||
| 122 | QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress) | - | ||||||||||||||||||
| 123 | { | - | ||||||||||||||||||
| 124 | ... | - | ||||||||||||||||||
| 125 | return QColor(...); | - | ||||||||||||||||||
| 126 | } | - | ||||||||||||||||||
| 127 | ... | - | ||||||||||||||||||
| 128 | qRegisterAnimationInterpolator<QColor>(myColorInterpolator); | - | ||||||||||||||||||
| 129 | \endcode | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | Another option is to reimplement interpolated(), which returns | - | ||||||||||||||||||
| 132 | interpolation values for the value being interpolated. | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | \omit We need some snippets around here. \endomit | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | \sa QPropertyAnimation, QAbstractAnimation, {The Animation Framework} | - | ||||||||||||||||||
| 137 | */ | - | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | /*! | - | ||||||||||||||||||
| 140 | \fn void QVariantAnimation::valueChanged(const QVariant &value) | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | QVariantAnimation emits this signal whenever the current \a value changes. | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | \sa currentValue, startValue, endValue | - | ||||||||||||||||||
| 145 | */ | - | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | /*! | - | ||||||||||||||||||
| 148 | This virtual function is called every time the animation's current | - | ||||||||||||||||||
| 149 | value changes. The \a value argument is the new current value. | - | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | The base class implementation does nothing. | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | \sa currentValue | - | ||||||||||||||||||
| 154 | */ | - | ||||||||||||||||||
| 155 | void QVariantAnimation::updateCurrentValue(const QVariant &) {} | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | static bool animationValueLessThan(const QVariantAnimation::KeyValue &p1, const QVariantAnimation::KeyValue &p2) | - | ||||||||||||||||||
| 158 | { | - | ||||||||||||||||||
| 159 | return p1.first < p2.first; executed 6706 times by 26 tests: return p1.first < p2.first;Executed by:
| 6706 | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | static QVariant defaultInterpolator(const void *, const void *, qreal) | - | ||||||||||||||||||
| 163 | { | - | ||||||||||||||||||
| 164 | return QVariant(); executed 2 times by 1 test: return QVariant();Executed by:
| 2 | ||||||||||||||||||
| 165 | } | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | template<> Q_INLINE_TEMPLATE QRect _q_interpolate(const QRect &f, const QRect &t, qreal progress) | - | ||||||||||||||||||
| 168 | { | - | ||||||||||||||||||
| 169 | QRect ret; | - | ||||||||||||||||||
| 170 | ret.setCoords(_q_interpolate(f.left(), t.left(), progress), | - | ||||||||||||||||||
| 171 | _q_interpolate(f.top(), t.top(), progress), | - | ||||||||||||||||||
| 172 | _q_interpolate(f.right(), t.right(), progress), | - | ||||||||||||||||||
| 173 | _q_interpolate(f.bottom(), t.bottom(), progress)); | - | ||||||||||||||||||
| 174 | return ret; executed 1846 times by 15 tests: return ret;Executed by:
| 1846 | ||||||||||||||||||
| 175 | } | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | template<> Q_INLINE_TEMPLATE QRectF _q_interpolate(const QRectF &f, const QRectF &t, qreal progress) | - | ||||||||||||||||||
| 178 | { | - | ||||||||||||||||||
| 179 | qreal x1, y1, w1, h1; | - | ||||||||||||||||||
| 180 | f.getRect(&x1, &y1, &w1, &h1); | - | ||||||||||||||||||
| 181 | qreal x2, y2, w2, h2; | - | ||||||||||||||||||
| 182 | t.getRect(&x2, &y2, &w2, &h2); | - | ||||||||||||||||||
| 183 | return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), never executed: return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress)); | 0 | ||||||||||||||||||
| 184 | _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress)); never executed: return QRectF(_q_interpolate(x1, x2, progress), _q_interpolate(y1, y2, progress), _q_interpolate(w1, w2, progress), _q_interpolate(h1, h2, progress)); | 0 | ||||||||||||||||||
| 185 | } | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); never executed: return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); | 0 | ||||||||||||||||||
| 190 | } | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | template<> Q_INLINE_TEMPLATE QLineF _q_interpolate(const QLineF &f, const QLineF &t, qreal progress) | - | ||||||||||||||||||
| 193 | { | - | ||||||||||||||||||
| 194 | return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); never executed: return QLineF( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); | 0 | ||||||||||||||||||
| 195 | } | - | ||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 | QVariantAnimationPrivate::QVariantAnimationPrivate() : duration(250), interpolator(&defaultInterpolator) | - | ||||||||||||||||||
| 198 | { executed 1979 times by 42 tests: }end of blockExecuted by:
executed 1979 times by 42 tests: end of blockExecuted by:
| 1979 | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | void QVariantAnimationPrivate::convertValues(int t) | - | ||||||||||||||||||
| 201 | { | - | ||||||||||||||||||
| 202 | //this ensures that all the keyValues are of type t | - | ||||||||||||||||||
| 203 | for (int i = 0; i < keyValues.count(); ++i) {
| 1109-2110 | ||||||||||||||||||
| 204 | QVariantAnimation::KeyValue &pair = keyValues[i]; | - | ||||||||||||||||||
| 205 | pair.second.convert(t); | - | ||||||||||||||||||
| 206 | } executed 1109 times by 23 tests: end of blockExecuted by:
| 1109 | ||||||||||||||||||
| 207 | //we also need update to the current interval if needed | - | ||||||||||||||||||
| 208 | currentInterval.start.second.convert(t); | - | ||||||||||||||||||
| 209 | currentInterval.end.second.convert(t); | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | //... and the interpolator | - | ||||||||||||||||||
| 212 | updateInterpolator(); | - | ||||||||||||||||||
| 213 | } executed 2110 times by 23 tests: end of blockExecuted by:
| 2110 | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | void QVariantAnimationPrivate::updateInterpolator() | - | ||||||||||||||||||
| 216 | { | - | ||||||||||||||||||
| 217 | int type = currentInterval.start.second.userType(); | - | ||||||||||||||||||
| 218 | if (type == currentInterval.end.second.userType())
| 2-3452 | ||||||||||||||||||
| 219 | interpolator = getInterpolator(type); executed 3452 times by 26 tests: interpolator = getInterpolator(type);Executed by:
| 3452 | ||||||||||||||||||
| 220 | else | - | ||||||||||||||||||
| 221 | interpolator = 0; executed 2 times by 1 test: interpolator = 0;Executed by:
| 2 | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | //we make sure that the interpolator is always set to something | - | ||||||||||||||||||
| 224 | if (!interpolator)
| 1457-1997 | ||||||||||||||||||
| 225 | interpolator = &defaultInterpolator; executed 1997 times by 23 tests: interpolator = &defaultInterpolator;Executed by:
| 1997 | ||||||||||||||||||
| 226 | } executed 3454 times by 26 tests: end of blockExecuted by:
| 3454 | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | /*! | - | ||||||||||||||||||
| 229 | \internal | - | ||||||||||||||||||
| 230 | The goal of this function is to update the currentInterval member. As a consequence, we also | - | ||||||||||||||||||
| 231 | need to update the currentValue. | - | ||||||||||||||||||
| 232 | Set \a force to true to always recalculate the interval. | - | ||||||||||||||||||
| 233 | */ | - | ||||||||||||||||||
| 234 | void QVariantAnimationPrivate::recalculateCurrentInterval(bool force/*=false*/) | - | ||||||||||||||||||
| 235 | { | - | ||||||||||||||||||
| 236 | // can't interpolate if we don't have at least 2 values | - | ||||||||||||||||||
| 237 | if ((keyValues.count() + (defaultStartEndValue.isValid() ? 1 : 0)) < 2)
| 3920-5163 | ||||||||||||||||||
| 238 | return; executed 3920 times by 42 tests: return;Executed by:
| 3920 | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | const qreal endProgress = (direction == QAbstractAnimation::Forward) ? qreal(1) : qreal(0);
| 264-4899 | ||||||||||||||||||
| 241 | const qreal progress = easing.valueForProgress(((duration == 0) ? endProgress : qreal(currentTime) / qreal(duration))); | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | //0 and 1 are still the boundaries | - | ||||||||||||||||||
| 244 | if (force || (currentInterval.start.first > 0 && progress < currentInterval.start.first)
| 0-3819 | ||||||||||||||||||
| 245 | || (currentInterval.end.first < 1 && progress > currentInterval.end.first)) {
| 0-3819 | ||||||||||||||||||
| 246 | //let's update currentInterval | - | ||||||||||||||||||
| 247 | QVariantAnimation::KeyValues::const_iterator it = std::lower_bound(keyValues.constBegin(), | - | ||||||||||||||||||
| 248 | keyValues.constEnd(), | - | ||||||||||||||||||
| 249 | qMakePair(progress, QVariant()), | - | ||||||||||||||||||
| 250 | animationValueLessThan); | - | ||||||||||||||||||
| 251 | if (it == keyValues.constBegin()) {
| 19-1325 | ||||||||||||||||||
| 252 | //the item pointed to by it is the start element in the range | - | ||||||||||||||||||
| 253 | if (it->first == 0 && keyValues.count() > 1) {
| 1-1086 | ||||||||||||||||||
| 254 | currentInterval.start = *it; | - | ||||||||||||||||||
| 255 | currentInterval.end = *(it+1); | - | ||||||||||||||||||
| 256 | } else { executed 238 times by 5 tests: end of blockExecuted by:
| 238 | ||||||||||||||||||
| 257 | currentInterval.start = qMakePair(qreal(0), defaultStartEndValue); | - | ||||||||||||||||||
| 258 | currentInterval.end = *it; | - | ||||||||||||||||||
| 259 | } executed 1087 times by 23 tests: end of blockExecuted by:
| 1087 | ||||||||||||||||||
| 260 | } else if (it == keyValues.constEnd()) {
| 2-17 | ||||||||||||||||||
| 261 | --it; //position the iterator on the last item | - | ||||||||||||||||||
| 262 | if (it->first == 1 && keyValues.count() > 1) {
| 0-2 | ||||||||||||||||||
| 263 | //we have an end value (item with progress = 1) | - | ||||||||||||||||||
| 264 | currentInterval.start = *(it-1); | - | ||||||||||||||||||
| 265 | currentInterval.end = *it; | - | ||||||||||||||||||
| 266 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 267 | //we use the default end value here | - | ||||||||||||||||||
| 268 | currentInterval.start = *it; | - | ||||||||||||||||||
| 269 | currentInterval.end = qMakePair(qreal(1), defaultStartEndValue); | - | ||||||||||||||||||
| 270 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 271 | } else { | - | ||||||||||||||||||
| 272 | currentInterval.start = *(it-1); | - | ||||||||||||||||||
| 273 | currentInterval.end = *it; | - | ||||||||||||||||||
| 274 | } executed 17 times by 2 tests: end of blockExecuted by:
| 17 | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | // update all the values of the currentInterval | - | ||||||||||||||||||
| 277 | updateInterpolator(); | - | ||||||||||||||||||
| 278 | } executed 1344 times by 26 tests: end of blockExecuted by:
| 1344 | ||||||||||||||||||
| 279 | setCurrentValueForProgress(progress); | - | ||||||||||||||||||
| 280 | } executed 5163 times by 26 tests: end of blockExecuted by:
| 5163 | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | void QVariantAnimationPrivate::setCurrentValueForProgress(const qreal progress) | - | ||||||||||||||||||
| 283 | { | - | ||||||||||||||||||
| 284 | Q_Q(QVariantAnimation); | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | const qreal startProgress = currentInterval.start.first; | - | ||||||||||||||||||
| 287 | const qreal endProgress = currentInterval.end.first; | - | ||||||||||||||||||
| 288 | const qreal localProgress = (progress - startProgress) / (endProgress - startProgress); | - | ||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | QVariant ret = q->interpolated(currentInterval.start.second, | - | ||||||||||||||||||
| 291 | currentInterval.end.second, | - | ||||||||||||||||||
| 292 | localProgress); | - | ||||||||||||||||||
| 293 | qSwap(currentValue, ret); | - | ||||||||||||||||||
| 294 | q->updateCurrentValue(currentValue); | - | ||||||||||||||||||
| 295 | static QBasicAtomicInt changedSignalIndex = Q_BASIC_ATOMIC_INITIALIZER(0); | - | ||||||||||||||||||
| 296 | if (!changedSignalIndex.load()) {
| 26-5137 | ||||||||||||||||||
| 297 | //we keep the mask so that we emit valueChanged only when needed (for performance reasons) | - | ||||||||||||||||||
| 298 | changedSignalIndex.testAndSetRelaxed(0, signalIndex("valueChanged(QVariant)")); | - | ||||||||||||||||||
| 299 | } executed 26 times by 26 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 300 | if (isSignalConnected(changedSignalIndex.load()) && currentValue != ret) {
| 6-5098 | ||||||||||||||||||
| 301 | //the value has changed | - | ||||||||||||||||||
| 302 | emit q->valueChanged(currentValue); | - | ||||||||||||||||||
| 303 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||
| 304 | } executed 5163 times by 26 tests: end of blockExecuted by:
| 5163 | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | QVariant QVariantAnimationPrivate::valueAt(qreal step) const | - | ||||||||||||||||||
| 307 | { | - | ||||||||||||||||||
| 308 | QVariantAnimation::KeyValues::const_iterator result = | - | ||||||||||||||||||
| 309 | std::lower_bound(keyValues.constBegin(), keyValues.constEnd(), qMakePair(step, QVariant()), animationValueLessThan); | - | ||||||||||||||||||
| 310 | if (result != keyValues.constEnd() && !animationValueLessThan(qMakePair(step, QVariant()), *result))
| 39-2293 | ||||||||||||||||||
| 311 | return result->second; executed 1255 times by 26 tests: return result->second;Executed by:
| 1255 | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | return QVariant(); executed 1077 times by 23 tests: return QVariant();Executed by:
| 1077 | ||||||||||||||||||
| 314 | } | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | void QVariantAnimationPrivate::setValueAt(qreal step, const QVariant &value) | - | ||||||||||||||||||
| 317 | { | - | ||||||||||||||||||
| 318 | if (step < qreal(0.0) || step > qreal(1.0)) {
| 0-1471 | ||||||||||||||||||
| 319 | qWarning("QVariantAnimation::setValueAt: invalid step = %f", step); | - | ||||||||||||||||||
| 320 | return; never executed: return; | 0 | ||||||||||||||||||
| 321 | } | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | QVariantAnimation::KeyValue pair(step, value); | - | ||||||||||||||||||
| 324 | - | |||||||||||||||||||
| 325 | QVariantAnimation::KeyValues::iterator result = std::lower_bound(keyValues.begin(), keyValues.end(), pair, animationValueLessThan); | - | ||||||||||||||||||
| 326 | if (result == keyValues.end() || result->first != step) {
| 5-1341 | ||||||||||||||||||
| 327 | keyValues.insert(result, pair); | - | ||||||||||||||||||
| 328 | } else { executed 1346 times by 26 tests: end of blockExecuted by:
| 1346 | ||||||||||||||||||
| 329 | if (value.isValid())
| 37-88 | ||||||||||||||||||
| 330 | result->second = value; // replaces the previous value executed 88 times by 5 tests: result->second = value;Executed by:
| 88 | ||||||||||||||||||
| 331 | else | - | ||||||||||||||||||
| 332 | keyValues.erase(result); // removes the previous value executed 37 times by 2 tests: keyValues.erase(result);Executed by:
| 37 | ||||||||||||||||||
| 333 | } | - | ||||||||||||||||||
| 334 | - | |||||||||||||||||||
| 335 | recalculateCurrentInterval(/*force=*/true); | - | ||||||||||||||||||
| 336 | } executed 1471 times by 26 tests: end of blockExecuted by:
| 1471 | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | void QVariantAnimationPrivate::setDefaultStartEndValue(const QVariant &value) | - | ||||||||||||||||||
| 339 | { | - | ||||||||||||||||||
| 340 | defaultStartEndValue = value; | - | ||||||||||||||||||
| 341 | recalculateCurrentInterval(/*force=*/true); | - | ||||||||||||||||||
| 342 | } executed 1071 times by 23 tests: end of blockExecuted by:
| 1071 | ||||||||||||||||||
| 343 | - | |||||||||||||||||||
| 344 | /*! | - | ||||||||||||||||||
| 345 | Construct a QVariantAnimation object. \a parent is passed to QAbstractAnimation's | - | ||||||||||||||||||
| 346 | constructor. | - | ||||||||||||||||||
| 347 | */ | - | ||||||||||||||||||
| 348 | QVariantAnimation::QVariantAnimation(QObject *parent) : QAbstractAnimation(*new QVariantAnimationPrivate, parent) | - | ||||||||||||||||||
| 349 | { | - | ||||||||||||||||||
| 350 | } executed 904 times by 25 tests: end of blockExecuted by:
| 904 | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | /*! | - | ||||||||||||||||||
| 353 | \internal | - | ||||||||||||||||||
| 354 | */ | - | ||||||||||||||||||
| 355 | QVariantAnimation::QVariantAnimation(QVariantAnimationPrivate &dd, QObject *parent) : QAbstractAnimation(dd, parent) | - | ||||||||||||||||||
| 356 | { | - | ||||||||||||||||||
| 357 | } executed 1075 times by 23 tests: end of blockExecuted by:
| 1075 | ||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | /*! | - | ||||||||||||||||||
| 360 | Destroys the animation. | - | ||||||||||||||||||
| 361 | */ | - | ||||||||||||||||||
| 362 | QVariantAnimation::~QVariantAnimation() | - | ||||||||||||||||||
| 363 | { | - | ||||||||||||||||||
| 364 | } | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | /*! | - | ||||||||||||||||||
| 367 | \property QVariantAnimation::easingCurve | - | ||||||||||||||||||
| 368 | \brief the easing curve of the animation | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | This property defines the easing curve of the animation. By | - | ||||||||||||||||||
| 371 | default, a linear easing curve is used, resulting in linear | - | ||||||||||||||||||
| 372 | interpolation. Other curves are provided, for instance, | - | ||||||||||||||||||
| 373 | QEasingCurve::InCirc, which provides a circular entry curve. | - | ||||||||||||||||||
| 374 | Another example is QEasingCurve::InOutElastic, which provides an | - | ||||||||||||||||||
| 375 | elastic effect on the values of the interpolated variant. | - | ||||||||||||||||||
| 376 | - | |||||||||||||||||||
| 377 | QVariantAnimation will use the QEasingCurve::valueForProgress() to | - | ||||||||||||||||||
| 378 | transform the "normalized progress" (currentTime / totalDuration) | - | ||||||||||||||||||
| 379 | of the animation into the effective progress actually | - | ||||||||||||||||||
| 380 | used by the animation. It is this effective progress that will be | - | ||||||||||||||||||
| 381 | the progress when interpolated() is called. Also, the steps in the | - | ||||||||||||||||||
| 382 | keyValues are referring to this effective progress. | - | ||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | The easing curve is used with the interpolator, the interpolated() | - | ||||||||||||||||||
| 385 | virtual function, and the animation's duration to control how the | - | ||||||||||||||||||
| 386 | current value changes as the animation progresses. | - | ||||||||||||||||||
| 387 | */ | - | ||||||||||||||||||
| 388 | QEasingCurve QVariantAnimation::easingCurve() const | - | ||||||||||||||||||
| 389 | { | - | ||||||||||||||||||
| 390 | Q_D(const QVariantAnimation); | - | ||||||||||||||||||
| 391 | return d->easing; executed 2 times by 1 test: return d->easing;Executed by:
| 2 | ||||||||||||||||||
| 392 | } | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | void QVariantAnimation::setEasingCurve(const QEasingCurve &easing) | - | ||||||||||||||||||
| 395 | { | - | ||||||||||||||||||
| 396 | Q_D(QVariantAnimation); | - | ||||||||||||||||||
| 397 | d->easing = easing; | - | ||||||||||||||||||
| 398 | d->recalculateCurrentInterval(); | - | ||||||||||||||||||
| 399 | } executed 1614 times by 36 tests: end of blockExecuted by:
| 1614 | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | typedef QVector<QVariantAnimation::Interpolator> QInterpolatorVector; | - | ||||||||||||||||||
| 402 | Q_GLOBAL_STATIC(QInterpolatorVector, registeredInterpolators) executed 5 times by 5 tests: end of blockExecuted by:
executed 5 times by 5 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 5595 times by 263 tests: return &holder.value;Executed by:
| 0-5595 | ||||||||||||||||||
| 403 | static QBasicMutex registeredInterpolatorsMutex; | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | /*! | - | ||||||||||||||||||
| 406 | \fn void qRegisterAnimationInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) | - | ||||||||||||||||||
| 407 | \relates QVariantAnimation | - | ||||||||||||||||||
| 408 | \threadsafe | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | Registers a custom interpolator \a func for the template type \c{T}. | - | ||||||||||||||||||
| 411 | The interpolator has to be registered before the animation is constructed. | - | ||||||||||||||||||
| 412 | To unregister (and use the default interpolator) set \a func to 0. | - | ||||||||||||||||||
| 413 | */ | - | ||||||||||||||||||
| 414 | - | |||||||||||||||||||
| 415 | /*! | - | ||||||||||||||||||
| 416 | \internal | - | ||||||||||||||||||
| 417 | \typedef QVariantAnimation::Interpolator | - | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | This is a typedef for a pointer to a function with the following | - | ||||||||||||||||||
| 420 | signature: | - | ||||||||||||||||||
| 421 | \code | - | ||||||||||||||||||
| 422 | QVariant myInterpolator(const QVariant &from, const QVariant &to, qreal progress); | - | ||||||||||||||||||
| 423 | \endcode | - | ||||||||||||||||||
| 424 | - | |||||||||||||||||||
| 425 | */ | - | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | /*! | - | ||||||||||||||||||
| 428 | * \internal | - | ||||||||||||||||||
| 429 | * Registers a custom interpolator \a func for the specific \a interpolationType. | - | ||||||||||||||||||
| 430 | * The interpolator has to be registered before the animation is constructed. | - | ||||||||||||||||||
| 431 | * To unregister (and use the default interpolator) set \a func to 0. | - | ||||||||||||||||||
| 432 | */ | - | ||||||||||||||||||
| 433 | void QVariantAnimation::registerInterpolator(QVariantAnimation::Interpolator func, int interpolationType) | - | ||||||||||||||||||
| 434 | { | - | ||||||||||||||||||
| 435 | // will override any existing interpolators | - | ||||||||||||||||||
| 436 | QInterpolatorVector *interpolators = registeredInterpolators(); | - | ||||||||||||||||||
| 437 | // When built on solaris with GCC, the destructors can be called | - | ||||||||||||||||||
| 438 | // in such an order that we get here with interpolators == NULL, | - | ||||||||||||||||||
| 439 | // to continue causes the app to crash on exit with a SEGV | - | ||||||||||||||||||
| 440 | if (interpolators) {
| 0-2143 | ||||||||||||||||||
| 441 | QMutexLocker locker(®isteredInterpolatorsMutex); | - | ||||||||||||||||||
| 442 | if (int(interpolationType) >= interpolators->count())
| 161-1982 | ||||||||||||||||||
| 443 | interpolators->resize(int(interpolationType) + 1); executed 161 times by 4 tests: interpolators->resize(int(interpolationType) + 1);Executed by:
| 161 | ||||||||||||||||||
| 444 | interpolators->replace(interpolationType, func); | - | ||||||||||||||||||
| 445 | } executed 2143 times by 238 tests: end of blockExecuted by:
| 2143 | ||||||||||||||||||
| 446 | } executed 2143 times by 238 tests: end of blockExecuted by:
| 2143 | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | template<typename T> static inline QVariantAnimation::Interpolator castToInterpolator(QVariant (*func)(const T &from, const T &to, qreal progress)) | - | ||||||||||||||||||
| 450 | { | - | ||||||||||||||||||
| 451 | return reinterpret_cast<QVariantAnimation::Interpolator>(func); executed 1451 times by 26 tests: return reinterpret_cast<QVariantAnimation::Interpolator>(func);Executed by:
| 1451 | ||||||||||||||||||
| 452 | } | - | ||||||||||||||||||
| 453 | - | |||||||||||||||||||
| 454 | QVariantAnimation::Interpolator QVariantAnimationPrivate::getInterpolator(int interpolationType) | - | ||||||||||||||||||
| 455 | { | - | ||||||||||||||||||
| 456 | { | - | ||||||||||||||||||
| 457 | QInterpolatorVector *interpolators = registeredInterpolators(); | - | ||||||||||||||||||
| 458 | QMutexLocker locker(®isteredInterpolatorsMutex); | - | ||||||||||||||||||
| 459 | QVariantAnimation::Interpolator ret = 0; | - | ||||||||||||||||||
| 460 | if (interpolationType < interpolators->count()) {
| 364-3088 | ||||||||||||||||||
| 461 | ret = interpolators->at(interpolationType); | - | ||||||||||||||||||
| 462 | if (ret) return ret; executed 6 times by 1 test: return ret;Executed by:
| 6-3082 | ||||||||||||||||||
| 463 | } executed 3082 times by 21 tests: end of blockExecuted by:
| 3082 | ||||||||||||||||||
| 464 | } | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | switch(interpolationType) | - | ||||||||||||||||||
| 467 | { | - | ||||||||||||||||||
| 468 | case QMetaType::Int: executed 529 times by 10 tests: case QMetaType::Int:Executed by:
| 529 | ||||||||||||||||||
| 469 | return castToInterpolator(_q_interpolateVariant<int>); executed 529 times by 10 tests: return castToInterpolator(_q_interpolateVariant<int>);Executed by:
| 529 | ||||||||||||||||||
| 470 | case QMetaType::UInt: never executed: case QMetaType::UInt: | 0 | ||||||||||||||||||
| 471 | return castToInterpolator(_q_interpolateVariant<uint>); never executed: return castToInterpolator(_q_interpolateVariant<uint>); | 0 | ||||||||||||||||||
| 472 | case QMetaType::Double: executed 71 times by 3 tests: case QMetaType::Double:Executed by:
| 71 | ||||||||||||||||||
| 473 | return castToInterpolator(_q_interpolateVariant<double>); executed 71 times by 3 tests: return castToInterpolator(_q_interpolateVariant<double>);Executed by:
| 71 | ||||||||||||||||||
| 474 | case QMetaType::Float: never executed: case QMetaType::Float: | 0 | ||||||||||||||||||
| 475 | return castToInterpolator(_q_interpolateVariant<float>); never executed: return castToInterpolator(_q_interpolateVariant<float>); | 0 | ||||||||||||||||||
| 476 | case QMetaType::QLine: never executed: case QMetaType::QLine: | 0 | ||||||||||||||||||
| 477 | return castToInterpolator(_q_interpolateVariant<QLine>); never executed: return castToInterpolator(_q_interpolateVariant<QLine>); | 0 | ||||||||||||||||||
| 478 | case QMetaType::QLineF: never executed: case QMetaType::QLineF: | 0 | ||||||||||||||||||
| 479 | return castToInterpolator(_q_interpolateVariant<QLineF>); never executed: return castToInterpolator(_q_interpolateVariant<QLineF>); | 0 | ||||||||||||||||||
| 480 | case QMetaType::QPoint: never executed: case QMetaType::QPoint: | 0 | ||||||||||||||||||
| 481 | return castToInterpolator(_q_interpolateVariant<QPoint>); never executed: return castToInterpolator(_q_interpolateVariant<QPoint>); | 0 | ||||||||||||||||||
| 482 | case QMetaType::QPointF: executed 3 times by 1 test: case QMetaType::QPointF:Executed by:
| 3 | ||||||||||||||||||
| 483 | return castToInterpolator(_q_interpolateVariant<QPointF>); executed 3 times by 1 test: return castToInterpolator(_q_interpolateVariant<QPointF>);Executed by:
| 3 | ||||||||||||||||||
| 484 | case QMetaType::QSize: never executed: case QMetaType::QSize: | 0 | ||||||||||||||||||
| 485 | return castToInterpolator(_q_interpolateVariant<QSize>); never executed: return castToInterpolator(_q_interpolateVariant<QSize>); | 0 | ||||||||||||||||||
| 486 | case QMetaType::QSizeF: never executed: case QMetaType::QSizeF: | 0 | ||||||||||||||||||
| 487 | return castToInterpolator(_q_interpolateVariant<QSizeF>); never executed: return castToInterpolator(_q_interpolateVariant<QSizeF>); | 0 | ||||||||||||||||||
| 488 | case QMetaType::QRect: executed 848 times by 15 tests: case QMetaType::QRect:Executed by:
| 848 | ||||||||||||||||||
| 489 | return castToInterpolator(_q_interpolateVariant<QRect>); executed 848 times by 15 tests: return castToInterpolator(_q_interpolateVariant<QRect>);Executed by:
| 848 | ||||||||||||||||||
| 490 | case QMetaType::QRectF: never executed: case QMetaType::QRectF: | 0 | ||||||||||||||||||
| 491 | return castToInterpolator(_q_interpolateVariant<QRectF>); never executed: return castToInterpolator(_q_interpolateVariant<QRectF>); | 0 | ||||||||||||||||||
| 492 | default: executed 1995 times by 23 tests: default:Executed by:
| 1995 | ||||||||||||||||||
| 493 | return 0; //this type is not handled executed 1995 times by 23 tests: return 0;Executed by:
| 1995 | ||||||||||||||||||
| 494 | } | - | ||||||||||||||||||
| 495 | } | - | ||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | /*! | - | ||||||||||||||||||
| 498 | \property QVariantAnimation::duration | - | ||||||||||||||||||
| 499 | \brief the duration of the animation | - | ||||||||||||||||||
| 500 | - | |||||||||||||||||||
| 501 | This property describes the duration in milliseconds of the | - | ||||||||||||||||||
| 502 | animation. The default duration is 250 milliseconds. | - | ||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | \sa QAbstractAnimation::duration() | - | ||||||||||||||||||
| 505 | */ | - | ||||||||||||||||||
| 506 | int QVariantAnimation::duration() const | - | ||||||||||||||||||
| 507 | { | - | ||||||||||||||||||
| 508 | Q_D(const QVariantAnimation); | - | ||||||||||||||||||
| 509 | return d->duration; executed 11191 times by 26 tests: return d->duration;Executed by:
| 11191 | ||||||||||||||||||
| 510 | } | - | ||||||||||||||||||
| 511 | - | |||||||||||||||||||
| 512 | void QVariantAnimation::setDuration(int msecs) | - | ||||||||||||||||||
| 513 | { | - | ||||||||||||||||||
| 514 | Q_D(QVariantAnimation); | - | ||||||||||||||||||
| 515 | if (msecs < 0) {
| 2-1134 | ||||||||||||||||||
| 516 | qWarning("QVariantAnimation::setDuration: cannot set a negative duration"); | - | ||||||||||||||||||
| 517 | return; executed 2 times by 2 tests: return;Executed by:
| 2 | ||||||||||||||||||
| 518 | } | - | ||||||||||||||||||
| 519 | if (d->duration == msecs)
| 13-1121 | ||||||||||||||||||
| 520 | return; executed 13 times by 5 tests: return;Executed by:
| 13 | ||||||||||||||||||
| 521 | d->duration = msecs; | - | ||||||||||||||||||
| 522 | d->recalculateCurrentInterval(); | - | ||||||||||||||||||
| 523 | } executed 1121 times by 24 tests: end of blockExecuted by:
| 1121 | ||||||||||||||||||
| 524 | - | |||||||||||||||||||
| 525 | /*! | - | ||||||||||||||||||
| 526 | \property QVariantAnimation::startValue | - | ||||||||||||||||||
| 527 | \brief the optional start value of the animation | - | ||||||||||||||||||
| 528 | - | |||||||||||||||||||
| 529 | This property describes the optional start value of the animation. If | - | ||||||||||||||||||
| 530 | omitted, or if a null QVariant is assigned as the start value, the | - | ||||||||||||||||||
| 531 | animation will use the current position of the end when the animation | - | ||||||||||||||||||
| 532 | is started. | - | ||||||||||||||||||
| 533 | - | |||||||||||||||||||
| 534 | \sa endValue | - | ||||||||||||||||||
| 535 | */ | - | ||||||||||||||||||
| 536 | QVariant QVariantAnimation::startValue() const | - | ||||||||||||||||||
| 537 | { | - | ||||||||||||||||||
| 538 | return keyValueAt(0); executed 1156 times by 26 tests: return keyValueAt(0);Executed by:
| 1156 | ||||||||||||||||||
| 539 | } | - | ||||||||||||||||||
| 540 | - | |||||||||||||||||||
| 541 | void QVariantAnimation::setStartValue(const QVariant &value) | - | ||||||||||||||||||
| 542 | { | - | ||||||||||||||||||
| 543 | setKeyValueAt(0, value); | - | ||||||||||||||||||
| 544 | } executed 206 times by 6 tests: end of blockExecuted by:
| 206 | ||||||||||||||||||
| 545 | - | |||||||||||||||||||
| 546 | /*! | - | ||||||||||||||||||
| 547 | \property QVariantAnimation::endValue | - | ||||||||||||||||||
| 548 | \brief the end value of the animation | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | This property describes the end value of the animation. | - | ||||||||||||||||||
| 551 | - | |||||||||||||||||||
| 552 | \sa startValue | - | ||||||||||||||||||
| 553 | */ | - | ||||||||||||||||||
| 554 | QVariant QVariantAnimation::endValue() const | - | ||||||||||||||||||
| 555 | { | - | ||||||||||||||||||
| 556 | return keyValueAt(1); executed 1165 times by 25 tests: return keyValueAt(1);Executed by:
| 1165 | ||||||||||||||||||
| 557 | } | - | ||||||||||||||||||
| 558 | - | |||||||||||||||||||
| 559 | void QVariantAnimation::setEndValue(const QVariant &value) | - | ||||||||||||||||||
| 560 | { | - | ||||||||||||||||||
| 561 | setKeyValueAt(1, value); | - | ||||||||||||||||||
| 562 | } executed 1252 times by 26 tests: end of blockExecuted by:
| 1252 | ||||||||||||||||||
| 563 | - | |||||||||||||||||||
| 564 | - | |||||||||||||||||||
| 565 | /*! | - | ||||||||||||||||||
| 566 | Returns the key frame value for the given \a step. The given \a step | - | ||||||||||||||||||
| 567 | must be in the range 0 to 1. If there is no KeyValue for \a step, | - | ||||||||||||||||||
| 568 | it returns an invalid QVariant. | - | ||||||||||||||||||
| 569 | - | |||||||||||||||||||
| 570 | \sa keyValues(), setKeyValueAt() | - | ||||||||||||||||||
| 571 | */ | - | ||||||||||||||||||
| 572 | QVariant QVariantAnimation::keyValueAt(qreal step) const | - | ||||||||||||||||||
| 573 | { | - | ||||||||||||||||||
| 574 | return d_func()->valueAt(step); executed 2332 times by 26 tests: return d_func()->valueAt(step);Executed by:
| 2332 | ||||||||||||||||||
| 575 | } | - | ||||||||||||||||||
| 576 | - | |||||||||||||||||||
| 577 | /*! | - | ||||||||||||||||||
| 578 | \typedef QVariantAnimation::KeyValue | - | ||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | This is a typedef for QPair<qreal, QVariant>. | - | ||||||||||||||||||
| 581 | */ | - | ||||||||||||||||||
| 582 | /*! | - | ||||||||||||||||||
| 583 | \typedef QVariantAnimation::KeyValues | - | ||||||||||||||||||
| 584 | - | |||||||||||||||||||
| 585 | This is a typedef for QVector<KeyValue> | - | ||||||||||||||||||
| 586 | */ | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | /*! | - | ||||||||||||||||||
| 589 | Creates a key frame at the given \a step with the given \a value. | - | ||||||||||||||||||
| 590 | The given \a step must be in the range 0 to 1. | - | ||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | \sa setKeyValues(), keyValueAt() | - | ||||||||||||||||||
| 593 | */ | - | ||||||||||||||||||
| 594 | void QVariantAnimation::setKeyValueAt(qreal step, const QVariant &value) | - | ||||||||||||||||||
| 595 | { | - | ||||||||||||||||||
| 596 | d_func()->setValueAt(step, value); | - | ||||||||||||||||||
| 597 | } executed 1471 times by 26 tests: end of blockExecuted by:
| 1471 | ||||||||||||||||||
| 598 | - | |||||||||||||||||||
| 599 | /*! | - | ||||||||||||||||||
| 600 | Returns the key frames of this animation. | - | ||||||||||||||||||
| 601 | - | |||||||||||||||||||
| 602 | \sa keyValueAt(), setKeyValues() | - | ||||||||||||||||||
| 603 | */ | - | ||||||||||||||||||
| 604 | QVariantAnimation::KeyValues QVariantAnimation::keyValues() const | - | ||||||||||||||||||
| 605 | { | - | ||||||||||||||||||
| 606 | return d_func()->keyValues; executed 9 times by 2 tests: return d_func()->keyValues;Executed by:
| 9 | ||||||||||||||||||
| 607 | } | - | ||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | /*! | - | ||||||||||||||||||
| 610 | Replaces the current set of key frames with the given \a keyValues. | - | ||||||||||||||||||
| 611 | the step of the key frames must be in the range 0 to 1. | - | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | \sa keyValues(), keyValueAt() | - | ||||||||||||||||||
| 614 | */ | - | ||||||||||||||||||
| 615 | void QVariantAnimation::setKeyValues(const KeyValues &keyValues) | - | ||||||||||||||||||
| 616 | { | - | ||||||||||||||||||
| 617 | Q_D(QVariantAnimation); | - | ||||||||||||||||||
| 618 | d->keyValues = keyValues; | - | ||||||||||||||||||
| 619 | std::sort(d->keyValues.begin(), d->keyValues.end(), animationValueLessThan); | - | ||||||||||||||||||
| 620 | d->recalculateCurrentInterval(/*force=*/true); | - | ||||||||||||||||||
| 621 | } executed 3 times by 2 tests: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | /*! | - | ||||||||||||||||||
| 624 | \property QVariantAnimation::currentValue | - | ||||||||||||||||||
| 625 | \brief the current value of the animation. | - | ||||||||||||||||||
| 626 | - | |||||||||||||||||||
| 627 | This property describes the current value; an interpolated value | - | ||||||||||||||||||
| 628 | between the \l{startValue}{start value} and the \l{endValue}{end | - | ||||||||||||||||||
| 629 | value}, using the current time for progress. The value itself is | - | ||||||||||||||||||
| 630 | obtained from interpolated(), which is called repeatedly as the | - | ||||||||||||||||||
| 631 | animation is running. | - | ||||||||||||||||||
| 632 | - | |||||||||||||||||||
| 633 | QVariantAnimation calls the virtual updateCurrentValue() function | - | ||||||||||||||||||
| 634 | when the current value changes. This is particularly useful for | - | ||||||||||||||||||
| 635 | subclasses that need to track updates. For example, | - | ||||||||||||||||||
| 636 | QPropertyAnimation uses this function to animate Qt \l{Qt's | - | ||||||||||||||||||
| 637 | Property System}{properties}. | - | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | \sa startValue, endValue | - | ||||||||||||||||||
| 640 | */ | - | ||||||||||||||||||
| 641 | QVariant QVariantAnimation::currentValue() const | - | ||||||||||||||||||
| 642 | { | - | ||||||||||||||||||
| 643 | Q_D(const QVariantAnimation); | - | ||||||||||||||||||
| 644 | if (!d->currentValue.isValid())
| 7-31 | ||||||||||||||||||
| 645 | const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval(); executed 7 times by 4 tests: const_cast<QVariantAnimationPrivate*>(d)->recalculateCurrentInterval();Executed by:
| 7 | ||||||||||||||||||
| 646 | return d->currentValue; executed 38 times by 6 tests: return d->currentValue;Executed by:
| 38 | ||||||||||||||||||
| 647 | } | - | ||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | /*! | - | ||||||||||||||||||
| 650 | \reimp | - | ||||||||||||||||||
| 651 | */ | - | ||||||||||||||||||
| 652 | bool QVariantAnimation::event(QEvent *event) | - | ||||||||||||||||||
| 653 | { | - | ||||||||||||||||||
| 654 | return QAbstractAnimation::event(event); executed 448 times by 17 tests: return QAbstractAnimation::event(event);Executed by:
| 448 | ||||||||||||||||||
| 655 | } | - | ||||||||||||||||||
| 656 | - | |||||||||||||||||||
| 657 | /*! | - | ||||||||||||||||||
| 658 | \reimp | - | ||||||||||||||||||
| 659 | */ | - | ||||||||||||||||||
| 660 | void QVariantAnimation::updateState(QAbstractAnimation::State newState, | - | ||||||||||||||||||
| 661 | QAbstractAnimation::State oldState) | - | ||||||||||||||||||
| 662 | { | - | ||||||||||||||||||
| 663 | Q_UNUSED(oldState); | - | ||||||||||||||||||
| 664 | Q_UNUSED(newState); | - | ||||||||||||||||||
| 665 | } executed 2175 times by 23 tests: end of blockExecuted by:
| 2175 | ||||||||||||||||||
| 666 | - | |||||||||||||||||||
| 667 | /*! | - | ||||||||||||||||||
| 668 | - | |||||||||||||||||||
| 669 | This virtual function returns the linear interpolation between | - | ||||||||||||||||||
| 670 | variants \a from and \a to, at \a progress, usually a value | - | ||||||||||||||||||
| 671 | between 0 and 1. You can reimplement this function in a subclass | - | ||||||||||||||||||
| 672 | of QVariantAnimation to provide your own interpolation algorithm. | - | ||||||||||||||||||
| 673 | - | |||||||||||||||||||
| 674 | Note that in order for the interpolation to work with a | - | ||||||||||||||||||
| 675 | QEasingCurve that return a value smaller than 0 or larger than 1 | - | ||||||||||||||||||
| 676 | (such as QEasingCurve::InBack) you should make sure that it can | - | ||||||||||||||||||
| 677 | extrapolate. If the semantic of the datatype does not allow | - | ||||||||||||||||||
| 678 | extrapolation this function should handle that gracefully. | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | You should call the QVariantAnimation implementation of this | - | ||||||||||||||||||
| 681 | function if you want your class to handle the types already | - | ||||||||||||||||||
| 682 | supported by Qt (see class QVariantAnimation description for a | - | ||||||||||||||||||
| 683 | list of supported types). | - | ||||||||||||||||||
| 684 | - | |||||||||||||||||||
| 685 | \sa QEasingCurve | - | ||||||||||||||||||
| 686 | */ | - | ||||||||||||||||||
| 687 | QVariant QVariantAnimation::interpolated(const QVariant &from, const QVariant &to, qreal progress) const | - | ||||||||||||||||||
| 688 | { | - | ||||||||||||||||||
| 689 | return d_func()->interpolator(from.constData(), to.constData(), progress); executed 5163 times by 26 tests: return d_func()->interpolator(from.constData(), to.constData(), progress);Executed by:
| 5163 | ||||||||||||||||||
| 690 | } | - | ||||||||||||||||||
| 691 | - | |||||||||||||||||||
| 692 | /*! | - | ||||||||||||||||||
| 693 | \reimp | - | ||||||||||||||||||
| 694 | */ | - | ||||||||||||||||||
| 695 | void QVariantAnimation::updateCurrentTime(int) | - | ||||||||||||||||||
| 696 | { | - | ||||||||||||||||||
| 697 | d_func()->recalculateCurrentInterval(); | - | ||||||||||||||||||
| 698 | } executed 3796 times by 25 tests: end of blockExecuted by:
| 3796 | ||||||||||||||||||
| 699 | - | |||||||||||||||||||
| 700 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 701 | - | |||||||||||||||||||
| 702 | #include "moc_qvariantanimation.cpp" | - | ||||||||||||||||||
| 703 | - | |||||||||||||||||||
| 704 | #endif //QT_NO_ANIMATION | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |