| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsitemanimation.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 QtWidgets 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 | /*! | - | ||||||||||||
| 35 | \class QGraphicsItemAnimation | - | ||||||||||||
| 36 | \brief The QGraphicsItemAnimation class provides simple animation | - | ||||||||||||
| 37 | support for QGraphicsItem. | - | ||||||||||||
| 38 | \since 4.2 | - | ||||||||||||
| 39 | \ingroup graphicsview-api | - | ||||||||||||
| 40 | \inmodule QtWidgets | - | ||||||||||||
| 41 | \deprecated | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | The QGraphicsItemAnimation class animates a QGraphicsItem. You can | - | ||||||||||||
| 44 | schedule changes to the item's transformation matrix at | - | ||||||||||||
| 45 | specified steps. The QGraphicsItemAnimation class has a | - | ||||||||||||
| 46 | current step value. When this value changes the transformations | - | ||||||||||||
| 47 | scheduled at that step are performed. The current step of the | - | ||||||||||||
| 48 | animation is set with the \c setStep() function. | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | QGraphicsItemAnimation will do a simple linear interpolation | - | ||||||||||||
| 51 | between the nearest adjacent scheduled changes to calculate the | - | ||||||||||||
| 52 | matrix. For instance, if you set the position of an item at values | - | ||||||||||||
| 53 | 0.0 and 1.0, the animation will show the item moving in a straight | - | ||||||||||||
| 54 | line between these positions. The same is true for scaling and | - | ||||||||||||
| 55 | rotation. | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | It is usual to use the class with a QTimeLine. The timeline's | - | ||||||||||||
| 58 | \l{QTimeLine::}{valueChanged()} signal is then connected to the | - | ||||||||||||
| 59 | \c setStep() slot. For example, you can set up an item for rotation | - | ||||||||||||
| 60 | by calling \c setRotationAt() for different step values. | - | ||||||||||||
| 61 | The animations timeline is set with the setTimeLine() function. | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | An example animation with a timeline follows: | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | \snippet timeline/main.cpp 0 | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | Note that steps lie between 0.0 and 1.0. It may be necessary to use | - | ||||||||||||
| 68 | \l{QTimeLine::}{setUpdateInterval()}. The default update interval | - | ||||||||||||
| 69 | is 40 ms. A scheduled transformation cannot be removed when set, | - | ||||||||||||
| 70 | so scheduling several transformations of the same kind (e.g., | - | ||||||||||||
| 71 | rotations) at the same step is not recommended. | - | ||||||||||||
| 72 | - | |||||||||||||
| 73 | \sa QTimeLine, {Graphics View Framework} | - | ||||||||||||
| 74 | */ | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | #include "qgraphicsitemanimation.h" | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | #ifndef QT_NO_GRAPHICSVIEW | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | #include "qgraphicsitem.h" | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | #include <QtCore/qtimeline.h> | - | ||||||||||||
| 83 | #include <QtCore/qpoint.h> | - | ||||||||||||
| 84 | #include <QtCore/qpointer.h> | - | ||||||||||||
| 85 | #include <QtCore/qpair.h> | - | ||||||||||||
| 86 | #include <QtGui/qmatrix.h> | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | #include <algorithm> | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | static inline bool check_step_valid(qreal step, const char *method) | - | ||||||||||||
| 93 | { | - | ||||||||||||
| 94 |     if (!(step >= 0 && step <= 1)) {
 
  | 0 | ||||||||||||
| 95 | qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step); | - | ||||||||||||
| 96 |         return false; never executed:  return false; | 0 | ||||||||||||
| 97 | } | - | ||||||||||||
| 98 |     return true; never executed:  return true; | 0 | ||||||||||||
| 99 | } | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | class QGraphicsItemAnimationPrivate | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | public: | - | ||||||||||||
| 104 | inline QGraphicsItemAnimationPrivate() | - | ||||||||||||
| 105 | : q(0), timeLine(0), item(0), step(0) | - | ||||||||||||
| 106 |     { } never executed:  end of block | 0 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | QGraphicsItemAnimation *q; | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | QPointer<QTimeLine> timeLine; | - | ||||||||||||
| 111 | QGraphicsItem *item; | - | ||||||||||||
| 112 | - | |||||||||||||
| 113 | QPointF startPos; | - | ||||||||||||
| 114 | QMatrix startMatrix; | - | ||||||||||||
| 115 | - | |||||||||||||
| 116 | qreal step; | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | struct Pair { | - | ||||||||||||
| 119 | bool operator <(const Pair &other) const | - | ||||||||||||
| 120 |         { return step < other.step; } never executed:  return step < other.step; | 0 | ||||||||||||
| 121 | bool operator==(const Pair &other) const | - | ||||||||||||
| 122 |         { return step == other.step; } never executed:  return step == other.step; | 0 | ||||||||||||
| 123 | qreal step; | - | ||||||||||||
| 124 | qreal value; | - | ||||||||||||
| 125 | }; | - | ||||||||||||
| 126 | QVector<Pair> xPosition; | - | ||||||||||||
| 127 | QVector<Pair> yPosition; | - | ||||||||||||
| 128 | QVector<Pair> rotation; | - | ||||||||||||
| 129 | QVector<Pair> verticalScale; | - | ||||||||||||
| 130 | QVector<Pair> horizontalScale; | - | ||||||||||||
| 131 | QVector<Pair> verticalShear; | - | ||||||||||||
| 132 | QVector<Pair> horizontalShear; | - | ||||||||||||
| 133 | QVector<Pair> xTranslation; | - | ||||||||||||
| 134 | QVector<Pair> yTranslation; | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | qreal linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue = 0); | - | ||||||||||||
| 137 | void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method); | - | ||||||||||||
| 138 | }; | - | ||||||||||||
| 139 | Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE); | - | ||||||||||||
| 140 | - | |||||||||||||
| 141 | qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue) | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 |     if (source->isEmpty())
  | 0 | ||||||||||||
