Pingpong example: move properties and event handlers
Reorganize code to have graphical elements and event handlers separated Change-Id: I64480649e7bf077b0e63193250a4cb0fe6be699d Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
parent
d031ee460d
commit
fe8ee78403
|
@ -56,31 +56,6 @@ Rectangle {
|
||||||
width: 600
|
width: 600
|
||||||
height: 300
|
height: 300
|
||||||
|
|
||||||
// 1 - server role; left pedal
|
|
||||||
// 2 - client role; right pedal
|
|
||||||
property int roleSide: pingPong.role
|
|
||||||
onRoleSideChanged: {
|
|
||||||
if (pingPong.role == 1) {
|
|
||||||
rightMouse.opacity = 0.7
|
|
||||||
rightMouse.enabled = false
|
|
||||||
}
|
|
||||||
else if (pingPong.role == 2) {
|
|
||||||
leftMouse.opacity = 0.7
|
|
||||||
leftMouse.enabled = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
property bool deviceMessage: pingPong.showDialog
|
|
||||||
onDeviceMessageChanged: {
|
|
||||||
if (pingPong.showDialog) {
|
|
||||||
info.visible = true;
|
|
||||||
board.opacity = 0.5;
|
|
||||||
} else {
|
|
||||||
info.visible = false;
|
|
||||||
board.opacity = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Left pedal - server role
|
// Left pedal - server role
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: leftblock
|
id: leftblock
|
||||||
|
@ -123,18 +98,6 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
property double leftBlockY: leftblock.y
|
|
||||||
onLeftBlockYChanged: pingPong.updateLeftBlock(leftblock.y)
|
|
||||||
|
|
||||||
property double leftBlockUpdate: pingPong.leftBlockY
|
|
||||||
onLeftBlockUpdateChanged: leftblock.y = pingPong.leftBlockY
|
|
||||||
|
|
||||||
property double rightBlockY: rightblock.y
|
|
||||||
onRightBlockYChanged: pingPong.updateRightBlock(rightblock.y)
|
|
||||||
|
|
||||||
property double rightBlockUpdate: pingPong.rightBlockY
|
|
||||||
onRightBlockUpdateChanged: rightblock.y = pingPong.rightBlockY
|
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: splitter
|
id: splitter
|
||||||
color: "#363636"
|
color: "#363636"
|
||||||
|
@ -179,6 +142,43 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1 - server role; left pedal
|
||||||
|
// 2 - client role; right pedal
|
||||||
|
property int roleSide: pingPong.role
|
||||||
|
onRoleSideChanged: {
|
||||||
|
if (pingPong.role == 1) {
|
||||||
|
rightMouse.opacity = 0.7
|
||||||
|
rightMouse.enabled = false
|
||||||
|
}
|
||||||
|
else if (pingPong.role == 2) {
|
||||||
|
leftMouse.opacity = 0.7
|
||||||
|
leftMouse.enabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property bool deviceMessage: pingPong.showDialog
|
||||||
|
onDeviceMessageChanged: {
|
||||||
|
if (pingPong.showDialog) {
|
||||||
|
info.visible = true;
|
||||||
|
board.opacity = 0.5;
|
||||||
|
} else {
|
||||||
|
info.visible = false;
|
||||||
|
board.opacity = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
property double leftBlockY: leftblock.y
|
||||||
|
onLeftBlockYChanged: pingPong.updateLeftBlock(leftblock.y)
|
||||||
|
|
||||||
|
property double leftBlockUpdate: pingPong.leftBlockY
|
||||||
|
onLeftBlockUpdateChanged: leftblock.y = pingPong.leftBlockY
|
||||||
|
|
||||||
|
property double rightBlockY: rightblock.y
|
||||||
|
onRightBlockYChanged: pingPong.updateRightBlock(rightblock.y)
|
||||||
|
|
||||||
|
property double rightBlockUpdate: pingPong.rightBlockY
|
||||||
|
onRightBlockUpdateChanged: rightblock.y = pingPong.rightBlockY
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (menulist.height == Screen.height && menulist.width == Screen.width)
|
if (menulist.height == Screen.height && menulist.width == Screen.width)
|
||||||
pingPong.setSize(Screen.width, Screen.height)
|
pingPong.setSize(Screen.width, Screen.height)
|
||||||
|
|
Loading…
Reference in New Issue