From cbfb6bda1d1ce3e169db6a0deb9bd901076653e4 Mon Sep 17 00:00:00 2001 From: Anna Wojciechowska Date: Fri, 20 Oct 2017 08:51:16 -0700 Subject: Fix restoring geometry of dockwidget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the past if the window with dock widgets was closed in maximized mode, after reopening the dock widget size was different from the original one. It was caused due to consecutive resizes of dock widgets when the window was shown. During resizing dock widget geometry restored from property file was lost. The solution was to keep restored size of dock widgets in QDockAreaLayoutInfo and use as hints for the dock layout engine. Task-number: QTBUG-16252 Change-Id: I94f4e895922063fa51150b68464fea4ddcb1d2a2 Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qdockarealayout.cpp | 20 ++++++++++++++++++-- src/widgets/widgets/qdockarealayout_p.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 21d1d4cb85..bef7214c75 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -226,7 +226,7 @@ static quintptr tabId(const QDockAreaLayoutItem &item) static const int zero = 0; QDockAreaLayoutInfo::QDockAreaLayoutInfo() - : sep(&zero), dockPos(QInternal::LeftDock), o(Qt::Horizontal), mainWindow(0) + : restoredSizeHint(0,0), sep(&zero), dockPos(QInternal::LeftDock), o(Qt::Horizontal), mainWindow(0) #if QT_CONFIG(tabbar) , tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth) #endif @@ -236,7 +236,7 @@ QDockAreaLayoutInfo::QDockAreaLayoutInfo() QDockAreaLayoutInfo::QDockAreaLayoutInfo(const int *_sep, QInternal::DockPosition _dockPos, Qt::Orientation _o, int tbshape, QMainWindow *window) - : sep(_sep), dockPos(_dockPos), o(_o), mainWindow(window) + : restoredSizeHint(0,0), sep(_sep), dockPos(_dockPos), o(_o), mainWindow(window) #if QT_CONFIG(tabbar) , tabbed(false), tabBar(0), tabBarShape(static_cast(tbshape)) #endif @@ -407,6 +407,9 @@ QSize QDockAreaLayoutInfo::sizeHint() const if (isEmpty()) return QSize(0, 0); + if (!restoredSizeHint.isNull()) + return restoredSizeHint; + int a = 0, b = 0; int min_perp = 0; int max_perp = QWIDGETSIZE_MAX; @@ -2373,6 +2376,7 @@ bool QDockAreaLayout::restoreState(QDataStream &stream, const QList> size; if (!testing) { docks[pos].rect = QRect(QPoint(0, 0), size); + docks[pos].restoredSizeHint = size; } if (!docks[pos].restoreState(stream, dockwidgets, testing)) { stream.setStatus(QDataStream::ReadCorruptData); @@ -2674,6 +2678,8 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, center_rect.setBottom(rect.bottom() - docks[QInternal::BottomDock].rect.height() - sep); QSize left_hint = docks[QInternal::LeftDock].size(); + if (!docks[QInternal::LeftDock].restoredSizeHint.isNull()) + left_hint = docks[QInternal::LeftDock].restoredSizeHint; if (left_hint.isNull() || fallbackToSizeHints) left_hint = docks[QInternal::LeftDock].sizeHint(); QSize left_min = docks[QInternal::LeftDock].minimumSize(); @@ -2681,6 +2687,8 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, left_hint = left_hint.boundedTo(left_max).expandedTo(left_min); QSize right_hint = docks[QInternal::RightDock].size(); + if (!docks[QInternal::RightDock].restoredSizeHint.isNull()) + right_hint = docks[QInternal::RightDock].restoredSizeHint; if (right_hint.isNull() || fallbackToSizeHints) right_hint = docks[QInternal::RightDock].sizeHint(); QSize right_min = docks[QInternal::RightDock].minimumSize(); @@ -2688,6 +2696,8 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, right_hint = right_hint.boundedTo(right_max).expandedTo(right_min); QSize top_hint = docks[QInternal::TopDock].size(); + if (!docks[QInternal::TopDock].restoredSizeHint.isNull()) + top_hint = docks[QInternal::TopDock].restoredSizeHint; if (top_hint.isNull() || fallbackToSizeHints) top_hint = docks[QInternal::TopDock].sizeHint(); QSize top_min = docks[QInternal::TopDock].minimumSize(); @@ -2695,6 +2705,8 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, top_hint = top_hint.boundedTo(top_max).expandedTo(top_min); QSize bottom_hint = docks[QInternal::BottomDock].size(); + if (!docks[QInternal::BottomDock].restoredSizeHint.isNull()) + bottom_hint = docks[QInternal::BottomDock].restoredSizeHint; if (bottom_hint.isNull() || fallbackToSizeHints) bottom_hint = docks[QInternal::BottomDock].sizeHint(); QSize bottom_min = docks[QInternal::BottomDock].minimumSize(); @@ -3276,6 +3288,10 @@ int QDockAreaLayout::separatorMove(const QList &separator, const QPoint &or int delta = 0; int index = separator.last(); + for (int i = 0; i < QInternal::DockCount; ++i) + if (!docks[i].restoredSizeHint.isNull()) + docks[i].restoredSizeHint = QSize(0, 0); + if (separator.count() > 1) { QDockAreaLayoutInfo *info = this->info(separator); delta = pick(info->o, dest - origin); diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 82244c192e..ea397e00ac 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -189,6 +189,7 @@ public: QMainWindowLayout *mainWindowLayout() const; + QSize restoredSizeHint; const int *sep; mutable QVector separatorWidgets; QInternal::DockPosition dockPos; -- cgit v1.2.3