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