roulette-payout/PlayerAreaView.qml

139 lines
4.6 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import roulette
Item {
anchors {
left: parent.left
leftMargin: 10
}
2024-06-01 14:46:10 +01:00
Text {
id: croupier
text: "Croupier"
}
ColumnLayout {
2024-06-01 14:46:10 +01:00
anchors {
top: croupier.bottom
topMargin: 20
}
2024-06-01 14:46:10 +01:00
spacing: 60
/*
* A repeater can only have one delegate model
* i.e. it can only have one object template defined in it.
* To repeat both a Text, and Rectangle AND a TextField, we put them inside an Item
* and use anchors to sort them inside the Item
*/
2024-06-01 14:46:10 +01:00
Repeater {
model: 7
Item {
Text {
id: label
text: "Player " + (index + 1)
}
Rectangle {
id: indicator
color: "red"
height: 10
width: 10
/*
* This check will run once when the object is created, but then only refresh
* when the NOTIFY signal for .focusedPlayer is sent
*/
visible: PlayerAreaModel.focusedPlayer == index
opacity: 0.5
anchors {
verticalCenter: inputField.verticalCenter
right: inputField.left
rightMargin: 5
}
}
2024-06-01 14:46:10 +01:00
TextField {
id: inputField
anchors {
top: label.bottom
topMargin: 6
}
2024-06-01 14:46:10 +01:00
onTextEdited: PlayerAreaModel.setPlayerName(text, index)
onActiveFocusChanged: {
/* focusReason 0, 1 and 2 are mouse, tab forward, and tab backward, respectively */
if (activeFocus && (focusReason == 0 || focusReason == 1 || focusReason == 2)) {
PlayerAreaModel.focusedPlayer = index
}
}
2024-06-01 14:46:10 +01:00
}
Text {
id: currentBet
anchors {
verticalCenter: inputField.verticalCenter
left: inputField.right
leftMargin: 5
}
text: ""
}
Connections {
target: PlayerAreaModel
function onBetChanged(b, n, bet) {
if (PlayerAreaModel.focusedPlayer == index) {
switch(b) {
case 1:
currentBet.text = "Red: " + bet + "g"
break;
case 2:
currentBet.text = "Black: " + bet + "g"
break;
case 3:
currentBet.text = "Odd: " + bet + "g"
break;
case 4:
currentBet.text = "Even: " + bet + "g"
break;
case 5:
currentBet.text = "Low: " + bet + "g"
break;
case 6:
currentBet.text = "High: " + bet + "g"
break;
case 7:
currentBet.text = "Dozen " + (n + 1) + ": " + bet + "g"
break;
case 8:
currentBet.text = "Street " + (n + 1) + ": " + bet + "g"
break;
case 9:
currentBet.text = "Single " + (n + 1) + ": " + bet + "g"
break;
case 10:
currentBet.text = "Column " + (n + 1) + ": " + bet + "g"
break;
}
}
}
function onBetRemoved(b, n, bet) {
if (PlayerAreaModel.focusedPlayer == index) {
currentBet.text = ""
}
}
}
2024-06-01 14:46:10 +01:00
}
}
}
}