Fix native titlebar offset and resizing upon unplugging dock widgets

When a dock widget received a native title bar upon unplugging, the
position of the newly unplugged dock widget was calculated without
taking the title bar's height into consideration.

Furthermore, dock widgets grew by the separator size upon undocking.
That is fixed by 10a143ccd7 by relying
on the assumption that passing a QRect() to the unplugging method
leads to un unchanged dock widget geometry.
However, when more than one dock widgets are docked in the same
main window dock on macOS or Windows, the size is stil increased.

This patch corrects the position offset for native title bars.
It also corrects an unplugged dock widget's geometry by the sparator's
size.

Fixes: QTBUG-106530
Fixes: QTBUG-106531
Pick-to: 6.4 6.2 5.15
Change-Id: Ia4bcb556841e14146f19c1377f4010d5ae009bcf
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Axel Spoerl 2022-09-23 16:50:09 +02:00
parent d35feca20c
commit d46f317c8e
2 changed files with 22 additions and 3 deletions

View File

@ -1013,12 +1013,18 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event)
pos = event->globalPosition().toPoint() - state->pressPos - windowMarginOffset;
}
// If the newly floating dock widget has got a native title bar,
// offset the position by the native title bar's height or width
const int dx = q->geometry().x() - q->x();
const int dy = q->geometry().y() - q->y();
pos.rx() += dx;
pos.ry() += dy;
QDockWidgetGroupWindow *floatingTab = qobject_cast<QDockWidgetGroupWindow*>(parent);
if (floatingTab && !q->isFloating())
floatingTab->move(pos);
else
q->move(pos);
if (state && !state->ctrlDrag)
mwlayout->hover(state->widgetItem, event->globalPosition().toPoint());

View File

@ -2655,8 +2655,21 @@ QLayoutItem *QMainWindowLayout::unplug(QWidget *widget, bool group)
#endif // QT_CONFIG(tabwidget)
{
// Dock widget is unplugged from the main window
// => geometry is not supposed to change
dw->d_func()->unplug(QRect());
// => geometry needs to be adjusted by separator size
switch (dockWidgetArea(dw)) {
case Qt::LeftDockWidgetArea:
case Qt::RightDockWidgetArea:
r.adjust(0, 0, 0, -sep);
break;
case Qt::TopDockWidgetArea:
case Qt::BottomDockWidgetArea:
r.adjust(0, 0, -sep, 0);
break;
case Qt::NoDockWidgetArea:
case Qt::DockWidgetArea_Mask:
break;
}
dw->d_func()->unplug(r);
}
}
#endif // QT_CONFIG(dockwidget)