QmlMaterial 0.1.0
Loading...
Searching...
No Matches
nested_scroll.hpp
1#pragma once
2
3#include <QPointer>
4#include <QQuickItem>
5#include <qqmlregistration.h>
6#include "qml_material/export.hpp"
7#include "qml_material/input/nested_scroll_connection.hpp"
8
9namespace qml_material
10{
11class ScrollInputHandler;
12
13class QML_MATERIAL_API NestedScroll : public QObject {
14 Q_OBJECT
15 QML_ELEMENT
16 QML_UNCREATABLE("NestedScroll is an attached property")
17 QML_ATTACHED(NestedScroll)
18 Q_PROPERTY(int pressDelay READ pressDelay WRITE setPressDelay NOTIFY pressDelayChanged FINAL)
19 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL)
20 Q_PROPERTY(Qt::Orientations axes READ axes WRITE setAxes NOTIFY axesChanged FINAL)
21 Q_PROPERTY(bool wheelEnabled MEMBER m_wheelEnabled NOTIFY wheelEnabledChanged FINAL)
22 Q_PROPERTY(bool restoreOnReverse MEMBER m_restoreOnReverse NOTIFY restoreOnReverseChanged FINAL)
23 Q_PROPERTY(NestedScrollConnection* connection READ connection WRITE setConnection NOTIFY
24 connectionChanged FINAL)
25public:
26 explicit NestedScroll(QObject* parent);
27 ~NestedScroll() override;
28 static NestedScroll* qmlAttachedProperties(QObject*);
29 int pressDelay() const { return m_pressDelay; }
30 void setPressDelay(int);
31 Q_SIGNAL void pressDelayChanged();
32 static int childPressDelay(QQuickItem* receiver);
33 static bool coordinates(QQuickItem* receiver, QQuickItem* ancestor);
34 bool restoreOnReverse() const { return m_restoreOnReverse; }
35 bool wheelEnabled() const { return m_wheelEnabled; }
36 bool enabled() const { return m_enabled; }
37 void setEnabled(bool);
38 Qt::Orientations axes() const { return m_axes; }
39 void setAxes(Qt::Orientations);
40 QQuickItem* item() const { return m_item; }
41 NestedScrollConnection* connection() const { return m_connection; }
42 void setConnection(NestedScrollConnection*);
43 Q_SIGNAL void connectionChanged();
44 Q_SIGNAL void enabledChanged();
45 Q_SIGNAL void axesChanged();
46 Q_SIGNAL void wheelEnabledChanged();
47 Q_SIGNAL void restoreOnReverseChanged();
48 // Actual content displacement in this participant's local coordinates, excluding overscroll.
49 Q_SIGNAL void scrollConsumed(QPointF delta);
50 Q_SIGNAL void scrollStarted();
51 Q_SIGNAL void scrollFinished(bool cancelled);
52
53private:
54 friend class ScrollInputHandler;
55 friend class ScrollInputAdapter;
56 QPointer<QQuickItem> m_item;
57 QPointer<ScrollInputHandler> m_handler;
58 QPointer<ScrollInputHandler> m_controller;
59 QPointer<NestedScrollConnection> m_connection;
60 QMetaObject::Connection m_connectionDestroyed;
61 int m_pressDelay = 100;
62 bool m_enabled = false;
63 bool m_wheelEnabled = true;
64 bool m_restoreOnReverse = false;
65 Qt::Orientations m_axes = Qt::Horizontal | Qt::Vertical;
66};
67} // namespace qml_material
68
69QML_DECLARE_TYPEINFO(qml_material::NestedScroll, QML_HAS_ATTACHED_PROPERTIES)