aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/handlers/qquickdragaxis_p.h
blob: d9aecf9d9d43589b13c9ac9c17cfd7b92e3bc96a (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQUICKDRAGAXIS_P_H
#define QQUICKDRAGAXIS_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtQml/qqml.h>
#include <QtQml/qqmlproperty.h>
#include <private/qtquickglobal_p.h>

QT_BEGIN_NAMESPACE

class QQuickItem;
class QQuickPointerHandler;

class Q_QUICK_EXPORT QQuickDragAxis : public QObject
{
    Q_OBJECT
    Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
    Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
    Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
    Q_PROPERTY(qreal activeValue READ activeValue NOTIFY activeValueChanged REVISION(6, 5))
    QML_NAMED_ELEMENT(DragAxis)
    QML_ADDED_IN_VERSION(2, 12)
    QML_UNCREATABLE("DragAxis is only available as a grouped property of DragHandler or PinchHandler.")

public:
    QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName,
                   qreal initValue = 0);

    qreal minimum() const { return m_minimum; }
    void setMinimum(qreal minimum);

    qreal maximum() const { return m_maximum; }
    void setMaximum(qreal maximum);

    bool enabled() const { return m_enabled; }
    void setEnabled(bool enabled);

    qreal activeValue() const { return m_activeValue; }

    qreal persistentValue() const { return m_accumulatedValue; }

protected:
    void onActiveChanged(bool active, qreal initActiveValue);
    qreal targetValue();
    void updateValue(qreal activeValue, qreal accumulatedValue, qreal delta = 0);

Q_SIGNALS:
    void minimumChanged();
    void maximumChanged();
    void enabledChanged();
    Q_REVISION(6, 5) void activeValueChanged(qreal delta);

private:
    qreal m_minimum = std::numeric_limits<qreal>::lowest();
    qreal m_maximum = std::numeric_limits<qreal>::max();
    qreal m_startValue = 0;
    qreal m_activeValue = 0;
    qreal m_accumulatedValue = 0;
    QString m_propertyName;
    bool m_enabled = true;

    friend class QQuickDragHandler;
    friend class QQuickPinchHandler;
};

QT_END_NAMESPACE

#endif // QQUICKDRAGAXIS_P_H