6#include <qqmlregistration.h>
9#include "qml_material/export.hpp"
10#include "qml_material/util/pool.hpp"
18class PresentationAttached;
20class QML_MATERIAL_API PopupPresentation :
public QObject {
22 QML_NAMED_ELEMENT(PopupPresentation)
23 QML_UNCREATABLE(
"PopupPresentation objects are returned by PopupPresenter.present()")
25 Q_PROPERTY(Status status READ status NOTIFY statusChanged FINAL)
26 Q_PROPERTY(
bool active READ active NOTIFY activeChanged FINAL)
27 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged FINAL)
28 Q_PROPERTY(QVariant result READ result NOTIFY resultChanged FINAL)
44 ~PopupPresentation()
override;
46 auto status() const -> Status;
47 auto active() const ->
bool;
48 auto errorString() const -> QString;
49 auto result() const -> QVariant;
51 Q_INVOKABLE
void close();
52 Q_INVOKABLE
void cancel();
54 Q_SIGNAL
void statusChanged();
55 Q_SIGNAL
void activeChanged();
56 Q_SIGNAL
void errorStringChanged();
57 Q_SIGNAL
void resultChanged();
58 Q_SIGNAL
void opened();
59 Q_SIGNAL
void completed(const QVariant& result);
60 Q_SIGNAL
void closed();
61 Q_SIGNAL
void failed(const QString& error);
62 Q_SIGNAL
void cancelled();
69 friend class PopupPresenter;
70 friend class PresentationAttached;
80 explicit PopupPresentation(PopupPresenter* presenter);
82 void setStatus(Status value);
83 void setErrorString(QString value);
84 void setResult(QVariant value);
86 QPointer<QQuickItem> m_anchor;
87 QList<QMetaObject::Connection> m_anchorConnections;
89 QPointer<PopupPresenter> m_presenter;
90 QPointer<PoolRequest> m_request;
91 QPointer<QObject> m_popup;
92 QPointer<PresentationAttached> m_attached;
93 Status m_status { Loading };
94 Finish m_finish { Finish::None };
95 QString m_errorString;
97 bool m_terminal {
false };
98 bool m_completed {
false };
101class QML_MATERIAL_API PresentationAttached final :
public QObject {
104 Q_PROPERTY(
bool ready READ ready WRITE setReady NOTIFY readyChanged FINAL)
107 explicit PresentationAttached(QObject* parent =
nullptr);
109 auto ready() const ->
bool;
110 void setReady(
bool value);
112 Q_INVOKABLE
void fail(const QString& error);
113 Q_INVOKABLE
void complete(const QVariant& result = {});
115 Q_SIGNAL
void readyChanged();
116 Q_SIGNAL
void failureReported(
const QString& error);
117 Q_SIGNAL
void completionRequested(
const QVariant& result);
120 friend class PopupPresenter;
122 void bind(PopupPresentation* presentation);
123 void unbind(PopupPresentation* presentation);
125 QPointer<PopupPresentation> m_presentation;
126 QString m_errorString;
127 bool m_ready {
true };
128 bool m_failed {
false };
131class QML_MATERIAL_API Presentation :
public QObject {
133 QML_NAMED_ELEMENT(Presentation)
134 QML_UNCREATABLE(
"Presentation is only available as an attached property")
135 QML_ATTACHED(PresentationAttached)
138 explicit Presentation(QObject* parent =
nullptr);
140 static PresentationAttached* qmlAttachedProperties(QObject*
object);
143class QML_MATERIAL_API PopupPresenter : public QObject {
147 Q_PROPERTY(QQuickItem* host READ host WRITE setHost NOTIFY hostChanged FINAL)
148 Q_PROPERTY(Pool::IncubationMode incubationMode READ incubationMode WRITE setIncubationMode
149 NOTIFY incubationModeChanged FINAL)
152 explicit PopupPresenter(QObject* parent =
nullptr);
153 ~PopupPresenter()
override;
155 auto host() const -> QQuickItem*;
156 void setHost(QQuickItem* value);
158 auto incubationMode() const -> Pool::IncubationMode;
159 void setIncubationMode(Pool::IncubationMode value);
161 Q_INVOKABLE PopupPresentation* present(const QVariant& source,
162 const QVariantMap& initialProperties = {});
163 Q_INVOKABLE PopupPresentation* presentMenu(
const QVariant& source, QQuickItem* anchor,
164 const QVariantMap& initialProperties = {});
165 Q_INVOKABLE
void closeAll();
167 Q_SIGNAL
void hostChanged();
168 Q_SIGNAL
void incubationModeChanged();
171 friend class PopupPresentation;
173 PopupPresentation* presentImpl(
const QVariant& source,
const QVariantMap& properties,
174 QQuickItem* anchor,
bool menu);
175 void requestClose(PopupPresentation* presentation, PopupPresentation::Finish finish);
176 void handleRequest(PopupPresentation* presentation);
177 void attachPopup(PopupPresentation* presentation, QObject* popup);
178 void openPopup(PopupPresentation* presentation);
179 void failPresentation(PopupPresentation* presentation, QString error);
180 void finishPresentation(PopupPresentation* presentation, PopupPresentation::Finish finish);
181 void completePresentation(PopupPresentation* presentation, QVariant result);
182 void popupOpened(PopupPresentation* presentation);
183 void popupClosed(PopupPresentation* presentation);
184 void popupDestroyed(PopupPresentation* presentation);
185 void presentationDestroyed(PopupPresentation* presentation);
186 void retire(PopupPresentation* presentation);
187 void ensurePoolContext();
189 QPointer<QQuickItem> m_host;
191 Pool::IncubationMode m_incubationMode { Pool::AsynchronousIfNested };
192 std::vector<QPointer<PopupPresentation>> m_presentations;
193 bool m_destroying {
false };