DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dpopupwindowhandle_p.h
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#pragma once
6
7#include <dtkdeclarative_global.h>
8
9#include <QtQml>
10
11#include "dqmlglobalobject_p.h"
12
13QT_BEGIN_NAMESPACE
14class QQuickWindow;
15class QQuickItem;
16QT_END_NAMESPACE
17
18DQUICK_BEGIN_NAMESPACE
19
20class DPopupWindowHandleImpl;
21class Q_DECL_EXPORT DPopupWindowHandle : public QObject
22{
23 Q_OBJECT
24 Q_PROPERTY(QQmlComponent *delegate READ delegate WRITE setDelegate)
25 Q_PROPERTY(QQuickWindow *window READ window NOTIFY windowChanged)
26 Q_PROPERTY(bool forceWindowMode READ forceWindowMode WRITE setForceWindowMode)
27#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
28 QML_UNCREATABLE("PopupWindow Attached.")
29 QML_NAMED_ELEMENT(PopupHandle)
30 QML_ATTACHED(DPopupWindowHandle)
31#endif
32
33public:
34 explicit DPopupWindowHandle(QObject *parent = nullptr);
35 ~DPopupWindowHandle() override;
36
37 static DPopupWindowHandle *qmlAttachedProperties(QObject *object);
38
39 static void setPopupMode(const DQMLGlobalObject::PopupMode mode);
40
41 QQuickWindow *window() const;
42 QQmlComponent *delegate() const;
43 void setDelegate(QQmlComponent *delegate);
44 bool forceWindowMode() const;
45 void setForceWindowMode(bool forceWindowMode);
46
47Q_SIGNALS:
48 void windowChanged();
49
50private Q_SLOTS:
51 void createHandle();
52
53private:
54 QObject *popup() const;
55 bool needCreateHandle() const;
56
57private:
58 bool m_forceWindowMode = false;
59 bool m_isWindowMode = false;
60 QQmlComponent *m_delegate = nullptr;
61 QScopedPointer<DPopupWindowHandleImpl> m_handle;
62 static DQMLGlobalObject::PopupMode m_popupMode;
63};
64
65class DPopupWindowHandleImpl : public QObject
66{
67 Q_OBJECT
68public:
69 explicit DPopupWindowHandleImpl(QQuickWindow *window, QObject *parent);
70 ~DPopupWindowHandleImpl() override;
71
72 QQuickWindow *window() const;
73 QObject *popup() const;
74 QQuickItem *popupItem() const;
75 void updatePosition();
76 bool isPositioning() const;
77 void setPositioning(bool positioning);
78
79private Q_SLOTS:
80 void reposition();
81 void close();
82private:
83 QQuickWindow *m_window = nullptr;
84 QObject *m_popup = nullptr;
85 bool m_positioning = false;
86};
87
88DQUICK_END_NAMESPACE
89
90QML_DECLARE_TYPEINFO(DTK_QUICK_NAMESPACE::DPopupWindowHandle, QML_HAS_ATTACHED_PROPERTIES)
Definition dpopupwindowhandle_p.h:66
Definition dpopupwindowhandle_p.h:22