QmlMaterial 0.1.0
Loading...
Searching...
No Matches
nested_scroll_connection.hpp
1#pragma once
2
3#include <QObject>
4#include <QPointF>
5#include <QPointer>
6#include <qqmlregistration.h>
7#include "qml_material/export.hpp"
8
9namespace qml_material
10{
11class NestedScroll;
12
13class QML_MATERIAL_API NestedScrollConnection : public QObject {
14 Q_OBJECT
15 QML_ELEMENT
16 QML_UNCREATABLE("Use a concrete scroll behavior")
17public:
18 enum Source
19 {
20 Drag,
21 Wheel,
22 Fling
23 };
24 Q_ENUM(Source)
25 explicit NestedScrollConnection(QObject* parent = nullptr): QObject(parent) {}
26 virtual Qt::Orientations dragAxes() const { return {}; }
27 // Called once on pointer release, before remaining velocity starts a fling.
28 virtual QPointF release(QPointF velocity) {
29 Q_UNUSED(velocity);
30 return {};
31 }
32 // Vectors use local content displacement, not pointer displacement.
33 virtual QPointF preScroll(QPointF available, Source source) = 0;
34 virtual QPointF postScroll(QPointF consumed, QPointF available, Source source) = 0;
35 virtual bool canConsume(QPointF delta, Source source) const = 0;
36 virtual void begin(Source source) = 0;
37 virtual void end(bool cancelled) = 0;
38 Q_SIGNAL void invalidated();
39
40private:
41 friend class NestedScroll;
42 QPointer<QObject> m_attachment;
43};
44} // namespace qml_material