| 144 |         return defaultValue; never executed:  return defaultValue; | 0 | ||||||||||||
| 145 | step = qMin<qreal>(qMax<qreal>(step, 0), 1); | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 |     if (step == 1)
  | 0 | ||||||||||||
| 148 |         return source->last().value; never executed:  return source->last().value; | 0 | ||||||||||||
| 149 | - | |||||||||||||
| 150 | qreal stepBefore = 0; | - | ||||||||||||
| 151 | qreal stepAfter = 1; | - | ||||||||||||
| 152 |     qreal valueBefore = source->first().step == 0 ? source->first().value : defaultValue;
  | 0 | ||||||||||||
| 153 | qreal valueAfter = source->last().value; | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | // Find the closest step and value before the given step. | - | ||||||||||||
| 156 |     for (int i = 0; i < source->size() && step >= source->at(i).step; ++i) {
 
  | 0 | ||||||||||||
| 157 | stepBefore = source->at(i).step; | - | ||||||||||||
| 158 | valueBefore = source->at(i).value; | - | ||||||||||||
| 159 |     } never executed:  end of block | 0 | ||||||||||||
| 160 | - | |||||||||||||
| 161 | // Find the closest step and value after the given step. | - | ||||||||||||
| 162 |     for (int j = source->size() - 1; j >= 0 && step < source->at(j).step; --j) {
 
  | 0 | ||||||||||||
| 163 | stepAfter = source->at(j).step; | - | ||||||||||||
| 164 | valueAfter = source->at(j).value; | - | ||||||||||||
| 165 |     } never executed:  end of block | 0 | ||||||||||||
| 166 | - | |||||||||||||
| 167 | // Do a simple linear interpolation. | - | ||||||||||||
| 168 |     return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore)); never executed:  return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore)); | 0 | ||||||||||||
| 169 | } | - | ||||||||||||
| 170 | - | |||||||||||||
| 171 | void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method) | - | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 |     if (!check_step_valid(step, method))
  | 0 | ||||||||||||
| 174 |         return; never executed:  return; | 0 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | const Pair pair = { step, value }; | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); | - | ||||||||||||
| 179 |     if (result == binList->end() || pair < *result)
 
  | 0 | ||||||||||||
