summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-07-01 03:24:24 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-07-01 03:24:24 (GMT)
commit5bb4fe79e92a4882977f64c03654e707721c59a9 (patch)
tree2800057e0700f17d161d9e308c83536380bd1497 /src/declarative
parente44a16c440a56ccd6d9a001f01c45d7327ce8e62 (diff)
downloadQt-5bb4fe79e92a4882977f64c03654e707721c59a9.zip
Qt-5bb4fe79e92a4882977f64c03654e707721c59a9.tar.gz
Qt-5bb4fe79e92a4882977f64c03654e707721c59a9.tar.bz2
Add a Scale transform object.
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/fx/qfxtransform.cpp133
-rw-r--r--src/declarative/fx/qfxtransform.h43
2 files changed, 176 insertions, 0 deletions
diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp
index 2c4f842..0f0ce80 100644
--- a/src/declarative/fx/qfxtransform.cpp
+++ b/src/declarative/fx/qfxtransform.cpp
@@ -84,6 +84,139 @@ void QFxTransform::update()
}
/*!
+ \qmlclass Scale
+ \brief A Scale object provides a way to scale an Item.
+
+ The scale object gives more control over scaling than using Item's scale property. Specifically,
+ it allows a different scale for the x and y axes, and allows the scale to be relative to an
+ arbitrary point.
+
+ The following example scales the X axis of the Rect, relative to its interior point 25, 25:
+ \qml
+ Rect {
+ width: 100; height: 100
+ color: "blue"
+ transform: Scale { originX: 25; originY: 25; xScale: 3}
+ }
+ \endqml
+*/
+
+QFxScale::QFxScale(QObject *parent)
+: QFxTransform(parent), _originX(0), _originY(0), _xScale(1), _yScale(1), _dirty(true)
+{
+}
+
+QFxScale::~QFxScale()
+{
+}
+
+/*!
+ \qmlproperty real Scale::originX
+ \qmlproperty real Scale::originY
+
+ The origin point for the scale. The scale will be relative to this point.
+*/
+qreal QFxScale::originX() const
+{
+ return _originX;
+}
+
+void QFxScale::setOriginX(qreal ox)
+{
+ _originX = ox;
+ update();
+}
+
+qreal QFxScale::originY() const
+{
+ return _originY;
+}
+
+void QFxScale::setOriginY(qreal oy)
+{
+ _originY = oy;
+ update();
+}
+
+/*!
+ \qmlproperty real Scale::xScale
+
+ The scaling factor for the X axis.
+*/
+qreal QFxScale::xScale() const
+{
+ return _xScale;
+}
+
+void QFxScale::setXScale(qreal scale)
+{
+ if (_xScale == scale)
+ return;
+ _xScale = scale;
+ update();
+ emit scaleChanged();
+}
+
+/*!
+ \qmlproperty real Scale::yScale
+
+ The scaling factor for the Y axis.
+*/
+qreal QFxScale::yScale() const
+{
+ return _yScale;
+}
+
+void QFxScale::setYScale(qreal scale)
+{
+ if (_yScale == scale)
+ return;
+ _yScale = scale;
+ update();
+ emit scaleChanged();
+}
+
+bool QFxScale::isIdentity() const
+{
+ return (_xScale == 1. && _yScale == 1.);
+}
+
+#if defined(QFX_RENDER_QPAINTER)
+QTransform QFxScale::transform() const
+{
+ if (_dirty) {
+ _transform = QTransform();
+ _dirty = false;
+ _transform.translate(_originX, _originY);
+ _transform.scale(_xScale, _yScale);
+ _transform.translate(-_originX, -_originY);
+ }
+ return _transform;
+}
+#elif defined(QFX_RENDER_OPENGL)
+QMatrix4x4 QFxScale::transform() const
+{
+ if (_dirty) {
+ _transform = QMatrix4x4();
+ _dirty = false;
+ _transform.translate(_originX, _originY);
+ _transform.scale(_xScale, _yScale);
+ _transform.translate(-_originX, -_originY);
+ }
+ return _transform;
+}
+#endif
+
+void QFxScale::update()
+{
+ _dirty = true;
+ QFxTransform::update();
+}
+
+QML_DEFINE_TYPE(QFxScale, Scale)
+
+
+/*!
\qmlclass Axis
\brief A Axis object defines an axis that can be used for rotation or translation.
diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h
index 8693e7b..e0bd276 100644
--- a/src/declarative/fx/qfxtransform.h
+++ b/src/declarative/fx/qfxtransform.h
@@ -68,6 +68,48 @@ public:
virtual QSimpleCanvas::Matrix transform() const;
};
+class Q_DECLARATIVE_EXPORT QFxScale : public QFxTransform
+{
+ Q_OBJECT
+
+ Q_PROPERTY(qreal originX READ originX WRITE setOriginX)
+ Q_PROPERTY(qreal originY READ originY WRITE setOriginY)
+ Q_PROPERTY(qreal xScale READ xScale WRITE setXScale NOTIFY scaleChanged())
+ Q_PROPERTY(qreal yScale READ yScale WRITE setYScale NOTIFY scaleChanged())
+public:
+ QFxScale(QObject *parent=0);
+ ~QFxScale();
+
+ qreal originX() const;
+ void setOriginX(qreal);
+
+ qreal originY() const;
+ void setOriginY(qreal);
+
+ qreal xScale() const;
+ void setXScale(qreal);
+
+ qreal yScale() const;
+ void setYScale(qreal);
+
+ virtual bool isIdentity() const;
+ virtual QSimpleCanvas::Matrix transform() const;
+
+Q_SIGNALS:
+ void scaleChanged();
+
+private Q_SLOTS:
+ void update();
+private:
+ qreal _originX;
+ qreal _originY;
+ qreal _xScale;
+ qreal _yScale;
+
+ mutable bool _dirty;
+ mutable QSimpleCanvas::Matrix _transform;
+};
+
class Q_DECLARATIVE_EXPORT QFxAxis : public QObject
{
Q_OBJECT
@@ -308,6 +350,7 @@ private:
QT_END_NAMESPACE
QML_DECLARE_TYPE(QFxTransform)
+QML_DECLARE_TYPE(QFxScale)
QML_DECLARE_TYPE(QFxAxis)
QML_DECLARE_TYPE(QFxRotation)
QML_DECLARE_TYPE(QFxRotation3D)