solitare/PlayingCard.qml

25 lines
856 B
QML

import QtQuick
Item {
id: playingCard
width: 100
height: width * 1.4 // Maintian the aspect ratio of a playing card
// Annoyingly, there is no easy way to make this type-safe, QML does have enums
// but they only act as ints, and since we need the string names for the img paths
// anyways, typing these as simple strings is the easiest way to do this.
required property string color
required property string value
property string backStyle: "red"
property bool isFaceDown: false
Image {
id: cardImage
anchors.fill: parent
source: playingCard.isFaceDown
? "qrc:/img/playing_cards/backs/" + playingCard.backStyle + ".svg"
: "qrc:/img/playing_cards/fronts/" + playingCard.color + "_" + playingCard.value + ".svg"
fillMode: Image.PreserveAspectFit
}
}