summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-07-27 11:10:04 (GMT)
committerLars Knoll <lars.knoll@nokia.com>2009-07-29 03:47:27 (GMT)
commite494fef4cd3fd2dbec273fc48c49f8d15469bc96 (patch)
treed5590952803bbad1443e365a25e532142ed5c056 /src/declarative/qml
parent27015a7662a8a1b2852f2d43d948c51ac4e90070 (diff)
downloadQt-e494fef4cd3fd2dbec273fc48c49f8d15469bc96.zip
Qt-e494fef4cd3fd2dbec273fc48c49f8d15469bc96.tar.gz
Qt-e494fef4cd3fd2dbec273fc48c49f8d15469bc96.tar.bz2
add support for points and fix rect
The value bindings for rects where using integers. Use floats instead (as JS only knows about floats anyway) and make it work with both QRect and QRectF. Add valuse bindings for QPoint and QPointF.
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlvaluetype.cpp57
-rw-r--r--src/declarative/qml/qmlvaluetype_p.h46
2 files changed, 82 insertions, 21 deletions
diff --git a/src/declarative/qml/qmlvaluetype.cpp b/src/declarative/qml/qmlvaluetype.cpp
index 571263e..e93fbc1 100644
--- a/src/declarative/qml/qmlvaluetype.cpp
+++ b/src/declarative/qml/qmlvaluetype.cpp
@@ -59,7 +59,11 @@ QmlValueTypeFactory::~QmlValueTypeFactory()
QmlValueType *QmlValueTypeFactory::valueType(int t)
{
switch (t) {
+ case QVariant::Point:
+ case QVariant::PointF:
+ return new QmlPointValueType;
case QVariant::Rect:
+ case QVariant::RectF:
return new QmlRectValueType;
case QVariant::Vector3D:
return new QmlVector3DValueType;
@@ -73,6 +77,43 @@ QmlValueType::QmlValueType(QObject *parent)
{
}
+QmlPointValueType::QmlPointValueType(QObject *parent)
+: QmlValueType(parent)
+{
+}
+
+void QmlPointValueType::read(QObject *obj, int idx)
+{
+ void *a[] = { &point, 0 };
+ QMetaObject::metacall(obj, QMetaObject::ReadProperty, idx, a);
+}
+
+void QmlPointValueType::write(QObject *obj, int idx)
+{
+ void *a[] = { &point, 0 };
+ QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a);
+}
+
+qreal QmlPointValueType::x() const
+{
+ return point.x();
+}
+
+qreal QmlPointValueType::y() const
+{
+ return point.y();
+}
+
+void QmlPointValueType::setX(qreal x)
+{
+ point.setX(x);
+}
+
+void QmlPointValueType::setY(qreal y)
+{
+ point.setY(y);
+}
+
QmlRectValueType::QmlRectValueType(QObject *parent)
: QmlValueType(parent)
{
@@ -90,42 +131,42 @@ void QmlRectValueType::write(QObject *obj, int idx)
QMetaObject::metacall(obj, QMetaObject::WriteProperty, idx, a);
}
-int QmlRectValueType::x() const
+qreal QmlRectValueType::x() const
{
return rect.x();
}
-int QmlRectValueType::y() const
+qreal QmlRectValueType::y() const
{
return rect.y();
}
-void QmlRectValueType::setX(int x)
+void QmlRectValueType::setX(qreal x)
{
rect.moveLeft(x);
}
-void QmlRectValueType::setY(int y)
+void QmlRectValueType::setY(qreal y)
{
rect.moveTop(y);
}
-int QmlRectValueType::width() const
+qreal QmlRectValueType::width() const
{
return rect.width();
}
-int QmlRectValueType::height() const
+qreal QmlRectValueType::height() const
{
return rect.height();
}
-void QmlRectValueType::setWidth(int w)
+void QmlRectValueType::setWidth(qreal w)
{
rect.setWidth(w);
}
-void QmlRectValueType::setHeight(int h)
+void QmlRectValueType::setHeight(qreal h)
{
rect.setHeight(h);
}
diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h
index b19c1ba..9195c61 100644
--- a/src/declarative/qml/qmlvaluetype_p.h
+++ b/src/declarative/qml/qmlvaluetype_p.h
@@ -80,12 +80,32 @@ public:
QmlValueType *operator[](int idx) const { return valueTypes[idx]; }
};
+class QmlPointValueType : public QmlValueType
+{
+ Q_PROPERTY(qreal x READ x WRITE setX);
+ Q_PROPERTY(qreal y READ y WRITE setY);
+ Q_OBJECT
+public:
+ QmlPointValueType(QObject *parent = 0);
+
+ virtual void read(QObject *, int);
+ virtual void write(QObject *, int);
+
+ qreal x() const;
+ qreal y() const;
+ void setX(qreal);
+ void setY(qreal);
+
+private:
+ QPointF point;
+};
+
class QmlRectValueType : public QmlValueType
{
- Q_PROPERTY(int x READ x WRITE setX);
- Q_PROPERTY(int y READ y WRITE setY);
- Q_PROPERTY(int width READ width WRITE setWidth);
- Q_PROPERTY(int height READ height WRITE setHeight);
+ Q_PROPERTY(qreal x READ x WRITE setX);
+ Q_PROPERTY(qreal y READ y WRITE setY);
+ Q_PROPERTY(qreal width READ width WRITE setWidth);
+ Q_PROPERTY(qreal height READ height WRITE setHeight);
Q_OBJECT
public:
QmlRectValueType(QObject *parent = 0);
@@ -93,18 +113,18 @@ public:
virtual void read(QObject *, int);
virtual void write(QObject *, int);
- int x() const;
- int y() const;
- void setX(int);
- void setY(int);
+ qreal x() const;
+ qreal y() const;
+ void setX(qreal);
+ void setY(qreal);
- int width() const;
- int height() const;
- void setWidth(int);
- void setHeight(int);
+ qreal width() const;
+ qreal height() const;
+ void setWidth(qreal);
+ void setHeight(qreal);
private:
- QRect rect;
+ QRectF rect;
};
class QmlVector3DValueType : public QmlValueType