diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2015-03-19 17:47:13 +0100 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2015-08-16 08:23:32 +0000 |
commit | f029468b8d822da378a20577f7b8c16a447e4e1b (patch) | |
tree | 1880893f39f04e8ab95240671f2b4b7f381ad62d /src/widgets/widgets/qdockarealayout.cpp | |
parent | 385202c27caa070e07eba098a1b968f9d466aaad (diff) |
Add QMainWindow::resizeDocks
This API allows to programatically resize QDockWidgets
Task-number: QTBUG-32001
Change-Id: I58072a391f8e7f325a26745b5bedd3fe49508e91
Reviewed-by: Jocelyn Turcotte (Woboq GmbH) <jturcotte@woboq.com>
Diffstat (limited to 'src/widgets/widgets/qdockarealayout.cpp')
-rw-r--r-- | src/widgets/widgets/qdockarealayout.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index c61984a457..0a00086138 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -3101,6 +3101,53 @@ void QDockAreaLayout::tabifyDockWidget(QDockWidget *first, QDockWidget *second) remove(index); } +void QDockAreaLayout::resizeDocks(const QList<QDockWidget *> &docks, + const QList<int> &sizes, Qt::Orientation o) +{ + if (docks.count() != sizes.count()) { + qWarning("QMainWidget::resizeDocks: size of the lists are not the same"); + return; + } + int count = docks.count(); + fallbackToSizeHints = false; + for (int i = 0; i < count; ++i) { + QList<int> path = indexOf(docks[i]); + if (path.isEmpty()) { + qWarning("QMainWidget::resizeDocks: one QDockWidget is not part of the layout"); + continue; + } + int size = sizes[i]; + if (size <= 0) { + qWarning("QMainWidget::resizeDocks: all sizes need to be larger than 0"); + size = 1; + } + + while (path.size() > 1) { + QDockAreaLayoutInfo *info = this->info(path); + if (!info->tabbed && info->o == o) { + info->item_list[path.last()].size = size; + int totalSize = 0; + foreach (const QDockAreaLayoutItem &item, info->item_list) { + if (!item.skip()) { + if (totalSize != 0) + totalSize += sep; + totalSize += item.size == -1 ? pick(o, item.sizeHint()) : item.size; + } + } + size = totalSize; + } + path.removeLast(); + } + + const int dockNum = path.first(); + Q_ASSERT(dockNum < QInternal::DockCount); + QRect &r = this->docks[dockNum].rect; + QSize s = r.size(); + rpick(o, s) = size; + r.setSize(s); + } +} + void QDockAreaLayout::splitDockWidget(QDockWidget *after, QDockWidget *dockWidget, Qt::Orientation orientation) |