Commit a781a5e0 authored by Richard Moe Gustavsen's avatar Richard Moe Gustavsen Committed by The Qt Project
Browse files

SplitView: calculate implicit size


Set the implicit size of the SplitView based on the sizes of the
split items.

Change-Id: I775b938215216831d10cb50868e4c6733e157eeb
Reviewed-by: default avatarJan Arve Sæther <jan-arve.saether@digia.com>
parent 1667675f
6.2 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 dev old/5.1 old/5.2 wip/calendar wip/tizen v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1 v5.3.2 v5.3.1 v5.3.0 v5.3.0-rc1 v5.3.0-beta1 v5.3.0-alpha1 v5.2.1 v5.2.0 v5.2.0-rc1 v5.2.0-beta1 v5.2.0-alpha1 v5.1.1 v5.1.0 v5.1.0-rc2 v5.1.0-rc1 v5.1.0-beta1
No related merge requests found
Showing with 50 additions and 24 deletions
......@@ -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
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment