diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2013-05-03 14:28:15 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-07 10:06:42 +0200 |
commit | a781a5e03d33e08efd694c02b7e7b423e4709789 (patch) | |
tree | 4f1c24125b0321d4784ef0ec15741c0b23ebdcf1 /src/controls | |
parent | 1667675fcdf30635aa9799728ad226abf875786e (diff) | |
download | qtquickcontrols-a781a5e03d33e08efd694c02b7e7b423e4709789.tar.gz |
SplitView: calculate implicit size
Set the implicit size of the SplitView based on the sizes of the
split items.
Change-Id: I775b938215216831d10cb50868e4c6733e157eeb
Reviewed-by: Jan Arve Sæther <jan-arve.saether@digia.com>
Diffstat (limited to 'src/controls')
-rw-r--r-- | src/controls/SplitView.qml | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/src/controls/SplitView.qml b/src/controls/SplitView.qml index b26abc0d..40d166d8 100644 --- a/src/controls/SplitView.qml +++ b/src/controls/SplitView.qml @@ -153,13 +153,17 @@ Item { QtObject { id: d - property bool horizontal: orientation == Qt.Horizontal - property string minimum: horizontal ? "minimumWidth" : "minimumHeight" - property string maximum: horizontal ? "maximumWidth" : "maximumHeight" - property string offset: horizontal ? "x" : "y" - property string otherOffset: horizontal ? "y" : "x" - property string size: horizontal ? "width" : "height" - property string otherSize: horizontal ? "height" : "width" + readonly property bool horizontal: orientation == Qt.Horizontal + readonly property string minimum: horizontal ? "minimumWidth" : "minimumHeight" + readonly property string maximum: horizontal ? "maximumWidth" : "maximumHeight" + readonly property string otherMinimum: horizontal ? "minimumHeight" : "minimumWidth" + readonly property string otherMaximum: horizontal ? "maximumHeight" : "maximumWidth" + readonly property string offset: horizontal ? "x" : "y" + readonly property string otherOffset: horizontal ? "y" : "x" + readonly property string size: horizontal ? "width" : "height" + readonly property string otherSize: horizontal ? "height" : "width" + readonly property string implicitSize: horizontal ? "implicitWidth" : "implicitHeight" + readonly property string implicitOtherSize: horizontal ? "implicitHeight" : "implicitWidth" property int expandingIndex: -1 property bool updateLayoutGuard: true @@ -186,6 +190,7 @@ Item { item.Layout.fillHeightChanged.connect(d.updateExpandingIndex) } + d.calculateImplicitSize() d.updateLayoutGuard = false d.updateExpandingIndex() } @@ -204,6 +209,35 @@ Item { d.updateLayout() } + function calculateImplicitSize() + { + var implicitSize = 0 + var implicitOtherSize = 0 + + for (var i=0; i<__items.length; ++i) { + var item = __items[i]; + implicitSize += clampedMinMax(item[d.size], item.Layout[minimum], item.Layout[maximum]) + var os = clampedMinMax(item[otherSize], item.Layout[otherMinimum], item.Layout[otherMaximum]) + implicitOtherSize = Math.max(implicitOtherSize, os) + + var handle = __handles[i] + if (handle) + implicitSize += handle[d.size] + } + + root[d.implicitSize] = implicitSize + root[d.implicitOtherSize] = implicitOtherSize + } + + function clampedMinMax(value, minimum, maximum) + { + if (minimum !== -1 && value < minimum) + value = minimum + if (maximum !== -1 && value > maximum) + value = maximum + return value + } + function accumulatedSize(firstIndex, lastIndex, includeExpandingMinimum) { // Go through items and handles, and @@ -252,15 +286,17 @@ Item { } } - // Set size of expanding item to remaining available space: - var expandingItem = __items[expandingIndex] - var min = expandingItem.Layout[minimum] !== undefined ? expandingItem.Layout[minimum] : 0 - expandingItem[d.size] = Math.max(min, root[d.size] - d.accumulatedSize(0, __items.length, false)) + // Set size of expanding item to remaining available space. + // Special case: If SplitView size is zero, we leave expandingItem with the size + // it already got, and assume that SplitView ends up with implicit size as size: + if (root[d.size] != 0) { + var expandingItem = __items[expandingIndex] + var min = expandingItem.Layout[minimum] !== undefined ? expandingItem.Layout[minimum] : 0 + expandingItem[d.size] = Math.max(min, root[d.size] - d.accumulatedSize(0, __items.length, false)) + } - // Then, position items and handles according to their width: + // Position items and handles according to their width: var lastVisibleItem, lastVisibleHandle, handle - var implicitSize = min - expandingItem[d.size] - for (i=0; i<__items.length; ++i) { // Position item to the right of the previous visible handle: item = __items[i]; @@ -268,7 +304,6 @@ Item { item[d.offset] = lastVisibleHandle ? lastVisibleHandle[d.offset] + lastVisibleHandle[d.size] : 0 item[d.otherOffset] = 0 item[d.otherSize] = root[d.otherSize] - implicitSize += item[d.size] lastVisibleItem = item handle = __handles[i] @@ -276,20 +311,11 @@ Item { handle[d.offset] = lastVisibleItem[d.offset] + Math.max(0, lastVisibleItem[d.size]) handle[d.otherOffset] = 0 handle[d.otherSize] = root[d.otherSize] - implicitSize += handle[d.size] lastVisibleHandle = handle } } } - if (root.orientation === Qt.horizontal) { - root.implicitWidth = implicitSize - root.implicitHeight = 0 - } else { - root.implicitWidth = 0 - root.implicitHeight = implicitSize - } - d.updateLayoutGuard = false } } |