diff options
author | Mikko Knuutila <mikko.knuutila@digia.com> | 2012-02-20 13:10:22 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-16 01:51:36 (GMT) |
commit | 8de28b65bd18bea49fa57682d7ec3c3cd3cc4e7a (patch) | |
tree | 06b0f8a43e9154f3f0f5c69d94da9b216f5c4b44 /src/gui | |
parent | 0c95d019c64c3cf3c5bd6e150846033b5a96e794 (diff) | |
download | Qt-8de28b65bd18bea49fa57682d7ec3c3cd3cc4e7a.zip Qt-8de28b65bd18bea49fa57682d7ec3c3cd3cc4e7a.tar.gz Qt-8de28b65bd18bea49fa57682d7ec3c3cd3cc4e7a.tar.bz2 |
Fix for restoring dockwidget's size when it gets dragged.
When user drags a dockwidget out of the docking area, restore widget's
previous floating size and center it's titlebar under the mouse.
Task-number: QTBUG-2940
Change-Id: I004de36d649abc4c32420bdd46bb6c810ef98c64
Reviewed-by: Girish Ramakrishnan <girish.1.ramakrishnan@nokia.com>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/widgets/qdockwidget.cpp | 30 |
1 files changed, 24 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); } |