summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/declarative/fx/qfxflipable.cpp2
-rw-r--r--src/declarative/fx/qfxtransform.cpp202
-rw-r--r--src/declarative/fx/qfxtransform.h22
3 files changed, 137 insertions, 89 deletions
diff --git a/src/declarative/fx/qfxflipable.cpp b/src/declarative/fx/qfxflipable.cpp
index 1d15827..81ed750 100644
--- a/src/declarative/fx/qfxflipable.cpp
+++ b/src/declarative/fx/qfxflipable.cpp
@@ -58,7 +58,7 @@ public:
QFxItem *front;
QFxItem *back;
QFxAxis *axis;
- QFxRotation axisRotation;
+ QFxRotation3D axisRotation;
qreal rotation;
};
diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp
index c355158..2bed170 100644
--- a/src/declarative/fx/qfxtransform.cpp
+++ b/src/declarative/fx/qfxtransform.cpp
@@ -178,8 +178,8 @@ void QFxAxis::setEndZ(qreal z)
}
/*!
- \qmlclass AxisRotation
- \brief The AxisRotation element provides a way to rotate an Item around an axis.
+ \qmlclass Rotation3D
+ \brief The Rotation3D element provides a way to rotate an Item around an axis.
Here is an example of various rotations applied to an \l Image.
\code
@@ -187,22 +187,22 @@ void QFxAxis::setEndZ(qreal z)
<Image src="qt.png"/>
<Image src="qt.png">
<transform>
- <AxisRotation axis.startX="30" axis.endX="30" axis.endY="60" angle="18"/>
+ <Rotation3D axis.startX="30" axis.endX="30" axis.endY="60" angle="18"/>
</transform>
</Image>
<Image src="qt.png">
<transform>
- <AxisRotation axis.startX="30" axis.endX="30" axis.endY="60" angle="36"/>
+ <Rotation3D axis.startX="30" axis.endX="30" axis.endY="60" angle="36"/>
</transform>
</Image>
<Image src="qt.png">
<transform>
- <AxisRotation axis.startX="30" axis.endX="30" axis.endY="60" angle="54"/>
+ <Rotation3D axis.startX="30" axis.endX="30" axis.endY="60" angle="54"/>
</transform>
</Image>
<Image src="qt.png">
<transform>
- <AxisRotation axis.startX="30" axis.endX="30" axis.endY="60" angle="72"/>
+ <Rotation3D axis.startX="30" axis.endX="30" axis.endY="60" angle="72"/>
</transform>
</Image>
</HorizontalLayout>
@@ -211,58 +211,58 @@ void QFxAxis::setEndZ(qreal z)
\image axisrotation.png
*/
-QML_DEFINE_TYPE(QFxRotation,AxisRotation);
+QML_DEFINE_TYPE(QFxRotation3D,Rotation3D);
-QFxRotation::QFxRotation(QObject *parent)
-: QFxTransform(parent), _angle(0), _distanceToPlane(1024.), _dirty(true)
+QFxRotation3D::QFxRotation3D(QObject *parent)
+: QFxTransform(parent), _angle(0), _dirty(true)
{
connect(&_axis, SIGNAL(updated()), this, SLOT(update()));
}
-QFxRotation::~QFxRotation()
+QFxRotation3D::~QFxRotation3D()
{
}
/*!
- \qmlproperty real AxisRotation::axis.startX
- \qmlproperty real AxisRotation::axis.startY
- \qmlproperty real AxisRotation::axis.endX
- \qmlproperty real AxisRotation::axis.endY
- \qmlproperty real AxisRotation::axis.endZ
+ \qmlproperty real Rotation3D::axis.startX
+ \qmlproperty real Rotation3D::axis.startY
+ \qmlproperty real Rotation3D::axis.endX
+ \qmlproperty real Rotation3D::axis.endY
+ \qmlproperty real Rotation3D::axis.endZ
A rotation axis is specified by 2 points in 3D space: a start point and
an end point. The z-position of the start point is assumed to be 0, and cannot
be changed.
*/
-QFxAxis *QFxRotation::axis()
+QFxAxis *QFxRotation3D::axis()
{
return &_axis;
}
/*!
- \qmlproperty real AxisRotation::angle
+ \qmlproperty real Rotation3D::angle
The angle, in degrees, to rotate around the specified axis.
*/
-qreal QFxRotation::angle() const
+qreal QFxRotation3D::angle() const
{
return _angle;
}
-void QFxRotation::setAngle(qreal angle)
+void QFxRotation3D::setAngle(qreal angle)
{
_angle = angle;
update();
}
-bool QFxRotation::isIdentity() const
+bool QFxRotation3D::isIdentity() const
{
return (_angle == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX());
}
#if defined(QFX_RENDER_QPAINTER)
const qreal inv_dist_to_plane = 1. / 1024.;
-QTransform QFxRotation::transform() const
+QTransform QFxRotation3D::transform() const
{
if (_dirty) {
_transform = QTransform();
@@ -282,10 +282,6 @@ QTransform QFxRotation::transform() const
qreal y = _axis.endY() - _axis.startY();
qreal z = _axis.endZ();
- qreal idtp = inv_dist_to_plane;
- if (distanceToPlane() != 1024.)
- idtp = 1. / distanceToPlane();
-
qreal len = x * x + y * y + z * z;
if (len != 1.) {
len = ::sqrt(len);
@@ -294,8 +290,8 @@ QTransform QFxRotation::transform() const
z /= len;
}
- QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*idtp,
- y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*idtp,
+ QTransform rot(x*x*(1-c)+c, x*y*(1-c)-z*s, x*z*(1-c)+y*s*inv_dist_to_plane,
+ y*x*(1-c)+z*s, y*y*(1-c)+c, y*z*(1-c)-x*s*inv_dist_to_plane,
0, 0, 1);
_transform *= rotTrans;
@@ -310,7 +306,7 @@ QTransform QFxRotation::transform() const
return _transform;
}
#elif defined(QFX_RENDER_OPENGL)
-QMatrix4x4 QFxRotation::transform() const
+QMatrix4x4 QFxRotation3D::transform() const
{
if (_dirty) {
_dirty = false;
@@ -333,21 +329,7 @@ QMatrix4x4 QFxRotation::transform() const
}
#endif
-/*!
- \qmlproperty real AxisRotation::distanceToPlane
-*/
-qreal QFxRotation::distanceToPlane() const
-{
- return _distanceToPlane;
-}
-
-void QFxRotation::setDistanceToPlane(qreal d)
-{
- _distanceToPlane = d;
- update();
-}
-
-void QFxRotation::update()
+void QFxRotation3D::update()
{
_dirty = true;
QFxItem *item = qobject_cast<QFxItem *>(parent());
@@ -356,77 +338,77 @@ void QFxRotation::update()
}
/*!
- \qmlclass AxisTranslation
- \brief The AxisTranslation element provides a way to move an Item along an axis.
+ \qmlclass Translation3D
+ \brief The Translation3D element provides a way to move an Item along an axis.
The following example translates the image to 10, 3.
\code
<Image src="logo.png">
<transform>
- <AxisTranslation axis.startX="0" axis.startY="0" axis.endX="1" axis.endY=".3" distance="10"/>
+ <Translation3D axis.startX="0" axis.startY="0" axis.endX="1" axis.endY=".3" distance="10"/>
</transform>
</Image>
\endcode
*/
-QML_DEFINE_TYPE(QFxTranslation,AxisTranslation);
+QML_DEFINE_TYPE(QFxTranslation3D,Translation3D);
-QFxTranslation::QFxTranslation(QObject *parent)
+QFxTranslation3D::QFxTranslation3D(QObject *parent)
: QFxTransform(parent), _distance(0), _dirty(true)
{
connect(&_axis, SIGNAL(updated()), this, SLOT(update()));
}
-QFxTranslation::~QFxTranslation()
+QFxTranslation3D::~QFxTranslation3D()
{
}
/*!
- \qmlproperty real AxisTranslation::axis.startX
- \qmlproperty real AxisTranslation::axis.startY
- \qmlproperty real AxisTranslation::axis.endX
- \qmlproperty real AxisTranslation::axis.endY
- \qmlproperty real AxisTranslation::axis.endZ
+ \qmlproperty real Translation3D::axis.startX
+ \qmlproperty real Translation3D::axis.startY
+ \qmlproperty real Translation3D::axis.endX
+ \qmlproperty real Translation3D::axis.endY
+ \qmlproperty real Translation3D::axis.endZ
A translation axis is specified by 2 points in 3D space: a start point and
an end point. The z-position of the start point is assumed to be 0, and cannot
be changed. Changing the z-position of the end point is only valid when running
under OpenGL.
*/
-QFxAxis *QFxTranslation::axis()
+QFxAxis *QFxTranslation3D::axis()
{
return &_axis;
}
/*!
- \qmlproperty real AxisTranslation::distance
+ \qmlproperty real Translation3D::distance
The distance to translate along the specified axis. distance is a multiplier;
in the example below, a distance of 1 would translate to 100, 50, while a distance
of 0.5 would translate to 50, 25.
\code
- <AxisTranslation axis.startX="0" axis.startY="0" axis.endX="100" axis.endY="50"/>
+ <Translation3D axis.startX="0" axis.startY="0" axis.endX="100" axis.endY="50"/>
\endcode
*/
-qreal QFxTranslation::distance() const
+qreal QFxTranslation3D::distance() const
{
return _distance;
}
-void QFxTranslation::setDistance(qreal distance)
+void QFxTranslation3D::setDistance(qreal distance)
{
_distance = distance;
update();
}
-bool QFxTranslation::isIdentity() const
+bool QFxTranslation3D::isIdentity() const
{
return (_distance == 0.) || (_axis.endZ() == 0. && _axis.endY() == _axis.startY() && _axis.endX() == _axis.startX());
}
#if defined(QFX_RENDER_QPAINTER)
-QTransform QFxTranslation::transform() const
+QTransform QFxTranslation3D::transform() const
{
if (_dirty) {
_transform = QTransform();
@@ -446,7 +428,7 @@ QTransform QFxTranslation::transform() const
return _transform;
}
#elif defined(QFX_RENDER_OPENGL)
-QMatrix4x4 QFxRotation::transform() const
+QMatrix4x4 QFxTranslation3D::transform() const
{
if (_dirty) {
_dirty = false;
@@ -465,7 +447,7 @@ QMatrix4x4 QFxRotation::transform() const
}
#endif
-void QFxTranslation::update()
+void QFxTranslation3D::update()
{
_dirty = true;
@@ -541,8 +523,62 @@ QMatrix4x4 QFxPerspective::transform() const
\qmlclass Squish
\brief The Squish element allows you to distort an items appearance by 'squishing' it.
- A Squish transform only affects an item when running under OpenGL; when running under software
- rasterization it has no effect.
+ Here is an example of various \l Image squishes.
+ \code
+ Rect {
+ id: Screen
+ width: 360; height: 80
+ color: "white"
+
+ HorizontalLayout {
+ margin: 10
+ spacing: 10
+ Image { src: "qt.png" }
+ Image {
+ src: "qt.png"
+ transform: Squish {
+ x:0; y:0; width:60; height:60
+ topLeftX:0; topLeftY:0
+ topRightX:50; topRightY:10
+ bottomLeftX:0; bottomLeftY:60
+ bottomRightX: 60; bottomRightY:60
+ }
+ }
+ Image {
+ src: "qt.png"
+ transform: Squish {
+ x:0; y:0; width:60; height:60
+ topLeftX:0; topLeftY:0
+ topRightX:50; topRightY:0
+ bottomLeftX:10; bottomLeftY:50
+ bottomRightX: 60; bottomRightY:60
+ }
+ }
+ Image {
+ src: "qt.png"
+ transform: Squish {
+ x:0; y:0; width:60; height:60
+ topLeftX:0; topLeftY:10
+ topRightX:60; topRightY:10
+ bottomLeftX:0; bottomLeftY:50
+ bottomRightX: 60; bottomRightY:50
+ }
+ }
+ Image {
+ src: "qt.png"
+ transform: Squish {
+ x:0; y:0; width:60; height:60
+ topLeftX:10; topLeftY:0
+ topRightX:50; topRightY:0
+ bottomLeftX:10; bottomLeftY:60
+ bottomRightX: 50; bottomRightY:60
+ }
+ }
+ }
+ }
+ \endcode
+
+ \image squish.png
*/
QML_DEFINE_TYPE(QFxSquish,Squish);
@@ -557,6 +593,11 @@ QFxSquish::~QFxSquish()
/*!
\qmlproperty real Squish::x
+ \qmlproperty real Squish::y
+ \qmlproperty real Squish::width
+ \qmlproperty real Squish::height
+
+ This is usually set to the original geometry of the item being squished.
*/
qreal QFxSquish::x() const
{
@@ -569,9 +610,6 @@ void QFxSquish::setX(qreal v)
update();
}
-/*!
- \qmlproperty real Squish::y
-*/
qreal QFxSquish::y() const
{
return p.y();
@@ -583,9 +621,6 @@ void QFxSquish::setY(qreal v)
update();
}
-/*!
- \qmlproperty real Squish::width
-*/
qreal QFxSquish::width() const
{
return s.width();
@@ -597,9 +632,6 @@ void QFxSquish::setWidth(qreal v)
update();
}
-/*!
- \qmlproperty real Squish::height
-*/
qreal QFxSquish::height() const
{
return s.height();
@@ -614,6 +646,8 @@ void QFxSquish::setHeight(qreal v)
/*!
\qmlproperty real Squish::topLeftX
\qmlproperty real Squish::topLeftY
+
+ The top left point for the squish.
*/
qreal QFxSquish::topLeft_x() const
{
@@ -640,6 +674,8 @@ void QFxSquish::settopLeft_y(qreal v)
/*!
\qmlproperty real Squish::topRightX
\qmlproperty real Squish::topRightY
+
+ The top right point for the squish.
*/
qreal QFxSquish::topRight_x() const
{
@@ -666,6 +702,8 @@ void QFxSquish::settopRight_y(qreal v)
/*!
\qmlproperty real Squish::bottomLeftX
\qmlproperty real Squish::bottomLeftY
+
+ The bottom left point for the squish.
*/
qreal QFxSquish::bottomLeft_x() const
{
@@ -692,6 +730,8 @@ void QFxSquish::setbottomLeft_y(qreal v)
/*!
\qmlproperty real Squish::bottomRightX
\qmlproperty real Squish::bottomRightY
+
+ The bottom right point for the squish.
*/
qreal QFxSquish::bottomRight_x() const
{
@@ -722,12 +762,24 @@ void QFxSquish::update()
item->updateTransform();
}
-#if defined(QFX_RENDER_OPENGL)
bool QFxSquish::isIdentity() const
{
return false;
}
+#if defined(QFX_RENDER_QPAINTER)
+QTransform QFxSquish::transform() const
+{
+ QPolygonF poly;
+ poly << p << QPointF(p.x() + s.width(), p.y()) << QPointF(p.x() + s.width(), p.y() + s.height()) << QPointF(p.x(), p.y() + s.height());
+ QPolygonF poly2;
+ poly2 << p1 << p2 << p4 << p3;
+
+ QTransform t;
+ QTransform::quadToQuad(poly, poly2, t);
+ return t;
+}
+#elif defined(QFX_RENDER_OPENGL)
QMatrix4x4 QFxSquish::transform() const
{
QPolygonF poly;
diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h
index 8a4eab1..14bce9b 100644
--- a/src/declarative/fx/qfxtransform.h
+++ b/src/declarative/fx/qfxtransform.h
@@ -109,16 +109,15 @@ private:
};
QML_DECLARE_TYPE(QFxAxis);
-class Q_DECLARATIVE_EXPORT QFxRotation : public QFxTransform
+class Q_DECLARATIVE_EXPORT QFxRotation3D : public QFxTransform
{
Q_OBJECT
Q_PROPERTY(QFxAxis *axis READ axis)
Q_PROPERTY(qreal angle READ angle WRITE setAngle)
- Q_PROPERTY(qreal distanceToPlane READ distanceToPlane WRITE setDistanceToPlane)
public:
- QFxRotation(QObject *parent=0);
- ~QFxRotation();
+ QFxRotation3D(QObject *parent=0);
+ ~QFxRotation3D();
QFxAxis *axis();
@@ -136,22 +135,21 @@ private Q_SLOTS:
private:
QFxAxis _axis;
qreal _angle;
- qreal _distanceToPlane;
mutable bool _dirty;
mutable QSimpleCanvas::Matrix _transform;
};
-QML_DECLARE_TYPE(QFxRotation);
+QML_DECLARE_TYPE(QFxRotation3D);
-class Q_DECLARATIVE_EXPORT QFxTranslation : public QFxTransform
+class Q_DECLARATIVE_EXPORT QFxTranslation3D : public QFxTransform
{
Q_OBJECT
Q_PROPERTY(QFxAxis *axis READ axis)
Q_PROPERTY(qreal distance READ distance WRITE setDistance)
public:
- QFxTranslation(QObject *parent=0);
- ~QFxTranslation();
+ QFxTranslation3D(QObject *parent=0);
+ ~QFxTranslation3D();
QFxAxis *axis();
@@ -170,7 +168,7 @@ private:
mutable bool _dirty;
mutable QSimpleCanvas::Matrix _transform;
};
-QML_DECLARE_TYPE(QFxTranslation);
+QML_DECLARE_TYPE(QFxTranslation3D);
class Q_DECLARATIVE_EXPORT QFxPerspective : public QFxTransform
{
@@ -269,10 +267,8 @@ public:
qreal bottomRight_x() const;
void setbottomRight_x(qreal);
-#if defined(QFX_RENDER_OPENGL)
virtual bool isIdentity() const;
- virtual QMatrix4x4 transform() const;
-#endif
+ virtual QSimpleCanvas::Matrix transform() const;
private:
void update();