aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/snippets/qmltc/colorpicker.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/doc/snippets/qmltc/colorpicker.h')
-rw-r--r--src/qml/doc/snippets/qmltc/colorpicker.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/qml/doc/snippets/qmltc/colorpicker.h b/src/qml/doc/snippets/qmltc/colorpicker.h
new file mode 100644
index 0000000000..84bc0caccf
--- /dev/null
+++ b/src/qml/doc/snippets/qmltc/colorpicker.h
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QtCore/qobject.h>
+#include <QtCore/qproperty.h>
+#include <QtQml/qqmlregistration.h>
+#include <QtGui/qcolor.h>
+
+class MyColorPicker : public QObject
+{
+ Q_OBJECT
+ QML_ELEMENT
+ // Stores a value in the range [0, 1); myApp.qml type sets this with
+ // Math.random()
+ Q_PROPERTY(double encodedColor READ encodedColor WRITE setEncodedColor BINDABLE bindableEncodedColor)
+
+ QProperty<double> m_encodedColor{0.5};
+public:
+ MyColorPicker(QObject *parent = nullptr) : QObject(parent) {}
+
+ double encodedColor() { return m_encodedColor; }
+ void setEncodedColor(double value);
+ QBindable<double> bindableEncodedColor();
+
+ // Returns a QColor "decoded" from encodedColor
+ Q_INVOKABLE QColor decodeColor();
+};