| 180 |         binList->insert(result, pair); never executed:  binList->insert(result, pair); | 0 | ||||||||||||
| 181 | else | - | ||||||||||||
| 182 |         result->value = value; never executed:  result->value = value; | 0 | ||||||||||||
| 183 | } | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | /*! | - | ||||||||||||
| 186 | Constructs an animation object with the given \a parent. | - | ||||||||||||
| 187 | */ | - | ||||||||||||
| 188 | QGraphicsItemAnimation::QGraphicsItemAnimation(QObject *parent) | - | ||||||||||||
| 189 | : QObject(parent), d(new QGraphicsItemAnimationPrivate) | - | ||||||||||||
| 190 | { | - | ||||||||||||
| 191 | d->q = this; | - | ||||||||||||
| 192 | } never executed:  end of block | 0 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | /*! | - | ||||||||||||
| 195 | Destroys the animation object. | - | ||||||||||||
| 196 | */ | - | ||||||||||||
| 197 | QGraphicsItemAnimation::~QGraphicsItemAnimation() | - | ||||||||||||
| 198 | { | - | ||||||||||||
| 199 | delete d; | - | ||||||||||||
| 200 | } never executed:  end of block | 0 | ||||||||||||
| 201 | - | |||||||||||||
| 202 | /*! | - | ||||||||||||
| 203 | Returns the item on which the animation object operates. | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | \sa setItem() | - | ||||||||||||
| 206 | */ | - | ||||||||||||
| 207 | QGraphicsItem *QGraphicsItemAnimation::item() const | - | ||||||||||||
| 208 | { | - | ||||||||||||
| 209 |     return d->item; never executed:  return d->item; | 0 | ||||||||||||
| 210 | } | - | ||||||||||||
| 211 | - | |||||||||||||
| 212 | /*! | - | ||||||||||||
| 213 | Sets the specified \a item to be used in the animation. | - | ||||||||||||
| 214 | - | |||||||||||||
| 215 | \sa item() | - | ||||||||||||
| 216 | */ | - | ||||||||||||
| 217 | void QGraphicsItemAnimation::setItem(QGraphicsItem *item) | - | ||||||||||||
| 218 | { | - | ||||||||||||
| 219 | d->item = item; | - | ||||||||||||
| 220 | d->startPos = d->item->pos(); | - | ||||||||||||
| 221 | } never executed:  end of block | 0 | ||||||||||||
| 222 | - | |||||||||||||
| 223 | /*! | - | ||||||||||||
| 224 | Returns the timeline object used to control the rate at which the animation | - | ||||||||||||
| 225 | occurs. | - | ||||||||||||
| 226 | - | |||||||||||||
| 227 | \sa setTimeLine() | - | ||||||||||||
| 228 | */ | - | ||||||||||||
| 229 | QTimeLine *QGraphicsItemAnimation::timeLine() const | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 |     return d->timeLine; never executed:  return d->timeLine; | 0 | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | /*! | - | ||||||||||||
| 235 | Sets the timeline object used to control the rate of animation to the \a timeLine | - | ||||||||||||
| 236 | specified. | - | ||||||||||||
| 237 | - | |||||||||||||
| 238 | \sa timeLine() | - | ||||||||||||
| 239 | */ | - | ||||||||||||
| 240 | void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine) | - | ||||||||||||
| 241 | { | - | ||||||||||||
| 242 |     if (d->timeLine == timeLine)
  | 0 | ||||||||||||
| 243 |         return; never executed:  return; | 0 | ||||||||||||
| 244 |     if (d->timeLine)
  | 0 | ||||||||||||
| 245 |         delete d->timeLine; never executed:  delete d->timeLine; | 0 | ||||||||||||
| 246 |     if (!timeLine)
  | 0 | ||||||||||||
| 247 |         return; never executed:  return; | 0 | ||||||||||||
| 248 | d->timeLine = timeLine; | - | ||||||||||||
| 249 | connect(timeLine, SIGNAL(valueChanged(qreal)), this, SLOT(setStep(qreal))); | - | ||||||||||||
| 250 | } never executed:  end of block | 0 | ||||||||||||
| 251 | - | |||||||||||||
| 252 | /*! | - | ||||||||||||
| 253 | Returns the position of the item at the given \a step value. | - | ||||||||||||
| 254 | - | |||||||||||||
| 255 | \sa setPosAt() | - | ||||||||||||
| 256 | */ | - | ||||||||||||
| 257 | QPointF QGraphicsItemAnimation::posAt(qreal step) const | - | ||||||||||||
| 258 | { | - | ||||||||||||
| 259 | check_step_valid(step, "posAt"); | - | ||||||||||||
| 260 |     return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()), never executed:  return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()), d->linearValueForStep(step, &d->yPosition, d->startPos.y())); | 0 | ||||||||||||
| 261 |                    d->linearValueForStep(step, &d->yPosition, d->startPos.y())); never executed:  return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()), d->linearValueForStep(step, &d->yPosition, d->startPos.y())); | 0 | ||||||||||||
| 262 | } | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | /*! | - | ||||||||||||
| 265 | \fn void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &point) | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | Sets the position of the item at the given \a step value to the \a point specified. | - | ||||||||||||
| 268 | - | |||||||||||||
| 269 | \sa posAt() | - | ||||||||||||
| 270 | */ | - | ||||||||||||
| 271 | void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &pos) | - | ||||||||||||
| 272 | { | - | ||||||||||||
| 273 | d->insertUniquePair(step, pos.x(), &d->xPosition, "setPosAt"); | - | ||||||||||||
| 274 | d->insertUniquePair(step, pos.y(), &d->yPosition, "setPosAt"); | - | ||||||||||||
| 275 | } never executed:  end of block | 0 | ||||||||||||
| 276 | - | |||||||||||||
| 277 | /*! | - | ||||||||||||
| 278 | Returns all explicitly inserted positions. | - | ||||||||||||
| 279 | - | |||||||||||||
| 280 | \sa posAt(), setPosAt() | - | ||||||||||||
| 281 | */ | - | ||||||||||||
| 282 | QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const | - | ||||||||||||
| 283 | { | - | ||||||||||||
| 284 | QList<QPair<qreal, QPointF> > list; | - | ||||||||||||
| 285 | const int xPosCount = d->xPosition.size(); | - | ||||||||||||
| 286 | list.reserve(xPosCount); | - | ||||||||||||
| 287 |     for (int i = 0; i < xPosCount; ++i)
  | 0 | ||||||||||||
| 288 |         list << QPair<qreal, QPointF>(d->xPosition.at(i).step, QPointF(d->xPosition.at(i).value, d->yPosition.at(i).value)); never executed:  list << QPair<qreal, QPointF>(d->xPosition.at(i).step, QPointF(d->xPosition.at(i).value, d->yPosition.at(i).value)); | 0 | ||||||||||||
| 289 | - | |||||||||||||
| 290 |     return list; never executed:  return list; | 0 | ||||||||||||
| 291 | } | - | ||||||||||||
| 292 | - | |||||||||||||
| 293 | /*! | - | ||||||||||||
| 294 | Returns the matrix used to transform the item at the specified \a step value. | - | ||||||||||||
| 295 | */ | - | ||||||||||||
| 296 | QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const | - | ||||||||||||
| 297 | { | - | ||||||||||||
| 298 | check_step_valid(step, "matrixAt"); | - | ||||||||||||
| 299 | - | |||||||||||||
| 300 | QMatrix matrix; | - | ||||||||||||
| 301 |     if (!d->rotation.isEmpty())
  | 0 | ||||||||||||
| 302 |         matrix.rotate(rotationAt(step)); never executed:  matrix.rotate(rotationAt(step)); | 0 | ||||||||||||
| 303 |     if (!d->verticalScale.isEmpty())
  | 0 | ||||||||||||
| 304 |         matrix.scale(horizontalScaleAt(step), verticalScaleAt(step)); never executed:  matrix.scale(horizontalScaleAt(step), verticalScaleAt(step)); | 0 | ||||||||||||
| 305 |     if (!d->verticalShear.isEmpty())
  | 0 | ||||||||||||
| 306 |         matrix.shear(horizontalShearAt(step), verticalShearAt(step)); never executed:  matrix.shear(horizontalShearAt(step), verticalShearAt(step)); | 0 | ||||||||||||
| 307 |     if (!d->xTranslation.isEmpty())
  | 0 | ||||||||||||
| 308 |         matrix.translate(xTranslationAt(step), yTranslationAt(step)); never executed:  matrix.translate(xTranslationAt(step), yTranslationAt(step)); | 0 | ||||||||||||
| 309 |     return matrix; never executed:  return matrix; | 0 | ||||||||||||
| 310 | } | - | ||||||||||||
| 311 | - | |||||||||||||
| 312 | /*! | - | ||||||||||||
| 313 | Returns the angle at which the item is rotated at the specified \a step value. | - | ||||||||||||
| 314 | - | |||||||||||||
| 315 | \sa setRotationAt() | - | ||||||||||||
| 316 | */ | - | ||||||||||||
| 317 | qreal QGraphicsItemAnimation::rotationAt(qreal step) const | - | ||||||||||||
| 318 | { | - | ||||||||||||
| 319 | check_step_valid(step, "rotationAt"); | - | ||||||||||||
| 320 |     return d->linearValueForStep(step, &d->rotation); never executed:  return d->linearValueForStep(step, &d->rotation); | 0 | ||||||||||||
| 321 | } | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | /*! | - | ||||||||||||
| 324 | Sets the rotation of the item at the given \a step value to the \a angle specified. | - | ||||||||||||
| 325 | - | |||||||||||||
| 326 | \sa rotationAt() | - | ||||||||||||
| 327 | */ | - | ||||||||||||
| 328 | void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle) | - | ||||||||||||
| 329 | { | - | ||||||||||||
| 330 | d->insertUniquePair(step, angle, &d->rotation, "setRotationAt"); | - | ||||||||||||
| 331 | } never executed:  end of block | 0 | ||||||||||||
| 332 | - | |||||||||||||
| 333 | /*! | - | ||||||||||||
| 334 | Returns all explicitly inserted rotations. | - | ||||||||||||
| 335 | - | |||||||||||||
| 336 | \sa rotationAt(), setRotationAt() | - | ||||||||||||
| 337 | */ | - | ||||||||||||
| 338 | QList<QPair<qreal, qreal> > QGraphicsItemAnimation::rotationList() const | - | ||||||||||||
| 339 | { | - | ||||||||||||
| 340 | QList<QPair<qreal, qreal> > list; | - | ||||||||||||
| 341 | const int numRotations = d->rotation.size(); | - | ||||||||||||
| 342 | list.reserve(numRotations); | - | ||||||||||||
| 343 |     for (int i = 0; i < numRotations; ++i)
  | 0 | ||||||||||||
| 344 |         list << QPair<qreal, qreal>(d->rotation.at(i).step, d->rotation.at(i).value); never executed:  list << QPair<qreal, qreal>(d->rotation.at(i).step, d->rotation.at(i).value); | 0 | ||||||||||||
| 345 | - | |||||||||||||
| 346 |     return list; never executed:  return list; | 0 | ||||||||||||
| 347 | } | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | /*! | - | ||||||||||||
| 350 | Returns the horizontal translation of the item at the specified \a step value. | - | ||||||||||||
| 351 | - | |||||||||||||
| 352 | \sa setTranslationAt() | - | ||||||||||||
| 353 | */ | - | ||||||||||||
| 354 | qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const | - | ||||||||||||
| 355 | { | - | ||||||||||||
| 356 | check_step_valid(step, "xTranslationAt"); | - | ||||||||||||
| 357 |     return d->linearValueForStep(step, &d->xTranslation); never executed:  return d->linearValueForStep(step, &d->xTranslation); | 0 | ||||||||||||
| 358 | } | - | ||||||||||||
| 359 | - | |||||||||||||
| 360 | /*! | - | ||||||||||||
| 361 | Returns the vertical translation of the item at the specified \a step value. | - | ||||||||||||
| 362 | - | |||||||||||||
| 363 | \sa setTranslationAt() | - | ||||||||||||
| 364 | */ | - | ||||||||||||
| 365 | qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const | - | ||||||||||||
| 366 | { | - | ||||||||||||
| 367 | check_step_valid(step, "yTranslationAt"); | - | ||||||||||||
| 368 |     return d->linearValueForStep(step, &d->yTranslation); never executed:  return d->linearValueForStep(step, &d->yTranslation); | 0 | ||||||||||||
| 369 | } | - | ||||||||||||
| 370 | - | |||||||||||||
| 371 | /*! | - | ||||||||||||
| 372 | Sets the translation of the item at the given \a step value using the horizontal | - | ||||||||||||
| 373 | and vertical coordinates specified by \a dx and \a dy. | - | ||||||||||||
| 374 | - | |||||||||||||
| 375 | \sa xTranslationAt(), yTranslationAt() | - | ||||||||||||
| 376 | */ | - | ||||||||||||
| 377 | void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy) | - | ||||||||||||
| 378 | { | - | ||||||||||||
| 379 | d->insertUniquePair(step, dx, &d->xTranslation, "setTranslationAt"); | - | ||||||||||||
| 380 | d->insertUniquePair(step, dy, &d->yTranslation, "setTranslationAt"); | - | ||||||||||||
| 381 | } never executed:  end of block | 0 | ||||||||||||
| 382 | - | |||||||||||||
| 383 | /*! | - | ||||||||||||
| 384 | Returns all explicitly inserted translations. | - | ||||||||||||
| 385 | - | |||||||||||||
| 386 | \sa xTranslationAt(), yTranslationAt(), setTranslationAt() | - | ||||||||||||
| 387 | */ | - | ||||||||||||
| 388 | QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::translationList() const | - | ||||||||||||
| 389 | { | - | ||||||||||||
| 390 | QList<QPair<qreal, QPointF> > list; | - | ||||||||||||
| 391 | const int numTranslations = d->xTranslation.size(); | - | ||||||||||||
| 392 | list.reserve(numTranslations); | - | ||||||||||||
| 393 |     for (int i = 0; i < numTranslations; ++i)
  | 0 | ||||||||||||
| 394 |         list << QPair<qreal, QPointF>(d->xTranslation.at(i).step, QPointF(d->xTranslation.at(i).value, d->yTranslation.at(i).value)); never executed:  list << QPair<qreal, QPointF>(d->xTranslation.at(i).step, QPointF(d->xTranslation.at(i).value, d->yTranslation.at(i).value)); | 0 | ||||||||||||
| 395 | - | |||||||||||||
| 396 |     return list; never executed:  return list; | 0 | ||||||||||||
| 397 | } | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | /*! | - | ||||||||||||
| 400 | Returns the vertical scale for the item at the specified \a step value. | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | \sa setScaleAt() | - | ||||||||||||
| 403 | */ | - | ||||||||||||
| 404 | qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const | - | ||||||||||||
| 405 | { | - | ||||||||||||
| 406 | check_step_valid(step, "verticalScaleAt"); | - | ||||||||||||
| 407 | - | |||||||||||||
| 408 |     return d->linearValueForStep(step, &d->verticalScale, 1); never executed:  return d->linearValueForStep(step, &d->verticalScale, 1); | 0 | ||||||||||||
| 409 | } | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | /*! | - | ||||||||||||
| 412 | Returns the horizontal scale for the item at the specified \a step value. | - | ||||||||||||
| 413 | - | |||||||||||||
| 414 | \sa setScaleAt() | - | ||||||||||||
| 415 | */ | - | ||||||||||||
| 416 | qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const | - | ||||||||||||
| 417 | { | - | ||||||||||||
| 418 | check_step_valid(step, "horizontalScaleAt"); | - | ||||||||||||
| 419 |     return d->linearValueForStep(step, &d->horizontalScale, 1); never executed:  return d->linearValueForStep(step, &d->horizontalScale, 1); | 0 | ||||||||||||
| 420 | } | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | /*! | - | ||||||||||||
| 423 | Sets the scale of the item at the given \a step value using the horizontal and | - | ||||||||||||
| 424 | vertical scale factors specified by \a sx and \a sy. | - | ||||||||||||
| 425 | - | |||||||||||||
| 426 | \sa verticalScaleAt(), horizontalScaleAt() | - | ||||||||||||
| 427 | */ | - | ||||||||||||
| 428 | void QGraphicsItemAnimation::setScaleAt(qreal step, qreal sx, qreal sy) | - | ||||||||||||
| 429 | { | - | ||||||||||||
| 430 | d->insertUniquePair(step, sx, &d->horizontalScale, "setScaleAt"); | - | ||||||||||||
| 431 | d->insertUniquePair(step, sy, &d->verticalScale, "setScaleAt"); | - | ||||||||||||
| 432 | } never executed:  end of block | 0 | ||||||||||||
| 433 | - | |||||||||||||
| 434 | /*! | - | ||||||||||||
| 435 | Returns all explicitly inserted scales. | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | \sa verticalScaleAt(), horizontalScaleAt(), setScaleAt() | - | ||||||||||||
| 438 | */ | - | ||||||||||||
| 439 | QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::scaleList() const | - | ||||||||||||
| 440 | { | - | ||||||||||||
| 441 | QList<QPair<qreal, QPointF> > list; | - | ||||||||||||
| 442 | const int numScales = d->horizontalScale.size(); | - | ||||||||||||
| 443 | list.reserve(numScales); | - | ||||||||||||
| 444 |     for (int i = 0; i < numScales; ++i)
  | 0 | ||||||||||||
| 445 |         list << QPair<qreal, QPointF>(d->horizontalScale.at(i).step, QPointF(d->horizontalScale.at(i).value, d->verticalScale.at(i).value)); never executed:  list << QPair<qreal, QPointF>(d->horizontalScale.at(i).step, QPointF(d->horizontalScale.at(i).value, d->verticalScale.at(i).value)); | 0 | ||||||||||||
| 446 | - | |||||||||||||
| 447 |     return list; never executed:  return list; | 0 | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | - | |||||||||||||
| 450 | /*! | - | ||||||||||||
| 451 | Returns the vertical shear for the item at the specified \a step value. | - | ||||||||||||
| 452 | - | |||||||||||||
| 453 | \sa setShearAt() | - | ||||||||||||
| 454 | */ | - | ||||||||||||
| 455 | qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const | - | ||||||||||||
| 456 | { | - | ||||||||||||
| 457 | check_step_valid(step, "verticalShearAt"); | - | ||||||||||||
| 458 |     return d->linearValueForStep(step, &d->verticalShear, 0); never executed:  return d->linearValueForStep(step, &d->verticalShear, 0); | 0 | ||||||||||||
| 459 | } | - | ||||||||||||
| 460 | - | |||||||||||||
| 461 | /*! | - | ||||||||||||
| 462 | Returns the horizontal shear for the item at the specified \a step value. | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | \sa setShearAt() | - | ||||||||||||
| 465 | */ | - | ||||||||||||
| 466 | qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const | - | ||||||||||||
| 467 | { | - | ||||||||||||
| 468 | check_step_valid(step, "horizontalShearAt"); | - | ||||||||||||
| 469 |     return d->linearValueForStep(step, &d->horizontalShear, 0); never executed:  return d->linearValueForStep(step, &d->horizontalShear, 0); | 0 | ||||||||||||
| 470 | } | - | ||||||||||||
| 471 | - | |||||||||||||
| 472 | /*! | - | ||||||||||||
| 473 | Sets the shear of the item at the given \a step value using the horizontal and | - | ||||||||||||
| 474 | vertical shear factors specified by \a sh and \a sv. | - | ||||||||||||
| 475 | - | |||||||||||||
| 476 | \sa verticalShearAt(), horizontalShearAt() | - | ||||||||||||
| 477 | */ | - | ||||||||||||
| 478 | void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv) | - | ||||||||||||
| 479 | { | - | ||||||||||||
| 480 | d->insertUniquePair(step, sh, &d->horizontalShear, "setShearAt"); | - | ||||||||||||
| 481 | d->insertUniquePair(step, sv, &d->verticalShear, "setShearAt"); | - | ||||||||||||
| 482 | } never executed:  end of block | 0 | ||||||||||||
| 483 | - | |||||||||||||
| 484 | /*! | - | ||||||||||||
| 485 | Returns all explicitly inserted shears. | - | ||||||||||||
| 486 | - | |||||||||||||
| 487 | \sa verticalShearAt(), horizontalShearAt(), setShearAt() | - | ||||||||||||
| 488 | */ | - | ||||||||||||
| 489 | QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::shearList() const | - | ||||||||||||
| 490 | { | - | ||||||||||||
| 491 | QList<QPair<qreal, QPointF> > list; | - | ||||||||||||
| 492 | const int numShears = d->horizontalShear.size(); | - | ||||||||||||
| 493 | list.reserve(numShears); | - | ||||||||||||
| 494 |     for (int i = 0; i < numShears; ++i)
  | 0 | ||||||||||||
| 495 |         list << QPair<qreal, QPointF>(d->horizontalShear.at(i).step, QPointF(d->horizontalShear.at(i).value, d->verticalShear.at(i).value)); never executed:  list << QPair<qreal, QPointF>(d->horizontalShear.at(i).step, QPointF(d->horizontalShear.at(i).value, d->verticalShear.at(i).value)); | 0 | ||||||||||||
| 496 | - | |||||||||||||
| 497 |     return list; never executed:  return list; | 0 | ||||||||||||
| 498 | } | - | ||||||||||||
| 499 | - | |||||||||||||
| 500 | /*! | - | ||||||||||||
| 501 | Clears the scheduled transformations used for the animation, but | - | ||||||||||||
| 502 | retains the item and timeline. | - | ||||||||||||
| 503 | */ | - | ||||||||||||
| 504 | void QGraphicsItemAnimation::clear() | - | ||||||||||||
| 505 | { | - | ||||||||||||
| 506 | d->xPosition.clear(); | - | ||||||||||||
| 507 | d->yPosition.clear(); | - | ||||||||||||
| 508 | d->rotation.clear(); | - | ||||||||||||
| 509 | d->verticalScale.clear(); | - | ||||||||||||
| 510 | d->horizontalScale.clear(); | - | ||||||||||||
| 511 | d->verticalShear.clear(); | - | ||||||||||||
| 512 | d->horizontalShear.clear(); | - | ||||||||||||
| 513 | d->xTranslation.clear(); | - | ||||||||||||
| 514 | d->yTranslation.clear(); | - | ||||||||||||
| 515 | } never executed:  end of block | 0 | ||||||||||||
| 516 | - | |||||||||||||
| 517 | /*! | - | ||||||||||||
| 518 | \fn void QGraphicsItemAnimation::setStep(qreal step) | - | ||||||||||||
| 519 | - | |||||||||||||
| 520 | Sets the current \a step value for the animation, causing the | - | ||||||||||||
| 521 | transformations scheduled at this step to be performed. | - | ||||||||||||
| 522 | */ | - | ||||||||||||
| 523 | void QGraphicsItemAnimation::setStep(qreal step) | - | ||||||||||||
| 524 | { | - | ||||||||||||
| 525 |     if (!check_step_valid(step, "setStep"))
  | 0 | ||||||||||||
| 526 |         return; never executed:  return; | 0 | ||||||||||||
| 527 | - | |||||||||||||
| 528 | beforeAnimationStep(step); | - | ||||||||||||
| 529 | - | |||||||||||||
| 530 | d->step = step; | - | ||||||||||||
| 531 |     if (d->item) {
  | 0 | ||||||||||||
| 532 |         if (!d->xPosition.isEmpty() || !d->yPosition.isEmpty())
 
  | 0 | ||||||||||||
| 533 |             d->item->setPos(posAt(step)); never executed:  d->item->setPos(posAt(step)); | 0 | ||||||||||||
| 534 |         if (!d->rotation.isEmpty()
  | 0 | ||||||||||||
| 535 |             || !d->verticalScale.isEmpty()
  | 0 | ||||||||||||
| 536 |             || !d->horizontalScale.isEmpty()
  | 0 | ||||||||||||
| 537 |             || !d->verticalShear.isEmpty()
  | 0 | ||||||||||||
| 538 |             || !d->horizontalShear.isEmpty()
  | 0 | ||||||||||||
| 539 |             || !d->xTranslation.isEmpty()
  | 0 | ||||||||||||
| 540 |             || !d->yTranslation.isEmpty()) {
  | 0 | ||||||||||||
| 541 | d->item->setMatrix(d->startMatrix * matrixAt(step)); | - | ||||||||||||
| 542 |         } never executed:  end of block | 0 | ||||||||||||
| 543 |     } never executed:  end of block | 0 | ||||||||||||
| 544 | - | |||||||||||||
| 545 | afterAnimationStep(step); | - | ||||||||||||
| 546 | } never executed:  end of block | 0 | ||||||||||||
| 547 | - | |||||||||||||
| 548 | /*! | - | ||||||||||||
| 549 | Resets the item to its starting position and transformation. | - | ||||||||||||
| 550 | - | |||||||||||||
| 551 | \obsolete | - | ||||||||||||
| 552 | - | |||||||||||||
| 553 | You can call setStep(0) instead. | - | ||||||||||||
| 554 | */ | - | ||||||||||||
| 555 | void QGraphicsItemAnimation::reset() | - | ||||||||||||
| 556 | { | - | ||||||||||||
| 557 |     if (!d->item)
  | 0 | ||||||||||||
| 558 |         return; never executed:  return; | 0 | ||||||||||||
| 559 | d->startPos = d->item->pos(); | - | ||||||||||||
| 560 | d->startMatrix = d->item->matrix(); | - | ||||||||||||
| 561 | } never executed:  end of block | 0 | ||||||||||||
| 562 | - | |||||||||||||
| 563 | /*! | - | ||||||||||||
| 564 | \fn void QGraphicsItemAnimation::beforeAnimationStep(qreal step) | - | ||||||||||||
| 565 | - | |||||||||||||
| 566 | This method is meant to be overridden by subclassed that needs to | - | ||||||||||||
| 567 | execute additional code before a new step takes place. The | - | ||||||||||||
| 568 | animation \a step is provided for use in cases where the action | - | ||||||||||||
| 569 | depends on its value. | - | ||||||||||||
| 570 | */ | - | ||||||||||||
| 571 | void QGraphicsItemAnimation::beforeAnimationStep(qreal step) | - | ||||||||||||
| 572 | { | - | ||||||||||||
| 573 | Q_UNUSED(step); | - | ||||||||||||
| 574 | } never executed:  end of block | 0 | ||||||||||||
| 575 | - | |||||||||||||
| 576 | /*! | - | ||||||||||||
| 577 | \fn void QGraphicsItemAnimation::afterAnimationStep(qreal step) | - | ||||||||||||
| 578 | - | |||||||||||||
| 579 | This method is meant to be overridden in subclasses that need to | - | ||||||||||||
| 580 | execute additional code after a new step has taken place. The | - | ||||||||||||
| 581 | animation \a step is provided for use in cases where the action | - | ||||||||||||
| 582 | depends on its value. | - | ||||||||||||
| 583 | */ | - | ||||||||||||
| 584 | void QGraphicsItemAnimation::afterAnimationStep(qreal step) | - | ||||||||||||
| 585 | { | - | ||||||||||||
| 586 | Q_UNUSED(step); | - | ||||||||||||
| 587 | } never executed:  end of block | 0 | ||||||||||||
| 588 | - | |||||||||||||
| 589 | QT_END_NAMESPACE | - | ||||||||||||
| 590 | - | |||||||||||||
| 591 | #include "moc_qgraphicsitemanimation.cpp" | - | ||||||||||||
| 592 | - | |||||||||||||
| 593 | #endif // QT_NO_GRAPHICSVIEW | - | ||||||||||||
| Source code | Switch to Preprocessed file |