From c977c687cbfed64fac4a1550733d111a3d8cdca0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 8 Oct 2015 17:14:57 +0200 Subject: [PATCH] QMdiSubWindow: Do not close when doubleclicking on disabled Restore action. Check whether the action under the mouse is enabled before closing. Task-number: QTBUG-48493 Change-Id: I2a0669840b9b6c81dacdf179325301c02f1c0c35 Reviewed-by: Giuseppe D'Angelo --- src/widgets/widgets/qmdisubwindow.cpp | 5 ++++- .../qmdisubwindow/tst_qmdisubwindow.cpp | 20 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/widgets/widgets/qmdisubwindow.cpp b/src/widgets/widgets/qmdisubwindow.cpp index c3b31ea5a4..14aeb73baf 100644 --- a/src/widgets/widgets/qmdisubwindow.cpp +++ b/src/widgets/widgets/qmdisubwindow.cpp @@ -2689,7 +2689,10 @@ bool QMdiSubWindow::eventFilter(QObject *object, QEvent *event) // System menu events. if (d->systemMenu && d->systemMenu == object) { if (event->type() == QEvent::MouseButtonDblClick) { - close(); + const QMouseEvent *mouseEvent = static_cast(event); + const QAction *action = d->systemMenu->actionAt(mouseEvent->pos()); + if (!action || action->isEnabled()) + close(); } else if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast(event); d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPos())); diff --git a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp index a6caa3d020..db252347ac 100644 --- a/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp +++ b/tests/auto/widgets/widgets/qmdisubwindow/tst_qmdisubwindow.cpp @@ -191,6 +191,7 @@ private slots: void fixedMinMaxSize(); #if !defined (Q_OS_MAC) && !defined (Q_OS_WINCE) void replaceMenuBarWhileMaximized(); + void closeOnDoubleClick_data(); void closeOnDoubleClick(); #endif void setFont(); @@ -1793,9 +1794,23 @@ void tst_QMdiSubWindow::replaceMenuBarWhileMaximized() QVERIFY(!subWindow->maximizedSystemMenuIconWidget()); } +void tst_QMdiSubWindow::closeOnDoubleClick_data() +{ + QTest::addColumn("actionIndex"); + QTest::addColumn("expectClosed"); + + QTest::newRow("close") << 1 << true; + QTest::newRow("disabled-restore-action") << 0 << false; // QTBUG-48493 +} + void tst_QMdiSubWindow::closeOnDoubleClick() { + QFETCH(int, actionIndex); + QFETCH(bool, expectClosed); + QMdiArea mdiArea; + mdiArea.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + + QLatin1Char(' ') + QLatin1String(QTest::currentDataTag())); QPointer subWindow = mdiArea.addSubWindow(new QWidget); mdiArea.show(); QVERIFY(QTest::qWaitForWindowExposed(&mdiArea)); @@ -1807,12 +1822,13 @@ void tst_QMdiSubWindow::closeOnDoubleClick() QVERIFY(systemMenu); QVERIFY(systemMenu->isVisible()); - sendMouseDoubleClick(systemMenu, QPoint(10, 10)); + const QRect actionGeometry = systemMenu->actionGeometry(systemMenu->actions().at(actionIndex)); + sendMouseDoubleClick(systemMenu, actionGeometry.center()); if (qApp->activePopupWidget() == static_cast(systemMenu)) systemMenu->hide(); qApp->processEvents(); - QVERIFY(!subWindow || !subWindow->isVisible()); QVERIFY(!systemMenu || !systemMenu->isVisible()); + QCOMPARE(subWindow.isNull() || !subWindow->isVisible(), expectClosed); } #endif