qgraphicsitemanimation.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/graphicsview/qgraphicsitemanimation.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10static inline bool check_step_valid(qreal step, const char *method)-
11{-
12 if (!(step >= 0
step >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& step <= 1
step <= 1Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
13 QMessageLogger(__FILE__, 101, __PRETTY_FUNCTION__).warning("QGraphicsItemAnimation::%s: invalid step = %f", method, step);-
14 return
never executed: return false;
false;
never executed: return false;
0
15 }-
16 return
never executed: return true;
true;
never executed: return true;
0
17}-
18-
19class QGraphicsItemAnimationPrivate-
20{-
21public:-
22 inline QGraphicsItemAnimationPrivate()-
23 : q(0), timeLine(0), item(0), step(0)-
24 { }
never executed: end of block
0
25-
26 QGraphicsItemAnimation *q;-
27-
28 QPointer<QTimeLine> timeLine;-
29 QGraphicsItem *item;-
30-
31 QPointF startPos;-
32 QMatrix startMatrix;-
33-
34 qreal step;-
35-
36 struct Pair {-
37 bool operator <(const Pair &other) const-
38 { return
never executed: return step < other.step;
step < other.step;
never executed: return step < other.step;
}
0
39 bool operator==(const Pair &other) const-
40 { return
never executed: return step == other.step;
step == other.step;
never executed: return step == other.step;
}
0
41 qreal step;-
42 qreal value;-
43 };-
44 QVector<Pair> xPosition;-
45 QVector<Pair> yPosition;-
46 QVector<Pair> rotation;-
47 QVector<Pair> verticalScale;-
48 QVector<Pair> horizontalScale;-
49 QVector<Pair> verticalShear;-
50 QVector<Pair> horizontalShear;-
51 QVector<Pair> xTranslation;-
52 QVector<Pair> yTranslation;-
53-
54 qreal linearValueForStep(qreal step, const QVector<Pair> &source, qreal defaultValue = 0);-
55 void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method);-
56};-
57template<> class QTypeInfo<QGraphicsItemAnimationPrivate::Pair > { public: enum { isComplex = (((Q_PRIMITIVE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_PRIMITIVE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_PRIMITIVE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QGraphicsItemAnimationPrivate::Pair)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QGraphicsItemAnimationPrivate::Pair >::value, isDummy = (((Q_PRIMITIVE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QGraphicsItemAnimationPrivate::Pair) }; static inline const char *name() { return "QGraphicsItemAnimationPrivate::Pair"; } };-
58-
59qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, const QVector<Pair> &source, qreal defaultValue)-
60{-
61 if (source.isEmpty()
source.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
62 return
never executed: return defaultValue;
defaultValue;
never executed: return defaultValue;
0
63 step = qMin<qreal>(qMax<qreal>(step, 0), 1);-
64-
65 if (step == 1
step == 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
66 return
never executed: return source.back().value;
source.back().value;
never executed: return source.back().value;
0
67-
68 qreal stepBefore = 0;-
69 qreal stepAfter = 1;-
70 qreal valueBefore = source.front().step == 0
source.front().step == 0Description
TRUEnever evaluated
FALSEnever evaluated
? source.front().value : defaultValue;
0
71 qreal valueAfter = source.back().value;-
72-
73-
74 for (int i = 0; i < source.size()
i < source.size()Description
TRUEnever evaluated
FALSEnever evaluated
&& step >= source[i].step
step >= source[i].stepDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
75 stepBefore = source[i].step;-
76 valueBefore = source[i].value;-
77 }
never executed: end of block
0
78-
79-
80 for (int i = source.size() - 1; i >= 0
i >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& step < source[i].step
step < source[i].stepDescription
TRUEnever evaluated
FALSEnever evaluated
; --i) {
0
81 stepAfter = source[i].step;-
82 valueAfter = source[i].value;-
83 }
never executed: end of block
0
84-
85-
86 return
never executed: return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore));
valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore));
never executed: return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore));
0
87}-
88-
89void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method)-
90{-
91 if (!check_step_valid(step, method)
!check_step_va...(step, method)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
92 return;
never executed: return;
0
93-
94 const Pair pair = { step, value };-
95-
96 const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair);-
97 if (result == binList->end()
result == binList->end()Description
TRUEnever evaluated
FALSEnever evaluated
|| pair < *result
pair < *resultDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
98 binList->insert(result, pair);
never executed: binList->insert(result, pair);
0
99 else-
100 result->value = value;
never executed: result->value = value;
0
101}-
102-
103-
104-
105-
106QGraphicsItemAnimation::QGraphicsItemAnimation(QObject *parent)-
107 : QObject(parent), d(new QGraphicsItemAnimationPrivate)-
108{-
109 d->q = this;-
110}
never executed: end of block
0
111-
112-
113-
114-
115QGraphicsItemAnimation::~QGraphicsItemAnimation()-
116{-
117 delete d;-
118}
never executed: end of block
0
119-
120-
121-
122-
123-
124-
125QGraphicsItem *QGraphicsItemAnimation::item() const-
126{-
127 return
never executed: return d->item;
d->item;
never executed: return d->item;
0
128}-
129-
130-
131-
132-
133-
134-
135void QGraphicsItemAnimation::setItem(QGraphicsItem *item)-
136{-
137 d->item = item;-
138 d->startPos = d->item->pos();-
139}
never executed: end of block
0
140-
141-
142-
143-
144-
145-
146-
147QTimeLine *QGraphicsItemAnimation::timeLine() const-
148{-
149 return
never executed: return d->timeLine;
d->timeLine;
never executed: return d->timeLine;
0
150}-
151-
152-
153-
154-
155-
156-
157-
158void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine)-
159{-
160 if (d->timeLine == timeLine
d->timeLine == timeLineDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
161 return;
never executed: return;
0
162 if (d->timeLine
d->timeLineDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
163 delete d->timeLine;
never executed: delete d->timeLine;
0
164 if (!timeLine
!timeLineDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
165 return;
never executed: return;
0
166 d->timeLine = timeLine;-
167 connect(timeLine, qFlagLocation("2""valueChanged(qreal)" "\0" __FILE__ ":" "255"), this, qFlagLocation("1""setStep(qreal)" "\0" __FILE__ ":" "255"));-
168}
never executed: end of block
0
169-
170-
171-
172-
173-
174-
175QPointF QGraphicsItemAnimation::posAt(qreal step) const-
176{-
177 check_step_valid(step, "posAt");-
178 return
never executed: return QPointF(d->linearValueForStep(step, d->xPosition, d->startPos.x()), d->linearValueForStep(step, d->yPosition, d->startPos.y()));
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
179 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
180}-
181void QGraphicsItemAnimation::setPosAt(qreal step, const QPointF &pos)-
182{-
183 d->insertUniquePair(step, pos.x(), &d->xPosition, "setPosAt");-
184 d->insertUniquePair(step, pos.y(), &d->yPosition, "setPosAt");-
185}
never executed: end of block
0
186-
187-
188-
189-
190-
191-
192QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const-
193{-
194 QList<QPair<qreal, QPointF> > list;-
195 const int xPosCount = d->xPosition.size();-
196 list.reserve(xPosCount);-
197 for (int i = 0; i < xPosCount
i < xPosCountDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
198 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
199-
200 return
never executed: return list;
list;
never executed: return list;
0
201}-
202-
203-
204-
205-
206QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const-
207{-
208 check_step_valid(step, "matrixAt");-
209-
210 QMatrix matrix;-
211 if (!d->rotation.isEmpty()
!d->rotation.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
212 matrix.rotate(rotationAt(step));
never executed: matrix.rotate(rotationAt(step));
0
213 if (!d->verticalScale.isEmpty()
!d->verticalScale.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
214 matrix.scale(horizontalScaleAt(step), verticalScaleAt(step));
never executed: matrix.scale(horizontalScaleAt(step), verticalScaleAt(step));
0
215 if (!d->verticalShear.isEmpty()
!d->verticalShear.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
216 matrix.shear(horizontalShearAt(step), verticalShearAt(step));
never executed: matrix.shear(horizontalShearAt(step), verticalShearAt(step));
0
217 if (!d->xTranslation.isEmpty()
!d->xTranslation.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
218 matrix.translate(xTranslationAt(step), yTranslationAt(step));
never executed: matrix.translate(xTranslationAt(step), yTranslationAt(step));
0
219 return
never executed: return matrix;
matrix;
never executed: return matrix;
0
220}-
221-
222-
223-
224-
225-
226-
227qreal QGraphicsItemAnimation::rotationAt(qreal step) const-
228{-
229 check_step_valid(step, "rotationAt");-
230 return
never executed: return d->linearValueForStep(step, d->rotation);
d->linearValueForStep(step, d->rotation);
never executed: return d->linearValueForStep(step, d->rotation);
0
231}-
232-
233-
234-
235-
236-
237-
238void QGraphicsItemAnimation::setRotationAt(qreal step, qreal angle)-
239{-
240 d->insertUniquePair(step, angle, &d->rotation, "setRotationAt");-
241}
never executed: end of block
0
242-
243-
244-
245-
246-
247-
248QList<QPair<qreal, qreal> > QGraphicsItemAnimation::rotationList() const-
249{-
250 QList<QPair<qreal, qreal> > list;-
251 const int numRotations = d->rotation.size();-
252 list.reserve(numRotations);-
253 for (int i = 0; i < numRotations
i < numRotationsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
254 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
255-
256 return
never executed: return list;
list;
never executed: return list;
0
257}-
258-
259-
260-
261-
262-
263-
264qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const-
265{-
266 check_step_valid(step, "xTranslationAt");-
267 return
never executed: return d->linearValueForStep(step, d->xTranslation);
d->linearValueForStep(step, d->xTranslation);
never executed: return d->linearValueForStep(step, d->xTranslation);
0
268}-
269-
270-
271-
272-
273-
274-
275qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const-
276{-
277 check_step_valid(step, "yTranslationAt");-
278 return
never executed: return d->linearValueForStep(step, d->yTranslation);
d->linearValueForStep(step, d->yTranslation);
never executed: return d->linearValueForStep(step, d->yTranslation);
0
279}-
280-
281-
282-
283-
284-
285-
286-
287void QGraphicsItemAnimation::setTranslationAt(qreal step, qreal dx, qreal dy)-
288{-
289 d->insertUniquePair(step, dx, &d->xTranslation, "setTranslationAt");-
290 d->insertUniquePair(step, dy, &d->yTranslation, "setTranslationAt");-
291}
never executed: end of block
0
292-
293-
294-
295-
296-
297-
298QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::translationList() const-
299{-
300 QList<QPair<qreal, QPointF> > list;-
301 const int numTranslations = d->xTranslation.size();-
302 list.reserve(numTranslations);-
303 for (int i = 0; i < numTranslations
i < numTranslationsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
304 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
305-
306 return
never executed: return list;
list;
never executed: return list;
0
307}-
308-
309-
310-
311-
312-
313-
314qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const-
315{-
316 check_step_valid(step, "verticalScaleAt");-
317-
318 return
never executed: return d->linearValueForStep(step, d->verticalScale, 1);
d->linearValueForStep(step, d->verticalScale, 1);
never executed: return d->linearValueForStep(step, d->verticalScale, 1);
0
319}-
320-
321-
322-
323-
324-
325-
326qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const-
327{-
328 check_step_valid(step, "horizontalScaleAt");-
329 return
never executed: return d->linearValueForStep(step, d->horizontalScale, 1);
d->linearValueForStep(step, d->horizontalScale, 1);
never executed: return d->linearValueForStep(step, d->horizontalScale, 1);
0
330}-
331-
332-
333-
334-
335-
336-
337-
338void QGraphicsItemAnimation::setScaleAt(qreal step, qreal sx, qreal sy)-
339{-
340 d->insertUniquePair(step, sx, &d->horizontalScale, "setScaleAt");-
341 d->insertUniquePair(step, sy, &d->verticalScale, "setScaleAt");-
342}
never executed: end of block
0
343-
344-
345-
346-
347-
348-
349QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::scaleList() const-
350{-
351 QList<QPair<qreal, QPointF> > list;-
352 const int numScales = d->horizontalScale.size();-
353 list.reserve(numScales);-
354 for (int i = 0; i < numScales
i < numScalesDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
355 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
356-
357 return
never executed: return list;
list;
never executed: return list;
0
358}-
359-
360-
361-
362-
363-
364-
365qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const-
366{-
367 check_step_valid(step, "verticalShearAt");-
368 return
never executed: return d->linearValueForStep(step, d->verticalShear, 0);
d->linearValueForStep(step, d->verticalShear, 0);
never executed: return d->linearValueForStep(step, d->verticalShear, 0);
0
369}-
370-
371-
372-
373-
374-
375-
376qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const-
377{-
378 check_step_valid(step, "horizontalShearAt");-
379 return
never executed: return d->linearValueForStep(step, d->horizontalShear, 0);
d->linearValueForStep(step, d->horizontalShear, 0);
never executed: return d->linearValueForStep(step, d->horizontalShear, 0);
0
380}-
381-
382-
383-
384-
385-
386-
387-
388void QGraphicsItemAnimation::setShearAt(qreal step, qreal sh, qreal sv)-
389{-
390 d->insertUniquePair(step, sh, &d->horizontalShear, "setShearAt");-
391 d->insertUniquePair(step, sv, &d->verticalShear, "setShearAt");-
392}
never executed: end of block
0
393-
394-
395-
396-
397-
398-
399QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::shearList() const-
400{-
401 QList<QPair<qreal, QPointF> > list;-
402 const int numShears = d->horizontalShear.size();-
403 list.reserve(numShears);-
404 for (int i = 0; i < numShears
i < numShearsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
405 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
406-
407 return
never executed: return list;
list;
never executed: return list;
0
408}-
409-
410-
411-
412-
413-
414void QGraphicsItemAnimation::clear()-
415{-
416 d->xPosition.clear();-
417 d->yPosition.clear();-
418 d->rotation.clear();-
419 d->verticalScale.clear();-
420 d->horizontalScale.clear();-
421 d->verticalShear.clear();-
422 d->horizontalShear.clear();-
423 d->xTranslation.clear();-
424 d->yTranslation.clear();-
425}
never executed: end of block
0
426-
427-
428-
429-
430-
431-
432-
433void QGraphicsItemAnimation::setStep(qreal step)-
434{-
435 if (!check_step_valid(step, "setStep")
!check_step_va...ep, "setStep")Description
TRUEnever evaluated
FALSEnever evaluated
)
0
436 return;
never executed: return;
0
437-
438 beforeAnimationStep(step);-
439-
440 d->step = step;-
441 if (d->item
d->itemDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
442 if (!d->xPosition.isEmpty()
!d->xPosition.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| !d->yPosition.isEmpty()
!d->yPosition.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
443 d->item->setPos(posAt(step));
never executed: d->item->setPos(posAt(step));
0
444 if (!d->rotation.isEmpty()
!d->rotation.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
445 || !d->verticalScale.isEmpty()
!d->verticalScale.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
446 || !d->horizontalScale.isEmpty()
!d->horizontalScale.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
447 || !d->verticalShear.isEmpty()
!d->verticalShear.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
448 || !d->horizontalShear.isEmpty()
!d->horizontalShear.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
449 || !d->xTranslation.isEmpty()
!d->xTranslation.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
450 || !d->yTranslation.isEmpty()
!d->yTranslation.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
451 d->item->setMatrix(d->startMatrix * matrixAt(step));-
452 }
never executed: end of block
0
453 }
never executed: end of block
0
454-
455 afterAnimationStep(step);-
456}
never executed: end of block
0
457void QGraphicsItemAnimation::reset()-
458{-
459 if (!d->item
!d->itemDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
460 return;
never executed: return;
0
461 d->startPos = d->item->pos();-
462 d->startMatrix = d->item->matrix();-
463}
never executed: end of block
0
464void QGraphicsItemAnimation::beforeAnimationStep(qreal step)-
465{-
466 (void)step;;-
467}
never executed: end of block
0
468void QGraphicsItemAnimation::afterAnimationStep(qreal step)-
469{-
470 (void)step;;-
471}
never executed: end of block
0
472-
473-
474-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9