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:
Andreas Buhr 2021-03-02 15:07:29 +01:00
parent d031ee460d
commit fe8ee78403
1 changed files with 37 additions and 37 deletions

View File

@ -56,31 +56,6 @@ Rectangle {
width: 600
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
Rectangle {
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 {
id: splitter
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: {
if (menulist.height == Screen.height && menulist.width == Screen.width)
pingPong.setSize(Screen.width, Screen.height)