diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlvaluetype.cpp | 57 | ||||
-rw-r--r-- | src/declarative/qml/qmlvaluetype_p.h | 46 |
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 |