solitare/Main.qml

110 lines
3.2 KiB
QML

import Solitare
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
ApplicationWindow {
width: 750
height: 650
visible: true
title: qsTr("Solitare")
ScoreBar {
id: scoreBar
height: 50
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
}
// Show the foundation piles, throwaway pile & the draw stack on the first row
Item {
id: firstRow
height: 120
anchors.top: scoreBar.bottom
anchors.left: parent.left
anchors.right: parent.right
Item {
anchors.fill: parent
anchors.margins: 10
// Left row (with the foundation piles)
Row {
spacing: 15
anchors.left: parent.left
Repeater {
model: 4 // Each of the 4 suits
CardModel {
required property int index; // passed from repeater
card: GameState.foundation[index].length > 0 ? GameState.foundation[index][0] : null
isFaceDown: false
}
}
}
// Spacer to push the second row to the right
Item {
Layout.fillWidth: true
}
// Right row (with throwaway and draw piles)
Row {
spacing: 20
anchors.right: parent.right
// Throwaway pile (last 3 cards visible with overlap)
Row {
// This allows makes the cards overlap
spacing: -60
Repeater {
model: Math.min(GameState.throwawayPile.length, 3)
delegate: CardModel {
required property int index // passed from repeater
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - index]
isFaceDown: false
}
}
}
// Draw pile (only the top card is shown)
CardModel {
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
isFaceDown: true
}
}
}
}
// Second row, with the individual columns
Row {
spacing: 10
anchors.top: firstRow.bottom
anchors.horizontalCenter: parent.horizontalCenter
anchors.topMargin: 50
Repeater {
model: GameState.columns.length
// Make a column for each slot
delegate: Column {
required property int index // passed from repeater
spacing: -80 // Overlap
Repeater {
model: GameState.columns[parent.index].length
delegate: CardModel {
required property int index
property ColumnSlot col: GameState.columns[parent.index][index]
card: col.card
isFaceDown: !col.revealed
}
}
}
}
}
}