solitare/qml/DrawPile.qml

90 lines
2.1 KiB
QML
Raw Normal View History

2024-12-04 18:22:20 +00:00
import QtQuick
2024-12-05 00:22:18 +00:00
import Solitare
2024-12-04 18:22:20 +00:00
2024-12-07 21:16:37 +00:00
Item {
id: drawPile
required property real cardWidth
required property real cardHeight
width: cardWidth
height: cardHeight
2024-12-07 21:16:37 +00:00
CardModel {
id: drawPileCard
anchors.fill: drawPile
2024-12-07 22:10:16 +00:00
visible: GameState.drawPile.length > 0
2024-12-07 21:16:37 +00:00
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
isFaceDown: GameState.drawPile.length > 0 ? true : false
2024-12-07 22:10:16 +00:00
}
Rectangle {
id: emptyPileRect
anchors.fill: parent
visible: GameState.drawPile.length === 0
color: "gray"
border.color: "white"
border.width: width * 0.03
2024-12-07 22:10:16 +00:00
opacity: 0.4
radius: width * 0.125
2024-12-07 22:10:16 +00:00
Image {
id: flipIcon
anchors.centerIn: parent
visible: GameState.throwawayPile.length > 0
source: "qrc:/img/flip_icon.svg"
width: parent.width * 0.5
height: width
// This makes sure the SVG scales properly, otherwise it would
// attempt to scale the image from the original source size, which
// can end up being blurry.
sourceSize: Qt.size(width, height)
fillMode: Image.Stretch
2024-12-06 03:55:48 +00:00
}
2024-12-07 21:16:37 +00:00
}
Rectangle {
id: cardCountBackground
color: "black"
opacity: 0.7
property real padding: Math.max(cardCountText.width, cardCountText.height) * 0.3
width: cardCountText.width + padding
height: cardCountText.height + padding
2024-12-07 21:16:37 +00:00
2024-12-07 22:10:16 +00:00
visible: drawPileCard.visible
2024-12-07 21:16:37 +00:00
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: parent.width * 0.05
radius: parent.width * 0.1
2024-12-07 21:16:37 +00:00
z: 1 // Behind the text, but above the card
}
Text {
2024-12-07 22:10:16 +00:00
id: cardCountText
2024-12-07 21:16:37 +00:00
text: GameState.drawPile.length
color: "white"
font.pixelSize: parent.width * 0.2
2024-12-07 21:16:37 +00:00
font.bold: true
2024-12-07 22:10:16 +00:00
visible: drawPileCard.visible
2024-12-07 21:16:37 +00:00
anchors.centerIn: cardCountBackground
z: 2
2024-12-04 18:22:20 +00:00
}
2024-12-07 22:10:16 +00:00
MouseArea {
anchors.fill: parent
2024-12-08 16:06:08 +00:00
onClicked: GameState.drawNextCard()
2024-12-07 22:10:16 +00:00
}
2024-12-04 18:22:20 +00:00
}