diff options
-rw-r--r-- | src/gui/widgets/qdockwidget.cpp | 30 | ||||
-rw-r--r-- | tests/auto/qdockwidget/tst_qdockwidget.cpp | 27 |
2 files changed, 51 insertions, 6 deletions
diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp index 5b2d250..f6da240 100644 --- a/src/gui/widgets/qdockwidget.cpp +++ b/src/gui/widgets/qdockwidget.cpp @@ -690,6 +690,7 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) if (state != 0) return; + Q_Q(QDockWidget); QMainWindow *win = qobject_cast<QMainWindow*>(parent); Q_ASSERT(win != 0); QMainWindowLayout *layout = qt_mainwindow_layout(win); @@ -698,12 +699,23 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca) return; state = new QDockWidgetPrivate::DragState; - state->pressPos = pos; state->dragging = false; state->widgetItem = 0; state->ownWidgetItem = false; state->nca = nca; state->ctrlDrag = false; + + if (!q->isFloating()) { + // When dragging the widget out of the docking area, + // use the middle of title area as pressPos + QDockWidgetLayout *dwlayout = qobject_cast<QDockWidgetLayout*>(q->layout()); + Q_ASSERT(dwlayout != 0); + int width = undockedGeometry.isNull() ? q->width() : undockedGeometry.width(); + state->pressPos.setY(dwlayout->titleArea().height() / 2); + state->pressPos.setX(width / 2); + } else { + state->pressPos = pos; + } } void QDockWidgetPrivate::startDrag() @@ -987,11 +999,17 @@ void QDockWidgetPrivate::moveEvent(QMoveEvent *event) void QDockWidgetPrivate::unplug(const QRect &rect) { Q_Q(QDockWidget); - QRect r = rect; - r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); - QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); - if (dwLayout->nativeWindowDeco(true)) - r.adjust(0, dwLayout->titleHeight(), 0, 0); + QRect r; + if (!undockedGeometry.isNull()) { + r = undockedGeometry; + } else { + r = rect; + r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); + QDockWidgetLayout *dwLayout = qobject_cast<QDockWidgetLayout*>(layout); + if (dwLayout->nativeWindowDeco(true)) + r.adjust(0, dwLayout->titleHeight(), 0, 0); + } + setWindowState(true, true, r); } diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index b3e3b31..6ac386f 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -97,6 +97,7 @@ private slots: void task258459_visibilityChanged(); void taskQTBUG_1665_closableChanged(); void taskQTBUG_9758_undockedGeometry(); + void taskQTBUG_2940_resizeAfterUndocking(); }; // Testing get/set functions @@ -899,6 +900,32 @@ void tst_QDockWidget::taskQTBUG_9758_undockedGeometry() QVERIFY(dock1.y() >= 0); } +void tst_QDockWidget::taskQTBUG_2940_resizeAfterUndocking() +{ + QMainWindow window; + QDockWidget dw("dw", &window); + window.setGeometry(window.x(), window.y(), 400, 400); + window.addDockWidget(Qt::TopDockWidgetArea, &dw); + window.show(); + dw.setFloating(true); + dw.setGeometry(dw.x(), dw.y(), 100, 100); + + // When docked, width should be the same than window's width + dw.setFloating(false); + QCOMPARE(dw.width(), window.width()); + + // Drag the dock widget out of the window + qApp->postEvent(&dw, new QMouseEvent(QEvent::MouseButtonPress, + QPoint(10, 10), Qt::LeftButton, 0, 0)); + qApp->postEvent(&dw, new QMouseEvent(QEvent::MouseMove, + QPoint(100, 100), Qt::LeftButton,Qt::LeftButton, 0)); + qApp->postEvent(&dw, new QMouseEvent(QEvent::MouseButtonRelease, + QPoint(100, 100), Qt::LeftButton, 0, 0)); + qApp->processEvents(); + + // When undocked, size should be the restored + QCOMPARE(dw.size(), QSize(100, 100)); +} QTEST_MAIN(tst_QDockWidget) |