Skip to content

Commit 053a47b

Browse files
committed
feat: rewrite PopupHandle for Qt6 with Window popupType support
1. Rewrite DPopupWindowHandle to work natively with Qt6 2. Support Popup.Window popupType with window decorations (radius, border, shadow, blur) 3. Implement screen edge avoidance for popup windows 4. Add close-on-focus-loss behavior through event filters 5. Simplify architecture: remove DPopupWindowHandleImpl and DVtableHook usage 6. Remove global PopupMode enum and forceWindowMode property 7. Update DQuickWindowAttached to support QQuickPopup objects Log: Rewrite PopupHandle to support popupType Window mode in Qt6 Influence: 1. Test Popup with popupType: Window – verify window decorations (radius, border, shadow, blur) 2. Test screen edge avoidance: open popups near screen edges and verify positioning 3. Test close-on-click-outside: click outside popup and verify it closes 4. Test close-on-focus-loss: switch to other window and verify popup closes 5. Test nested popups (submenus) – verify correct screen assignment and flipping behavior 6. Test window properties: windowRadius, borderWidth, borderColor, shadowRadius, shadowOffset, shadowColor 7. Test translucentBackground and enableBlurWindow properties 8. Test menu popup behavior – ensure no regressions in Menu popup 9. Test with different screen configurations (multiple monitors, different DPI) 10. Verify no crash when popup is destroyed feat: 重写PopupHandle以支持Qt6的Window模式 1. 重写DPopupWindowHandle以原生支持Qt6 2. 支持Popup.Window弹窗类型,添加窗口装饰(圆角、边框、阴影、模糊) 3. 实现弹窗窗口的屏幕边缘避让 4. 通过事件过滤器实现失去焦点自动关闭 5. 简化架构:移除DPopupWindowHandleImpl和DVtableHook的使用 6. 移除全局PopupMode枚举和forceWindowMode属性 7. 更新DQuickWindowAttached以支持QQuickPopup对象 Log: 重写PopupHandle支持popupType为Window模式 Influence: 1. 测试Popup的popupType: Window模式 – 验证窗口装饰(圆角、边框、阴影、 模糊) 2. 测试屏幕边缘避让:在屏幕边缘打开弹窗,验证位置调整 3. 测试点击外部关闭:点击弹窗外区域,验证弹窗关闭 4. 测试失去焦点关闭:切换到其他窗口,验证弹窗关闭 5. 测试嵌套弹窗(子菜单)– 验证正确的屏幕分配和翻转行为 6. 测试窗口属性:windowRadius、borderWidth、borderColor、shadowRadius、 shadowOffset、shadowColor 7. 测试translucentBackground和enableBlurWindow属性 8. 测试菜单弹窗行为 – 确保菜单弹窗没有回归问题 9. 测试不同屏幕配置(多显示器、不同DPI) 10. 验证弹窗销毁时不会崩溃
1 parent 06d2ef0 commit 053a47b

14 files changed

Lines changed: 318 additions & 281 deletions

examples/qml-inspect/Example_Popup.qml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -68,12 +68,6 @@ Column {
6868
}
6969
}
7070
}
71-
Button {
72-
text: "handle forceWindowMode"
73-
onClicked: {
74-
popupWindow.PopupHandle.forceWindowMode = !popupWindow.PopupHandle.forceWindowMode
75-
}
76-
}
7771

