summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikko Knuutila <mikko.knuutila@digia.com>2012-02-20 13:10:22 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-08-16 01:51:36 (GMT)
commit8de28b65bd18bea49fa57682d7ec3c3cd3cc4e7a (patch)
tree06b0f8a43e9154f3f0f5c69d94da9b216f5c4b44
parent0c95d019c64c3cf3c5bd6e150846033b5a96e794 (diff)
downloadQt-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>
-rw-r--r--src/gui/widgets/qdockwidget.cpp30
-rw-r--r--tests/auto/qdockwidget/tst_qdockwidget.cpp27
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)