diff options
author | Erik Larsson <erik@ortogonal.com> | 2013-12-11 07:22:49 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-07 14:44:50 +0100 |
commit | 4b9a44274563b8cc0a9d98f86893df3f31f01307 (patch) | |
tree | 953c40be8ec6025a801820041d8201729d797bb7 /src/quick/items/qquicktranslate.cpp | |
parent | 34793538fbbfce733da1d8495b7f2ed05c5e9a8b (diff) |
Add QQuickMatrix4x4, a way to specify a matrix transform in QML.
Add QQuickMatrix4x4 which makes it possible to specify a 4x4
matrix tranformation directly in QML instead of decomposing the
transformation into rotation, scale etc. It does NOT replace anything,
just adds a new way of specifying a tranformation of an Item.
Change-Id: I1b123778d1d458dfe4314cdb4f0fc99fd8a4c86a
Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'src/quick/items/qquicktranslate.cpp')
-rw-r--r-- | src/quick/items/qquicktranslate.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/quick/items/qquicktranslate.cpp b/src/quick/items/qquicktranslate.cpp index f1b716cf5b..5c61fb33f8 100644 --- a/src/quick/items/qquicktranslate.cpp +++ b/src/quick/items/qquicktranslate.cpp @@ -458,4 +458,79 @@ void QQuickRotation::applyTo(QMatrix4x4 *matrix) const matrix->translate(-d->origin); } +class QQuickMatrix4x4Private : public QQuickTransformPrivate +{ +public: + QQuickMatrix4x4Private() + : matrix() {} + QMatrix4x4 matrix; +}; + +/*! + \qmltype Matrix4x4 + \instantiates QQuickMatrix4x4 + \inqmlmodule QtQuick + \ingroup qtquick-visual-transforms + \brief Provides a way to apply a 4x4 tranformation matrix to an \l Item + + The Matrix4x4 type provides a way to apply a transformation to an + \l Item through a 4x4 matrix. + + It allows for a combination of rotation, scale, translatation and shearing + by using just one tranformation provided in a 4x4-matrix. + + The following example rotates a Rectangle 45 degress (PI/4): + + \qml + Rectangle { + width: 100 + height: 100 + color: "red" + + transform: Matrix4x4 { + property real a: Math.PI / 4 + matrix: Qt.matrix4x4(Math.cos(a), -Math.sin(a), 0, 0, + Math.sin(a), Math.cos(a), 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1) + } + } + \endqml +*/ +QQuickMatrix4x4::QQuickMatrix4x4(QObject *parent) + : QQuickTransform(*new QQuickMatrix4x4Private, parent) +{ +} + +QQuickMatrix4x4::~QQuickMatrix4x4() +{ +} + +/*! + \qmlproperty QMatrix4x4 QtQuick::Matrix4x4::matrix + + 4x4-matrix which will be used in the tranformation of an \l Item +*/ +QMatrix4x4 QQuickMatrix4x4::matrix() const +{ + Q_D(const QQuickMatrix4x4); + return d->matrix; +} + +void QQuickMatrix4x4::setMatrix(const QMatrix4x4 &matrix) +{ + Q_D(QQuickMatrix4x4); + if (d->matrix == matrix) + return; + d->matrix = matrix; + update(); + emit matrixChanged(); +} + +void QQuickMatrix4x4::applyTo(QMatrix4x4 *matrix) const +{ + Q_D(const QQuickMatrix4x4); + *matrix *= d->matrix; +} + QT_END_NAMESPACE |