Skip to content

Conversation

@dengzhongyuan365-dev
Copy link

  • Added additional checks to ensure the toolbar visibility logic accurately reflects whether the mouse is over the main window, even when other windows may overlap.
  • Implemented logic to confirm that the topmost window under the cursor is the main window or the toolbar, preventing issues with overlapping windows affecting toolbar visibility.

This update improves user experience by ensuring the toolbar behaves correctly in multi-window scenarios.

bug: https://pms.uniontech.com/bug-view-334269.html

- Added additional checks to ensure the toolbar visibility logic accurately reflects whether the mouse is over the main window, even when other windows may overlap.
- Implemented logic to confirm that the topmost window under the cursor is the main window or the toolbar, preventing issues with overlapping windows affecting toolbar visibility.

This update improves user experience by ensuring the toolbar behaves correctly in multi-window scenarios.

bug: https://pms.uniontech.com/bug-view-334269.html
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要是在处理窗口工具栏的显示逻辑,特别是针对多个贴图窗口重叠时的交互问题。以下是对这段代码的详细审查和改进建议:

1. 语法逻辑审查

优点

  • 逻辑清晰:通过检查鼠标位置和窗口层级关系,正确处理了窗口重叠时的工具栏显示问题
  • 条件判断完整:对 topWidgettopWindow 进行了空指针检查

潜在问题

  • m_toolBar 作为窗口检查可能不合适:工具栏通常不是独立窗口,而是子窗口。将其作为顶级窗口检查可能导致逻辑错误。

2. 代码质量建议

  1. 变量命名mouseOnMainWindow 的语义在修改后变得不够准确,因为它现在表示"鼠标是否在当前窗口且该窗口是最顶层窗口",建议重命名为 isMouseOnTopWindow 或类似名称。

  2. 注释位置:注释放在变量声明之后更好,这样更符合代码阅读习惯。

  3. 代码组织:可以将窗口检查逻辑提取为单独的函数,提高可读性和可维护性。

3. 代码性能建议

  1. 减少重复计算QCursor::pos() 可能会被多次调用,建议缓存结果。

  2. 窗口查询优化QApplication::widgetAt() 是相对昂贵的操作,可以考虑只在必要时调用。

4. 代码安全建议

  1. 空指针检查:虽然已经检查了 topWidget,但 topWindow 也应该进行检查,尽管 window() 通常不会返回 nullptr。

  2. 类型安全:考虑使用 qobject_cast 进行类型转换,而不是直接使用指针比较。

改进后的代码示例:

void MainWindow::checkToolbarVisibility()
{
    // ... 其他代码 ...

    const QPoint globalPos = QCursor::pos();
    
    // 检查鼠标是否在当前窗口且该窗口是最顶层窗口
    bool isMouseOnTopWindow = this->geometry().contains(globalPos);
    if (isMouseOnTopWindow) {
        QWidget *topWidget = QApplication::widgetAt(globalPos);
        if (topWidget) {
            QWidget *topWindow = topWidget->window();
            // 确保顶层窗口是当前窗口或其子窗口
            if (topWindow != this) {
                isMouseOnTopWindow = false;
            }
        }
    }
    
    const bool mouseOnToolBar = m_toolBar && m_toolBar->isVisible() && 
                              m_toolBar->geometry().contains(globalPos);

    bool mouseOnMenu = false;
    
    // ... 其他代码 ...
}

进一步优化建议:

  1. 提取函数:可以将窗口检查逻辑提取为私有方法:
bool MainWindow::isMouseOnTopWindow(const QPoint &globalPos) const
{
    if (!this->geometry().contains(globalPos)) {
        return false;
    }
    
    QWidget *topWidget = QApplication::widgetAt(globalPos);
    if (!topWidget) {
        return false;
    }
    
    QWidget *topWindow = topWidget->window();
    return topWindow == this;
}
  1. 使用智能指针:如果可能,考虑使用智能指针管理窗口对象。

  2. 性能监控:如果这段代码在频繁事件(如鼠标移动)中被调用,建议添加性能监控代码,确保不会造成性能问题。

总结

这段代码解决了窗口重叠时的工具栏显示问题,逻辑基本正确。主要改进方向是提高代码的可读性、可维护性和性能,同时确保类型安全和空指针安全。建议将窗口检查逻辑提取为独立函数,并优化变量命名和注释位置。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@dengzhongyuan365-dev
Copy link
Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Jan 22, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 15aeca3 into linuxdeepin:develop/snipe Jan 22, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants