QmlMaterial 0.1.0
Loading...
Searching...
No Matches
overlay.hpp
1#pragma once
2
3#include <QQuickItem>
4#include <QQuickWindow>
5#include <QQmlComponent>
6#include <QPointer>
7#include "qml_material/export.hpp"
8
9namespace qml_material
10{
11class Popup;
12class Drawer;
13class OverlayAttached;
14
15class QML_MATERIAL_API OverlayManager : public QQuickItem {
16 Q_OBJECT
17 QML_ANONYMOUS
18public:
19 static OverlayManager* get(QQuickWindow*);
20 ~OverlayManager() override;
21 void add(Popup*);
22 void remove(Popup*);
23 void refresh();
24 void updateDimmer(Popup*);
25 void registerDrawer(Drawer*);
26 void unregisterDrawer(Drawer*);
27 void releaseDrawer(Drawer*);
28 int popupCount() const { return m_entries.size(); }
29 bool isWindowDestroying() const;
30
31protected:
32 bool eventFilter(QObject*, QEvent*) override;
33
34private:
35 explicit OverlayManager(QQuickWindow*);
36 void resize();
37 bool press(const QPointF&);
38 bool release(const QPointF&);
39 bool blocks(const QPointF&) const;
40 Popup* topModal() const;
41 void restoreFocus(Popup*, QQuickItem*);
42 Drawer* dragCandidate(const QPointF&) const;
43 bool drawerPointer(QPointerEvent*, const QEventPoint&);
44 void cancelDrawerDrag();
45 void cancelPress();
46 struct Entry {
47 QPointer<Popup> popup;
48 QPointer<QQuickItem> dimmer;
49 QPointer<QQuickItem> hoverBarrier;
50 QPointer<QQmlComponent> component;
51 QPointer<QQuickItem> previousFocus;
52 qreal opacity = 1;
53 quint64 order = 0;
54 };
55 QList<Entry> m_entries;
56 quint64 m_nextOrder = 0;
57 QPointer<QQuickWindow> m_window;
58 QList<QPointer<Popup>> m_pressObservers;
59 QList<QPointer<Drawer>> m_drawers;
60 QPointer<Drawer> m_dragDrawer;
61 QPointer<const QPointingDevice> m_dragDevice;
62 int m_dragId = -1;
63 bool m_pressed = false, m_blocked = false;
64 bool m_destroying = false;
65 int m_touchId = -1;
66};
67
68class QML_MATERIAL_API Overlay : public QObject {
69 Q_OBJECT
70 QML_NAMED_ELEMENT(Overlay)
71 QML_UNCREATABLE("Overlay is an attached type")
72 QML_ATTACHED(OverlayAttached)
73public:
74 static OverlayAttached* qmlAttachedProperties(QObject*);
75};
76
77class QML_MATERIAL_API OverlayAttached : public QObject {
78 Q_OBJECT
79 Q_PROPERTY(QQuickItem* overlay READ overlay NOTIFY overlayChanged FINAL)
80 Q_PROPERTY(QQmlComponent* modal READ modal WRITE setModal NOTIFY modalChanged FINAL)
81 Q_PROPERTY(QQmlComponent* modeless READ modeless WRITE setModeless NOTIFY modelessChanged FINAL)
82public:
83 explicit OverlayAttached(QObject*);
84 QQuickItem* overlay() const;
85 QQmlComponent* modal() const { return m_modal; }
86 QQmlComponent* modeless() const { return m_modeless; }
87 void setModal(QQmlComponent*);
88 void setModeless(QQmlComponent*);
89 Q_SIGNAL void overlayChanged();
90 Q_SIGNAL void modalChanged();
91 Q_SIGNAL void modelessChanged();
92
93private:
94 QQuickWindow* window() const;
95 QPointer<QQmlComponent> m_modal, m_modeless;
96};
97} // namespace qml_material
98QML_DECLARE_TYPEINFO(qml_material::Overlay, QML_HAS_ATTACHED_PROPERTIES)