feat: rewrite PopupHandle for Qt6 with Window popupType support#612
feat: rewrite PopupHandle for Qt6 with Window popupType support#61218202781743 wants to merge 1 commit intomasterfrom
Conversation
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. 验证弹窗销毁时不会崩溃
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto reviewGit Diff 代码审查报告总体概述这次代码改动主要针对 Qt6 中的 Popup 窗口处理进行了重构,移除了旧版的 详细审查1. 语法和逻辑问题1.1
|
Reviewer's GuideRewrites the PopupHandle/DPopupWindowHandle integration for Qt6 to work natively with QQuickPopup popupType Window, removes the old delegate/PopupMode/vtable-hook based architecture, and routes popup windows through DQuickWindowAttached to provide window decorations, edge-avoidance positioning, and close-on-focus-loss/press-outside behavior while updating QML usages accordingly. Sequence diagram for QQuickPopup Window popupType with PopupHandle and DQuickWindowAttachedsequenceDiagram
actor QMLApp
participant QQuickPopup as QQuickPopup_popup
participant DQuickWindow as DQuickWindow
participant DQuickWindowAttached as DQuickWindowAttached_attached
participant DPopupWindowHandle as PopupHandle
participant QQuickWindow as PopupWindow
participant ParentWindow as Parent_QQuickWindow
participant QGuiApplication as QGuiApp
participant QScreen as Screen
participant QQuickItem
participant QQuickPopupItem
QMLApp->>QQuickPopup: create Popup { D.PopupHandle attached }
QQuickPopup->>DPopupWindowHandle: qmlAttachedProperties(object)
activate DPopupWindowHandle
DPopupWindowHandle->>DQuickWindow: qmlAttachedProperties(popup)
DQuickWindow-->>DQuickWindowAttached: new DQuickWindowAttached(popup)
DQuickWindowAttached-->>DPopupWindowHandle: pointer stored as m_attached
DPopupWindowHandle->>DPopupWindowHandle: updateEnabled()
DPopupWindowHandle->>QQuickPopup: property(popupType)
QQuickPopup-->>DPopupWindowHandle: popupType == Window
DPopupWindowHandle->>DQuickWindowAttached: setEnabled(true)
DPopupWindowHandle->>DPopupWindowHandle: popupItemReparented()
DPopupWindowHandle->>QQuickPopup: findChildren<QQuickItem>()
QQuickPopup-->>DPopupWindowHandle: QQuickPopupItem
DPopupWindowHandle->>QQuickItem: addItemChangeListener(Geometry|Visibility)
DPopupWindowHandle->>QQuickItem: connect windowChanged(...)
QQuickPopup->>PopupWindow: open() creates QQuickPopupWindow
QQuickPopup->>DPopupWindowHandle: popupTypeChanged()
DPopupWindowHandle->>DPopupWindowHandle: updateEnabled()
QQuickPopupItem->>DPopupWindowHandle: onWindowChanged(PopupWindow)
DPopupWindowHandle->>DQuickWindowAttached: setWindow(PopupWindow)
DPopupWindowHandle->>PopupWindow: installEventFilter(this)
PopupWindow->>ParentWindow: setTransientParent(parent)
DPopupWindowHandle->>ParentWindow: installEventFilter(this)
Note over PopupWindow,QGuiApp: During move or initial show
PopupWindow-->>DPopupWindowHandle: QEvent::Move via eventFilter
DPopupWindowHandle->>DPopupWindowHandle: adjustPopupPosition()
DPopupWindowHandle->>PopupWindow: position(), size()
DPopupWindowHandle->>PopupWindow: transientParent()
alt nested popup
DPopupWindowHandle->>ParentWindow: screen()
ParentWindow-->>DPopupWindowHandle: Screen
else top level
DPopupWindowHandle->>QGuiApp: screenAt(windowCenter)
QGuiApp-->>DPopupWindowHandle: Screen
end
DPopupWindowHandle->>Screen: availableGeometry()
DPopupWindowHandle->>PopupWindow: setPosition(adjustedWithinScreen)
Note over ParentWindow,DPopupWindowHandle: Close on press outside
ParentWindow-->>DPopupWindowHandle: QEvent::MouseButtonPress via eventFilter
DPopupWindowHandle->>QQuickPopup: property(visible), property(closePolicy)
alt closePolicy allows press outside
DPopupWindowHandle->>QQuickPopup: invokeMethod("close")
else do nothing
end
Note over PopupWindow,DPopupWindowHandle: Close on focus loss is handled by Qt6 popup window
Class diagram for rewritten DPopupWindowHandle and DQuickWindowAttached integrationclassDiagram
direction LR
class DPopupWindowHandle {
+DPopupWindowHandle(QObject *popup)
+~DPopupWindowHandle()
+static DQuickWindowAttached *qmlAttachedProperties(QObject *object)
+DQuickWindowAttached *windowAttached() const
+bool eventFilter(QObject *watched, QEvent *event)
+void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry)
+void itemVisibilityChanged(QQuickItem *item)
+void itemParentChanged(QQuickItem *item, QQuickItem *oldParent)
-void updateEnabled()
-void onWindowChanged(QQuickWindow *window)
-QQuickWindow *popupWindow() const
-QQuickItem *popupItem() const
-void popupItemReparented()
-bool isEnabled() const
-void adjustPopupPosition()
-members
-QObject *m_popup
-bool m_enabled
-DQuickWindowAttached *m_attached
-QPointer~QQuickWindow~ m_parentWindow
-QPointer~QQuickWindow~ m_popupWin
-QPointer~QQuickItem~ m_trackedItem
}
class QQuickItemChangeListener {
<<interface>>
+void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &oldGeometry)
+void itemVisibilityChanged(QQuickItem *item)
+void itemParentChanged(QQuickItem *item, QQuickItem *oldParent)
}
class DQuickWindowAttached {
+DQuickWindowAttached(QWindow *window)
+DQuickWindowAttached(QObject *popupObject)
+QQuickWindow *window() const
+void setWindow(QQuickWindow *window)
+bool isEnabled() const
+int windowRadius() const
+int borderWidth() const
+QColor borderColor() const
+int shadowRadius() const
+QPointF shadowOffset() const
+QColor shadowColor() const
+bool translucentBackground() const
+bool enableBlurWindow() const
}
class DQuickWindowAttachedPrivate {
+DQuickWindowAttachedPrivate(QQuickWindow *window, DQuickWindowAttached *q)
+bool ensurePlatformHandle()
+void destoryPlatformHandle()
+void setWindow(QWindow *newWindow)
+void _q_onWindowMotifHintsChanged(quint32 winId)
-QWindow *window
-DPlatformHandle *handle
-DTK_CORE_NAMESPACE::DObject::ExplicitEnable explicitEnable
}
class DQuickWindow {
+static DQuickWindowAttached *qmlAttachedProperties(QObject *object)
}
%% relationships
DPopupWindowHandle ..|> QObject
DPopupWindowHandle ..|> QQuickItemChangeListener
DPopupWindowHandle --> DQuickWindowAttached : uses m_attached
DQuickWindowAttached o--> DQuickWindowAttachedPrivate : d_ptr
DQuickWindowAttachedPrivate --> QWindow : window
DQuickWindow ..> DQuickWindowAttached : returns
%% removed classes (for context)
class DPopupWindowHandleImpl {
-QQuickWindow *m_window
-QObject *m_popup
-bool m_positioning
}
DPopupWindowHandleImpl .. DPopupWindowHandle : removed composition
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In DPopupWindowHandle::popupItemReparented() you call QQuickItemPrivate::get(item) without checking if item is null, which will dereference a null pointer when the popup currently has no QQuickPopupItem child; add a null check after updating m_trackedItem.
- DQuickWindowAttachedPrivate::setWindow() updates the tracked window but does not remove the event filter, motif-hints connection, or any existing platform handle from the previous window, which can lead to stale callbacks and resources; consider explicitly disconnecting and calling destoryPlatformHandle() when the window changes or becomes null.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In DPopupWindowHandle::popupItemReparented() you call QQuickItemPrivate::get(item) without checking if item is null, which will dereference a null pointer when the popup currently has no QQuickPopupItem child; add a null check after updating m_trackedItem.
- DQuickWindowAttachedPrivate::setWindow() updates the tracked window but does not remove the event filter, motif-hints connection, or any existing platform handle from the previous window, which can lead to stale callbacks and resources; consider explicitly disconnecting and calling destoryPlatformHandle() when the window changes or becomes null.
## Individual Comments
### Comment 1
<location path="src/private/dpopupwindowhandle.cpp" line_range="82-91" />
<code_context>
+ QQuickItem *item = popupItem();
</code_context>
<issue_to_address>
**issue (bug_risk):** Guard against popupItem() returning null before using QQuickItemPrivate::get(item).
After `m_trackedItem = item;`, add an early return when `item` is null before calling `QQuickItemPrivate::get(item)` or connecting signals, e.g.:
```cpp
m_trackedItem = item;
if (!item)
return;
QQuickItemPrivate::get(item)->addItemChangeListener(...);
connect(item, &QQuickItem::windowChanged, ...);
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| QQuickItem *item = popupItem(); | ||
| if (m_trackedItem == item) | ||
| return; | ||
|
|
||
| m_forceWindowMode = forceWindowMode; | ||
| if (!m_forceWindowMode && m_handle) { | ||
| m_handle.reset(); | ||
| Q_EMIT windowChanged(); | ||
| if (m_trackedItem) { | ||
| QQuickItemPrivate::get(m_trackedItem)->removeItemChangeListener(this, QQuickItemPrivate::Geometry); | ||
| disconnect(m_trackedItem, &QQuickItem::windowChanged, this, &DPopupWindowHandle::onWindowChanged); | ||
| } | ||
| if (m_forceWindowMode) { | ||
| // try to create handle. | ||
| createHandle(); | ||
| } | ||
| } | ||
|
|
||
| void DPopupWindowHandle::createHandle() | ||
| { | ||
| if (!needCreateHandle()) | ||
| return; | ||
| m_trackedItem = item; |
There was a problem hiding this comment.
issue (bug_risk): Guard against popupItem() returning null before using QQuickItemPrivate::get(item).
After m_trackedItem = item;, add an early return when item is null before calling QQuickItemPrivate::get(item) or connecting signals, e.g.:
m_trackedItem = item;
if (!item)
return;
QQuickItemPrivate::get(item)->addItemChangeListener(...);
connect(item, &QQuickItem::windowChanged, ...);
border, shadow, blur)
usage
Log: Rewrite PopupHandle to support popupType Window mode in Qt6
Influence:
(radius, border, shadow, blur)
positioning
closes
flipping behavior
shadowRadius, shadowOffset, shadowColor
different DPI)
feat: 重写PopupHandle以支持Qt6的Window模式
Log: 重写PopupHandle支持popupType为Window模式
Influence:
模糊)
shadowOffset、shadowColor
Summary by Sourcery
Rewrite the popup window handling to integrate natively with Qt 6 popup windows and DQuickWindowAttached, enabling Window-type popups with proper decorations and screen-aware positioning.
New Features:
Bug Fixes:
Enhancements:
Tests: