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 <giuseppe.dangelo@kdab.com>
This commit is contained in:
Friedemann Kleint 2015-10-08 17:14:57 +02:00
parent 2042a091a3
commit c977c687cb
2 changed files with 22 additions and 3 deletions

View File

@ -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<const QMouseEvent *>(event);
const QAction *action = d->systemMenu->actionAt(mouseEvent->pos());
if (!action || action->isEnabled())
close();
} else if (event->type() == QEvent::MouseMove) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
d->hoveredSubControl = d->getSubControl(mapFromGlobal(mouseEvent->globalPos()));

View File

@ -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<int>("actionIndex");
QTest::addColumn<bool>("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<QMdiSubWindow> 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<QWidget *>(systemMenu))
systemMenu->hide();
qApp->processEvents();
QVERIFY(!subWindow || !subWindow->isVisible());
QVERIFY(!systemMenu || !systemMenu->isVisible());
QCOMPARE(subWindow.isNull() || !subWindow->isVisible(), expectClosed);
}
#endif