7872
Popup {
7973
id: popupWindow; objectName: "pupup window"
@@ -85,10 +79,25 @@ Column {
8579
// width: 300
8680
// height: 300
8781
// margins: 100
88-
PopupHandle.forceWindowMode: true
89-
PopupHandle.delegate: PopupWindow {
90-
blurControl: popupWindow
91-
}
82+
83+
// Test window properties in Qt6
84+
// popupType: Popup.Window
85+
// PopupHandle.windowRadius: 18
86+
// PopupHandle.borderWidth: 2
87+
// PopupHandle.borderColor: "red"
88+
// PopupHandle.shadowRadius: 30
89+
// PopupHandle.shadowOffset: Qt.point(0, 4)
90+
// PopupHandle.shadowColor: Qt.rgba(0, 0, 0, 0.5)
91+
// PopupHandle.translucentBackground: true
92+
// PopupHandle.enableBlurWindow: true
93+
94+
// Component.onCompleted: {
95+
// console.log("=== Popup Properties ===")
96+
// console.log("windowRadius:", PopupHandle.windowRadius)
97+
// console.log("borderWidth:", PopupHandle.borderWidth)
98+
// console.log("borderColor:", PopupHandle.borderColor)
99+
// console.log("translucentBackground:", PopupHandle.translucentBackground)
100+
// }
92101
contentItem: Column {
93102
spacing: 10
94103
Text {
@@ -125,8 +134,6 @@ Column {
125134
Menu {
126135
id: menuPopup
127136
MenuItem { text: "Text" }
128-
129-
PopupHandle.forceWindowMode: true
130137
}
131138
ArrowShapePopup {
132139
id: arrow

qmlplugin/qmlplugin_plugin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "private/dquickiconlabel_p.h"
2323
#include "private/dsettingscontainer_p.h"
2424
#include "private/dmessagemanager_p.h"
25-
#include "private/dpopupwindowhandle_p.h"
2625
#include "private/dobjectmodelproxy_p.h"
2726
#include "private/dquickwaterprogressattribute_p.h"
2827
#include "private/dquickarrowboxpath_p.h"
@@ -208,7 +207,6 @@ void QmlpluginPlugin::registerTypes(const char *uri)
208207
QStringLiteral("ColorSelector is only available as an attached property."));
209208
dtkRegisterUncreatableType<DColor>(uri, implUri, 1, 0, "Color",
210209
QStringLiteral("Color is only available as enums."));
211-
dtkRegisterUncreatableType<DPopupWindowHandle>(uri, implUri, 1, 0, "PopupHandle", "PopupWindow Attached");
212210
dtkRegisterUncreatableType<DPlatformHandle>(uri, implUri, 1, 0, "PlatformHandle", "PlatformHandle");
213211

214212
qRegisterMetaType<DQUICK_NAMESPACE::DQuickDciIcon>();

qt6/src/qml/Menu.qml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -39,9 +39,6 @@ T.Menu {
3939

4040
delegate: MenuItem { }
4141

42-
D.PopupHandle.delegate: PopupWindow {
43-
blurControl: control
44-
}
4542

4643
contentItem: FocusScope {
4744
// QTBUG-99897 focus doesn't be clear.
@@ -100,7 +97,7 @@ T.Menu {
10097
}
10198

10299
background: Loader {
103-
active: !control.D.PopupHandle.window
100+
active: control.popupType !== Popup.Window
104101
sourceComponent: FloatingPanel {
105102
implicitWidth: DS.Style.menu.item.width
106103
implicitHeight: DS.Style.menu.item.height

qt6/src/qml/Popup.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -19,7 +19,7 @@ T.Popup {
1919
padding: DS.Style.popup.padding
2020

2121
background: Loader {
22-
active: !control.D.PopupHandle.window
22+
active: control.popupType !== Popup.Window
2323
sourceComponent: FloatingPanel {
2424
implicitHeight: DS.Style.popup.height
2525
implicitWidth: DS.Style.popup.width

src/dquickwindow.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ DQuickWindowAttached *DQuickWindow::qmlAttachedProperties(QObject *object)
5656
if (window) {
5757
return new DQuickWindowAttached(window);
5858
}
59+
60+
// Support QQuickPopup with popupType == Window
61+
if (object && object->inherits("QQuickPopup")) {
62+
return new DQuickWindowAttached(object);
63+
}
5964

6065
return nullptr;
6166
}
@@ -131,6 +136,10 @@ bool DQuickWindowAttachedPrivate::ensurePlatformHandle()
131136
if (handle)
132137
return true;
133138

139+
if (!window) {
140+
return false;
141+
}
142+
134143
if (!DPlatformHandle::setEnabledNoTitlebarForWindow(window, true)) {
135144
qWarning() << "Failed to enable NoTitlebar for the window:" << window;
136145
return false;
@@ -179,10 +188,32 @@ void DQuickWindowAttachedPrivate::destoryPlatformHandle()
179188
handle = nullptr;
180189
}
181190

191+
void DQuickWindowAttachedPrivate::setWindow(QWindow *newWindow)
192+
{
193+
Q_Q(DQuickWindowAttached);
194+
195+
if (window == newWindow)
196+
return;
197+
198+
window = newWindow;
199+
200+
if (newWindow) {
201+
newWindow->installEventFilter(q);
202+
QObject::connect(DWindowManagerHelper::instance(), SIGNAL(windowMotifWMHintsChanged(quint32)),
203+
q, SLOT(_q_onWindowMotifHintsChanged(quint32)), Qt::UniqueConnection);
204+
205+
if (explicitEnable == True) {
206+
ensurePlatformHandle();
207+
}
208+
}
209+
}
210+
182211
void DQuickWindowAttachedPrivate::_q_onWindowMotifHintsChanged(quint32 winId)
183212
{
184213
D_Q(DQuickWindowAttached);
185214

215+
if (!q->window())
216+
return;
186217
if (q->window()->winId() != winId)
187218
return;
188219

@@ -339,9 +370,22 @@ DQuickWindowAttached::DQuickWindowAttached(QWindow *window)
339370
this, SLOT(_q_onWindowMotifHintsChanged(quint32)));
340371
}
341372

373+
DQuickWindowAttached::DQuickWindowAttached(QObject *popupObject)
374+
: QObject(popupObject)
375+
, DObject(*new DQuickWindowAttachedPrivate(nullptr, this))
376+
{
377+
}
378+
342379
QQuickWindow *DQuickWindowAttached::window() const
343380
{
344-
return qobject_cast<QQuickWindow *>(parent());
381+
D_DC(DQuickWindowAttached);
382+
return qobject_cast<QQuickWindow *>(d->window);
383+
}
384+
385+
void DQuickWindowAttached::setWindow(QQuickWindow *window)
386+
{
387+
D_D(DQuickWindowAttached);
388+
d->setWindow(window);
345389
}
346390

347391
/*!

src/dquickwindow.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2020 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -80,8 +80,10 @@ class DQuickWindowAttached : public QObject, public DTK_CORE_NAMESPACE::DObject
8080

8181
public:
8282
explicit DQuickWindowAttached(QWindow *window);
83+
explicit DQuickWindowAttached(QObject *popupObject);
8384

8485
QQuickWindow *window() const;
86+
void setWindow(QQuickWindow *window);
8587
bool isEnabled() const;
8688

8789
int windowRadius() const;

0 commit comments

Comments
 (0)