aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativevaluetype_p.h
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2011-08-03 09:20:18 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-18 05:10:14 +0200
commit36767e3fe1f0038441ae06ef5b5e1cb19a3738fa (patch)
treeb0585a341061534876ac1e5ce1ce85f78a504ef1 /src/declarative/qml/qdeclarativevaluetype_p.h
parent74f3a67fe80fecf7ba2fd76e1758b6c0f68ce918 (diff)
Make QColor a value type
This commit allows direct access to the r, g, b and a components of a color (in floating point format: 0 <= v <= 1). Since conversion from color to string is a common operation, this commit also adds unit tests to ensure that the previous behaviour is maintained in other cases (comparison with toString value, etc). Task-number: QTBUG-14731 Change-Id: I87b521dd4f9c1e96dfe5b20cf8053293cb14cfe4 Reviewed-on: http://codereview.qt.nokia.com/2527 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Aaron Kennedy <aaron.kennedy@nokia.com>
Diffstat (limited to 'src/declarative/qml/qdeclarativevaluetype_p.h')
-rw-r--r--src/declarative/qml/qdeclarativevaluetype_p.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h
index 01a1765fd8..03cb83fdad 100644
--- a/src/declarative/qml/qdeclarativevaluetype_p.h
+++ b/src/declarative/qml/qdeclarativevaluetype_p.h
@@ -582,6 +582,36 @@ private:
mutable QDeclarativeNullableValue<int> dpi;
};
+class Q_AUTOTEST_EXPORT QDeclarativeColorValueType : public QDeclarativeValueType
+{
+ Q_PROPERTY(qreal r READ r WRITE setR)
+ Q_PROPERTY(qreal g READ g WRITE setG)
+ Q_PROPERTY(qreal b READ b WRITE setB)
+ Q_PROPERTY(qreal a READ a WRITE setA)
+ Q_OBJECT
+public:
+ QDeclarativeColorValueType(QObject *parent = 0);
+
+ virtual void read(QObject *, int);
+ virtual void write(QObject *, int, QDeclarativePropertyPrivate::WriteFlags);
+ virtual QVariant value();
+ virtual void setValue(QVariant value);
+ virtual QString toString() const;
+ virtual bool isEqual(const QVariant &value) const;
+
+ qreal r() const;
+ qreal g() const;
+ qreal b() const;
+ qreal a() const;
+ void setR(qreal);
+ void setG(qreal);
+ void setB(qreal);
+ void setA(qreal);
+
+private:
+ QColor color;
+};
+
QT_END_NAMESPACE
#endif // QDECLARATIVEVALUETYPE_P_H