Commit d8df1613 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig Committed by The Qt Project
Browse files

Improve resize behavior in testbench


- I now update width and height properties dynamically
- I automatically reset the size when properties are changed

Change-Id: I7edf717e52cd746f9921a8027c43617b54117a0f
Reviewed-by: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
parent 8ef3923e
Branches
Tags
No related merge requests found
Showing with 61 additions and 12 deletions
...@@ -45,7 +45,12 @@ QtObject { ...@@ -45,7 +45,12 @@ QtObject {
property Component boolLayout: CheckBox { property Component boolLayout: CheckBox {
checked: visible ? (result == "true") : false checked: visible ? (result == "true") : false
text: name text: name
onCheckedChanged: loader.item[name] = checked onCheckedChanged: {
if (!ignoreUpdate) {
loader.item[name] = checked
propertyChanged()
}
}
} }
property Component intLayout: RowLayout { property Component intLayout: RowLayout {
...@@ -59,7 +64,12 @@ QtObject { ...@@ -59,7 +64,12 @@ QtObject {
maximumValue: 9999 maximumValue: 9999
minimumValue: -9999 minimumValue: -9999
Layout.horizontalSizePolicy: Layout.Expanding Layout.horizontalSizePolicy: Layout.Expanding
onValueChanged: loader.item[name] = value onValueChanged: {
if (!ignoreUpdate) {
loader.item[name] = value
propertyChanged()
}
}
} }
} }
...@@ -70,13 +80,27 @@ QtObject { ...@@ -70,13 +80,27 @@ QtObject {
Layout.minimumWidth: 100 Layout.minimumWidth: 100
} }
SpinBox { SpinBox {
id: spinbox
value: result value: result
decimals: 1 decimals: 1
stepSize: 0.5 stepSize: 0.5
maximumValue: 9999 maximumValue: 9999
minimumValue: -9999 minimumValue: -9999
Layout.horizontalSizePolicy: Layout.Expanding Layout.horizontalSizePolicy: Layout.Expanding
onValueChanged: loader.item[name] = value onValueChanged: {
if (!ignoreUpdate) {
loader.item[name] = value
if (name != "width" && name != "height") // We dont want to reset size when size changes
propertyChanged()
}
}
Component.onCompleted: {
if (name == "width")
widthControl = spinbox
else if (name == "height")
heightControl = spinbox
}
} }
} }
...@@ -89,8 +113,13 @@ QtObject { ...@@ -89,8 +113,13 @@ QtObject {
TextField { TextField {
id: tf id: tf
text: result text: result
onTextChanged: loader.item[name] = tf.text
Layout.horizontalSizePolicy: Layout.Expanding Layout.horizontalSizePolicy: Layout.Expanding
onTextChanged: {
if (!ignoreUpdate) {
loader.item[name] = tf.text
propertyChanged()
}
}
} }
} }
...@@ -104,8 +133,8 @@ QtObject { ...@@ -104,8 +133,8 @@ QtObject {
Text { Text {
height: 20 height: 20
anchors.right: parent.right anchors.right: parent.right
text: loader.item[name] ? loader.item[name] : ""
Layout.horizontalSizePolicy: Layout.Expanding Layout.horizontalSizePolicy: Layout.Expanding
text: loader.item[name] ? loader.item[name] : ""
} }
} }
...@@ -122,7 +151,12 @@ QtObject { ...@@ -122,7 +151,12 @@ QtObject {
height: 20 height: 20
model: enumModel model: enumModel
Layout.horizontalSizePolicy: Layout.Expanding Layout.horizontalSizePolicy: Layout.Expanding
onSelectedIndexChanged: loader.item[name] = model.get(selectedIndex).value onSelectedIndexChanged: {
if (!ignoreUpdate) {
loader.item[name] = model.get(selectedIndex).value
propertyChanged()
}
}
Component.onCompleted: selectedIndex = getDefaultIndex() Component.onCompleted: selectedIndex = getDefaultIndex()
......
...@@ -46,7 +46,15 @@ ApplicationWindow { ...@@ -46,7 +46,15 @@ ApplicationWindow {
width: 950 width: 950
height: 600 height: 600
signal propertyChanged
property bool ignoreUpdate: false
onPropertyChanged: container.resetSize()
property var propertyMap: [] property var propertyMap: []
property SpinBox widthControl
property SpinBox heightControl
Components{ id: components } Components{ id: components }
SystemPalette { id: syspal } SystemPalette { id: syspal }
...@@ -67,11 +75,6 @@ ApplicationWindow { ...@@ -67,11 +75,6 @@ ApplicationWindow {
checked: true checked: true
text: "Background" text: "Background"
} }
ToolButton {
id: resetButton
text: "Reset size"
onClicked: container.resetSize()
}
} }
CheckBox { CheckBox {
...@@ -129,6 +132,18 @@ ApplicationWindow { ...@@ -129,6 +132,18 @@ ApplicationWindow {
bottomRightHandle.y = topLeftHandle.y + loader.item.implicitHeight; bottomRightHandle.y = topLeftHandle.y + loader.item.implicitHeight;
} }
function updateSize() {
ignoreUpdate = true
if (widthControl)
widthControl.value = loader.item.width
if (heightControl)
heightControl.value = loader.item.height
ignoreUpdate = false
}
onHeightChanged: updateSize()
onWidthChanged: updateSize()
y: Math.floor(topLeftHandle.y + topLeftHandle.height - topLeftHandle.width/2) y: Math.floor(topLeftHandle.y + topLeftHandle.height - topLeftHandle.width/2)
x: Math.floor(topLeftHandle.x + topLeftHandle.width - topLeftHandle.height/2) x: Math.floor(topLeftHandle.x + topLeftHandle.width - topLeftHandle.height/2)
width: Math.floor(bottomRightHandle.x - topLeftHandle.x ) width: Math.floor(bottomRightHandle.x - topLeftHandle.x )
...@@ -370,7 +385,7 @@ ApplicationWindow { ...@@ -370,7 +385,7 @@ ApplicationWindow {
Rectangle { Rectangle {
id: sidebar id: sidebar
color : syspal.window color : syspal.window
width: 300 width: 200
ScrollView { ScrollView {
id: scrollView id: scrollView
anchors.fill: parent anchors.fill: parent
......
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