| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKDRAGAXIS_P_H |
| 5 | #define QQUICKDRAGAXIS_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQml/qqml.h> |
| 19 | #include <QtQml/qqmlproperty.h> |
| 20 | #include <private/qtquickglobal_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QQuickItem; |
| 25 | class QQuickPointerHandler; |
| 26 | |
| 27 | class Q_QUICK_EXPORT QQuickDragAxis : public QObject |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | Q_PROPERTY(qreal minimum READ minimum WRITE setMinimum NOTIFY minimumChanged) |
| 31 | Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY maximumChanged) |
| 32 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) |
| 33 | Q_PROPERTY(qreal activeValue READ activeValue NOTIFY activeValueChanged REVISION(6, 5)) |
| 34 | QML_NAMED_ELEMENT(DragAxis) |
| 35 | QML_ADDED_IN_VERSION(2, 12) |
| 36 | QML_UNCREATABLE("DragAxis is only available as a grouped property of DragHandler or PinchHandler." ) |
| 37 | |
| 38 | public: |
| 39 | QQuickDragAxis(QQuickPointerHandler *handler, const QString &propertyName, |
| 40 | qreal initValue = 0); |
| 41 | |
| 42 | qreal minimum() const { return m_minimum; } |
| 43 | void setMinimum(qreal minimum); |
| 44 | |
| 45 | qreal maximum() const { return m_maximum; } |
| 46 | void setMaximum(qreal maximum); |
| 47 | |
| 48 | bool enabled() const { return m_enabled; } |
| 49 | void setEnabled(bool enabled); |
| 50 | |
| 51 | qreal activeValue() const { return m_activeValue; } |
| 52 | |
| 53 | qreal persistentValue() const { return m_accumulatedValue; } |
| 54 | |
| 55 | protected: |
| 56 | void onActiveChanged(bool active, qreal initActiveValue); |
| 57 | qreal targetValue(); |
| 58 | void updateValue(qreal activeValue, qreal accumulatedValue, qreal delta = 0); |
| 59 | |
| 60 | Q_SIGNALS: |
| 61 | void minimumChanged(); |
| 62 | void maximumChanged(); |
| 63 | void enabledChanged(); |
| 64 | Q_REVISION(6, 5) void activeValueChanged(qreal delta); |
| 65 | |
| 66 | private: |
| 67 | qreal m_minimum = std::numeric_limits<qreal>::lowest(); |
| 68 | qreal m_maximum = std::numeric_limits<qreal>::max(); |
| 69 | qreal m_startValue = 0; |
| 70 | qreal m_activeValue = 0; |
| 71 | qreal m_accumulatedValue = 0; |
| 72 | QString m_propertyName; |
| 73 | bool m_enabled = true; |
| 74 | |
| 75 | friend class QQuickDragHandler; |
| 76 | friend class QQuickPinchHandler; |
| 77 | }; |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 | |
| 81 | #endif // QQUICKDRAGAXIS_P_H |
| 82 | |