void QGraphicsTranslation3D::setTranslate(const QVector3D &value) { Q_D(QGraphicsTranslation3D); if (d->translate != value) { d->translate = value; emit transformChanged(); emit translateChanged(); } }
void QGraphicsTranslation3D::setZTranslate(qreal value) { Q_D(QGraphicsTranslation3D); if (d->translate.z() != value) { d->translate.setZ(value); update(); emit translateChanged(); } }
void tst_QGraphicsTransform3D::translation3D() { QGraphicsTranslation3D translate1; QVERIFY(translate1.translate() == QVector3D(0, 0, 0)); QCOMPARE(translate1.xTranslate(), qreal(0.0f)); QCOMPARE(translate1.yTranslate(), qreal(0.0f)); QCOMPARE(translate1.zTranslate(), qreal(0.0f)); QCOMPARE(translate1.progress(), qreal(1.0f)); QSignalSpy spy1(&translate1, SIGNAL(translateChanged())); QSignalSpy spy2(&translate1, SIGNAL(progressChanged())); translate1.setTranslate(QVector3D(4, -6, 0.5f)); translate1.setProgress(2.0f); QVERIFY(translate1.translate() == QVector3D(4, -6, 0.5f)); QCOMPARE(translate1.xTranslate(), qreal(4.0f)); QCOMPARE(translate1.yTranslate(), qreal(-6.0f)); QCOMPARE(translate1.zTranslate(), qreal(0.5f)); QCOMPARE(translate1.progress(), qreal(2.0f)); QCOMPARE(spy1.size(), 1); QCOMPARE(spy2.size(), 1); QMatrix4x4 m1; translate1.applyTo(&m1); QMatrix4x4 m2; m2.translate(QVector3D(8, -12, 1)); QVERIFY(isSameMatrix(m1, m2)); translate1.setXTranslate(20); QCOMPARE(spy1.size(), 2); translate1.setYTranslate(-4); QCOMPARE(spy1.size(), 3); translate1.setZTranslate(42); QCOMPARE(spy1.size(), 4); translate1.setProgress(0.5f); QCOMPARE(spy2.size(), 2); QVERIFY(translate1.translate() == QVector3D(20, -4, 42)); QCOMPARE(translate1.progress(), qreal(0.5f)); }
void Item3dPrivate::pretransform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *item) { Item3d *object = qobject_cast<Item3d *>(list->object); QList<QGraphicsTransform *> *ptrans; if (object) { ptrans = &object->d->pretransforms; //We now need to connect the underlying transform so that any change will update the graphical item. if (!ptrans->contains(item)) { ptrans->append(item); if (qobject_cast<QGraphicsScale *>(item)) { QObject::connect(item, SIGNAL(originChanged()), object, SLOT(update())); QObject::connect(item, SIGNAL(scaleChanged()), object, SLOT(update())); } else if (qobject_cast<QGraphicsRotation *>(item)) { QObject::connect(item, SIGNAL(originChanged()), object, SLOT(update())); QObject::connect(item, SIGNAL(angleChanged()), object, SLOT(update())); QObject::connect(item, SIGNAL(axisChanged()), object, SLOT(update())); } else if (qobject_cast<QGraphicsScale3D *>(item)) { QObject::connect(item, SIGNAL(originChanged()), object, SLOT(update())); QObject::connect(item, SIGNAL(scaleChanged()), object, SLOT(update())); } else if (qobject_cast<QGraphicsTranslation3D *>(item)) { QObject::connect(item, SIGNAL(translateChanged()), object, SLOT(update())); } else if (qobject_cast<QGraphicsFaceCamera *>(item)) { QObject::connect(item, SIGNAL(preserveUpVectorChanged()), object, SLOT(update())); } } } else qWarning()<<"Warning: could not find Item3d to add transformation to."; }