import QtQuick import QtQuick.Controls import QtQuick.Layouts import roulette Item { anchors { left: parent.left leftMargin: 10 } Text { id: croupier font.pointSize: 18 text: "Croupier" color: { if (tapHandler.pressed) { "#99000000" } else { "#000000" } } TapHandler { id: tapHandler onSingleTapped: { PlayerAreaModel.focusedPlayer = 0 } } Rectangle { id: indicator color: "red" height: 10 width: 10 opacity: 0.5 visible: PlayerAreaModel.focusedPlayer == 0 anchors { verticalCenter: parent.verticalCenter right: parent.left rightMargin: 5 } } Text { id: roll anchors { top: parent.top topMargin: 8 left: parent.right leftMargin: 5 } } Connections { target: PlayerAreaModel function onBetChanged(b, n, bet) { if (PlayerAreaModel.focusedPlayer == 0) { const betTypes = ["NONE", "Red", "Black", "Odd", "Even", "Low", "High", "Dozen", "Street", "Single", "Column", "Split"] if (b < 7) { roll.text = betTypes[b] } else { roll.text = betTypes[b] + " " + (n + 1) } } } function onBetRemoved(b, n) { if (PlayerAreaModel.focusedPlayer == 0) { roll.text = "" } } } } ColumnLayout { anchors { top: croupier.bottom topMargin: 20 } 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 */ 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 - 1 == index opacity: 0.5 anchors { verticalCenter: inputField.verticalCenter right: inputField.left rightMargin: 5 } } TextField { id: inputField anchors { top: label.bottom topMargin: 6 } onTextEdited: PlayerAreaModel.setPlayerName(text, index + 1) 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 + 1 } } } Text { property int betType property int n id: currentBet1 anchors { verticalCenter: inputField.verticalCenter left: inputField.right leftMargin: 5 } text: "" } Text { property int betType property int n id: currentBet2 anchors { verticalCenter: inputField.verticalCenter left: currentBet1.right leftMargin: 5 } text: "" } Connections { target: PlayerAreaModel function onBetChanged(b, n, bet) { if (PlayerAreaModel.focusedPlayer - 1 == index) { const betTypes = ["NONE", "Red", "Black", "Odd", "Even", "Low", "High", "Dozen", "Street", "Single", "Column", "Split"] if (currentBet1.text == "") { currentBet1.betType = b currentBet1.n = n if (b < 7) { currentBet1.text = betTypes[b] + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g" } else { currentBet1.text = betTypes[b] + " " + (n + 1) + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g" } } else { currentBet2.betType = b currentBet2.n = n if (b < 7) { currentBet2.text = betTypes[b] + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g" } else { currentBet2.text = betTypes[b] + " " + (n + 1) + ": " + bet.toLocaleString(Qt.locale(), 'f', 0) + "g" } } } } function onBetRemoved(b, n) { if (PlayerAreaModel.focusedPlayer - 1 == index) { if (currentBet1.betType == b && currentBet1.n == n) { currentBet1.text = "" } else if (currentBet2.betType == b && currentBet2.n == n) { currentBet2.text = "" } } } } } } } }