nested mdi: Fix detaching inner dock widgets

Only the outter-most MDI frame is dragged in MDI mode. The inner ones
are dragged in normal docking mode, they become real floating windows.
This commit is contained in:
Sergio Martins
2022-01-14 22:25:32 +00:00
parent ea64aae861
commit 86bceb4c48
2 changed files with 36 additions and 2 deletions

View File

@@ -101,7 +101,26 @@ MainWindowBase *TitleBar::mainWindow() const
bool TitleBar::isMDI() const
{
return firstParentOfType<MDILayoutWidget>(this) != nullptr;
QObject *p = const_cast<TitleBar *>(this);
while (p) {
if (qobject_cast<const QWindow*>(p)) {
// Ignore QObject hierarchies spanning though multiple windows
return false;
}
if (qobject_cast<MDILayoutWidget *>(p))
return true;
if (qobject_cast<DropArea *>(p)) {
// Note that the TitleBar can be inside a DropArea that's inside a MDIArea
// so we need this additional check
return false;
}
p = p->parent();
}
return false;
}
void TitleBar::updateButtons()

View File

@@ -5095,12 +5095,12 @@ void TestDocks::tst_mdi_mixed_with_docking2()
Frame *frame1 = mdiWidget1->d->frame();
Frame *mdiFrame1 = frame1->mdiFrame();
QPointer<DropArea> dropArea1 = frame1->mdiDropAreaWrapper();
QPointer<Frame> frame2 = mdiWidget2->d->frame();
QPointer<Frame> mdiFrame2 = frame2->mdiFrame();
QPointer<DropArea> dropArea2 = frame2->mdiDropAreaWrapper();
QPointer<DropArea> dropArea1 = frame1->mdiDropAreaWrapper();
dropArea1->addDockWidget(mdiWidget3, Location_OnLeft, nullptr);
QVERIFY(!frame1->isMDI());
@@ -5191,6 +5191,21 @@ void TestDocks::tst_mdi_mixed_with_docking2()
QVERIFY(Testing::waitForDeleted(mdiFrame1));
QCOMPARE(mdiArea->frames().size(), 0);
// Dock again:
mdiArea->addDockWidget(mdiWidget1, QPoint(10, 10));
mdiArea->addDockWidget(mdiWidget2, QPoint(50, 50));
frame1 = mdiWidget1->d->frame();
dropArea1 = frame1->mdiDropAreaWrapper();
dropArea1->addDockWidget(mdiWidget3, Location_OnLeft, nullptr);
// Detach an internal dock widget by dragging
const QPoint globalSrc = mdiWidget1->mapToGlobal(QPoint(5, 5));
const QPoint globalDest = globalSrc + QPoint(10, 0);
drag(mdiWidget1, globalDest);
// QTest::qWait(100000);
}