aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/snippets/qmltc/colorpicker.h
blob: 84bc0caccfa3e077b9741f7ccfcb23a5b07369f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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();
};