QDockWidget: Store tab position when undocking
Add a field remembering the tab position of the dock widget area to QDockWidgetPrivate and use that when grouping floating docks. Fixes: QTBUG-74242 Change-Id: I2a453080cb39dd4a5491976f1aeca70ae681682a Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
86fc0b0e88
commit
0590da532e
@ -67,18 +67,21 @@ extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); /
|
||||
// qmainwindow.cpp
|
||||
extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
|
||||
|
||||
static inline QMainWindowLayout *qt_mainwindow_layout_from_dock(const QDockWidget *dock)
|
||||
static const QMainWindow *mainwindow_from_dock(const QDockWidget *dock)
|
||||
{
|
||||
const QWidget *p = dock->parentWidget();
|
||||
while (p) {
|
||||
const QMainWindow *window = qobject_cast<const QMainWindow*>(p);
|
||||
if (window)
|
||||
return qt_mainwindow_layout(window);
|
||||
p = p->parentWidget();
|
||||
for (const QWidget *p = dock->parentWidget(); p; p = p->parentWidget()) {
|
||||
if (const QMainWindow *window = qobject_cast<const QMainWindow*>(p))
|
||||
return window;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static inline QMainWindowLayout *qt_mainwindow_layout_from_dock(const QDockWidget *dock)
|
||||
{
|
||||
auto mainWindow = mainwindow_from_dock(dock);
|
||||
return mainWindow ? qt_mainwindow_layout(mainWindow) : nullptr;
|
||||
}
|
||||
|
||||
static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
|
||||
{ return (priv->features & feature) == feature; }
|
||||
|
||||
@ -839,8 +842,9 @@ void QDockWidgetPrivate::endDrag(bool abort)
|
||||
q->releaseMouse();
|
||||
|
||||
if (state->dragging) {
|
||||
QMainWindowLayout *mwLayout = qt_mainwindow_layout_from_dock(q);
|
||||
Q_ASSERT(mwLayout != 0);
|
||||
const QMainWindow *mainWindow = mainwindow_from_dock(q);
|
||||
Q_ASSERT(mainWindow != nullptr);
|
||||
QMainWindowLayout *mwLayout = qt_mainwindow_layout(mainWindow);
|
||||
|
||||
if (abort || !mwLayout->plug(state->widgetItem)) {
|
||||
if (hasFeature(this, QDockWidget::DockWidgetFloatable)) {
|
||||
@ -861,8 +865,12 @@ void QDockWidgetPrivate::endDrag(bool abort)
|
||||
} else {
|
||||
setResizerActive(false);
|
||||
}
|
||||
if (q->isFloating()) // Might not be floating when dragging a QDockWidgetGroupWindow
|
||||
if (q->isFloating()) { // Might not be floating when dragging a QDockWidgetGroupWindow
|
||||
undockedGeometry = q->geometry();
|
||||
#if QT_CONFIG(tabwidget)
|
||||
tabPosition = mwLayout->tabPosition(mainWindow->dockWidgetArea(q));
|
||||
#endif
|
||||
}
|
||||
q->activateWindow();
|
||||
} else {
|
||||
// The tab was not plugged back in the QMainWindow but the QDockWidget cannot
|
||||
|
@ -57,6 +57,10 @@
|
||||
#include "QtWidgets/qboxlayout.h"
|
||||
#include "QtWidgets/qdockwidget.h"
|
||||
|
||||
#if QT_CONFIG(tabwidget)
|
||||
# include "QtWidgets/qtabwidget.h"
|
||||
#endif
|
||||
|
||||
QT_REQUIRE_CONFIG(dockwidget);
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -86,6 +90,11 @@ public:
|
||||
void _q_toggleTopLevel(); // private slot
|
||||
|
||||
void updateButtons();
|
||||
|
||||
#if QT_CONFIG(tabwidget)
|
||||
QTabWidget::TabPosition tabPosition = QTabWidget::North;
|
||||
#endif
|
||||
|
||||
DragState *state = nullptr;
|
||||
|
||||
QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable
|
||||
|
@ -2525,6 +2525,30 @@ void QMainWindowLayout::updateGapIndicator()
|
||||
#endif // QT_CONFIG(rubberband)
|
||||
}
|
||||
|
||||
static QTabBar::Shape tabwidgetPositionToTabBarShape(QWidget *w)
|
||||
{
|
||||
QTabBar::Shape result = QTabBar::RoundedSouth;
|
||||
#if QT_CONFIG(tabwidget)
|
||||
if (qobject_cast<QDockWidget *>(w)) {
|
||||
switch (static_cast<QDockWidgetPrivate *>(qt_widget_private(w))->tabPosition) {
|
||||
case QTabWidget::North:
|
||||
result = QTabBar::RoundedNorth;
|
||||
break;
|
||||
case QTabWidget::South:
|
||||
result = QTabBar::RoundedSouth;
|
||||
break;
|
||||
case QTabWidget::West:
|
||||
result = QTabBar::RoundedWest;
|
||||
break;
|
||||
case QTabWidget::East:
|
||||
result = QTabBar::RoundedEast;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // tabwidget
|
||||
return result;
|
||||
}
|
||||
|
||||
void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos)
|
||||
{
|
||||
if (!parentWidget()->isVisible() || parentWidget()->isMinimized()
|
||||
@ -2573,8 +2597,9 @@ void QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mousePos)
|
||||
QDockWidgetGroupWindow *floatingTabs = createTabbedDockWindow(); // FIXME
|
||||
floatingTabs->setGeometry(dropTo->geometry());
|
||||
QDockAreaLayoutInfo *info = floatingTabs->layoutInfo();
|
||||
const QTabBar::Shape shape = tabwidgetPositionToTabBarShape(dropTo);
|
||||
*info = QDockAreaLayoutInfo(&layoutState.dockAreaLayout.sep, QInternal::LeftDock,
|
||||
Qt::Horizontal, QTabBar::RoundedSouth,
|
||||
Qt::Horizontal, shape,
|
||||
static_cast<QMainWindow *>(parentWidget()));
|
||||
info->tabbed = true;
|
||||
QLayout *parentLayout = dropTo->parentWidget()->layout();
|
||||
|
Loading…
x
Reference in New Issue
Block a user