QGraphicsItemAnimation: save some string data (text size -= 1K)
Also changed the 'step' range check to treat NaNs as invalid, too. Change-Id: I993c5efffcf7140fba8f80a7db499cd2335867e0 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
This commit is contained in:
parent
6a63554bf8
commit
d0b419e355
@ -97,6 +97,15 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
static inline bool check_step_valid(qreal step, const char *method)
|
||||||
|
{
|
||||||
|
if (!(step >= 0 && step <= 1)) {
|
||||||
|
qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
class QGraphicsItemAnimationPrivate
|
class QGraphicsItemAnimationPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -169,10 +178,8 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair>
|
|||||||
|
|
||||||
void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method)
|
void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method)
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0) {
|
if (!check_step_valid(step, method))
|
||||||
qWarning("QGraphicsItemAnimation::%s: invalid step = %f", method, step);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Pair pair(step, value);
|
Pair pair(step, value);
|
||||||
|
|
||||||
@ -259,9 +266,7 @@ void QGraphicsItemAnimation::setTimeLine(QTimeLine *timeLine)
|
|||||||
*/
|
*/
|
||||||
QPointF QGraphicsItemAnimation::posAt(qreal step) const
|
QPointF QGraphicsItemAnimation::posAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "posAt");
|
||||||
qWarning("QGraphicsItemAnimation::posAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()),
|
return QPointF(d->linearValueForStep(step, &d->xPosition, d->startPos.x()),
|
||||||
d->linearValueForStep(step, &d->yPosition, d->startPos.y()));
|
d->linearValueForStep(step, &d->yPosition, d->startPos.y()));
|
||||||
}
|
}
|
||||||
@ -298,8 +303,7 @@ QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::posList() const
|
|||||||
*/
|
*/
|
||||||
QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const
|
QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "matrixAt");
|
||||||
qWarning("QGraphicsItemAnimation::matrixAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
QMatrix matrix;
|
QMatrix matrix;
|
||||||
if (!d->rotation.isEmpty())
|
if (!d->rotation.isEmpty())
|
||||||
@ -320,9 +324,7 @@ QMatrix QGraphicsItemAnimation::matrixAt(qreal step) const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::rotationAt(qreal step) const
|
qreal QGraphicsItemAnimation::rotationAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "rotationAt");
|
||||||
qWarning("QGraphicsItemAnimation::rotationAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->rotation);
|
return d->linearValueForStep(step, &d->rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,9 +359,7 @@ QList<QPair<qreal, qreal> > QGraphicsItemAnimation::rotationList() const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const
|
qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "xTranslationAt");
|
||||||
qWarning("QGraphicsItemAnimation::xTranslationAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->xTranslation);
|
return d->linearValueForStep(step, &d->xTranslation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,9 +370,7 @@ qreal QGraphicsItemAnimation::xTranslationAt(qreal step) const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const
|
qreal QGraphicsItemAnimation::yTranslationAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "yTranslationAt");
|
||||||
qWarning("QGraphicsItemAnimation::yTranslationAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->yTranslation);
|
return d->linearValueForStep(step, &d->yTranslation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -409,8 +407,7 @@ QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::translationList() const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const
|
qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "verticalScaleAt");
|
||||||
qWarning("QGraphicsItemAnimation::verticalScaleAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->verticalScale, 1);
|
return d->linearValueForStep(step, &d->verticalScale, 1);
|
||||||
}
|
}
|
||||||
@ -422,9 +419,7 @@ qreal QGraphicsItemAnimation::verticalScaleAt(qreal step) const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const
|
qreal QGraphicsItemAnimation::horizontalScaleAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "horizontalScaleAt");
|
||||||
qWarning("QGraphicsItemAnimation::horizontalScaleAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->horizontalScale, 1);
|
return d->linearValueForStep(step, &d->horizontalScale, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,9 +456,7 @@ QList<QPair<qreal, QPointF> > QGraphicsItemAnimation::scaleList() const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const
|
qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "verticalShearAt");
|
||||||
qWarning("QGraphicsItemAnimation::verticalShearAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->verticalShear, 0);
|
return d->linearValueForStep(step, &d->verticalShear, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,9 +467,7 @@ qreal QGraphicsItemAnimation::verticalShearAt(qreal step) const
|
|||||||
*/
|
*/
|
||||||
qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const
|
qreal QGraphicsItemAnimation::horizontalShearAt(qreal step) const
|
||||||
{
|
{
|
||||||
if (step < 0.0 || step > 1.0)
|
check_step_valid(step, "horizontalShearAt");
|
||||||
qWarning("QGraphicsItemAnimation::horizontalShearAt: invalid step = %f", step);
|
|
||||||
|
|
||||||
return d->linearValueForStep(step, &d->horizontalShear, 0);
|
return d->linearValueForStep(step, &d->horizontalShear, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,19 +520,17 @@ void QGraphicsItemAnimation::clear()
|
|||||||
Sets the current \a step value for the animation, causing the
|
Sets the current \a step value for the animation, causing the
|
||||||
transformations scheduled at this step to be performed.
|
transformations scheduled at this step to be performed.
|
||||||
*/
|
*/
|
||||||
void QGraphicsItemAnimation::setStep(qreal x)
|
void QGraphicsItemAnimation::setStep(qreal step)
|
||||||
{
|
{
|
||||||
if (x < 0.0 || x > 1.0) {
|
if (!check_step_valid(step, "setStep"))
|
||||||
qWarning("QGraphicsItemAnimation::setStep: invalid step = %f", x);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
beforeAnimationStep(x);
|
beforeAnimationStep(step);
|
||||||
|
|
||||||
d->step = x;
|
d->step = step;
|
||||||
if (d->item) {
|
if (d->item) {
|
||||||
if (!d->xPosition.isEmpty() || !d->yPosition.isEmpty())
|
if (!d->xPosition.isEmpty() || !d->yPosition.isEmpty())
|
||||||
d->item->setPos(posAt(x));
|
d->item->setPos(posAt(step));
|
||||||
if (!d->rotation.isEmpty()
|
if (!d->rotation.isEmpty()
|
||||||
|| !d->verticalScale.isEmpty()
|
|| !d->verticalScale.isEmpty()
|
||||||
|| !d->horizontalScale.isEmpty()
|
|| !d->horizontalScale.isEmpty()
|
||||||
@ -549,11 +538,11 @@ void QGraphicsItemAnimation::setStep(qreal x)
|
|||||||
|| !d->horizontalShear.isEmpty()
|
|| !d->horizontalShear.isEmpty()
|
||||||
|| !d->xTranslation.isEmpty()
|
|| !d->xTranslation.isEmpty()
|
||||||
|| !d->yTranslation.isEmpty()) {
|
|| !d->yTranslation.isEmpty()) {
|
||||||
d->item->setMatrix(d->startMatrix * matrixAt(x));
|
d->item->setMatrix(d->startMatrix * matrixAt(step));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterAnimationStep(x);
|
afterAnimationStep(step);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user