Format qml files
This commit is contained in:
parent
36a010d5aa
commit
ad690429a4
|
@ -3,16 +3,19 @@ import Solitare
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
id: cardModel
|
id: cardModel
|
||||||
width: 80
|
|
||||||
height: width * 1.4 // Maintian the aspect ratio of a playing card
|
|
||||||
|
|
||||||
required property PlayingCard card
|
required property PlayingCard card
|
||||||
required property bool isFaceDown
|
required property bool isFaceDown
|
||||||
property string backStyle: "red"
|
property string backStyle: "red"
|
||||||
|
|
||||||
signal clicked
|
signal clicked
|
||||||
|
|
||||||
|
width: 80
|
||||||
|
height: width * 1.4 // Maintian the aspect ratio of a playing card
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: cardImage
|
id: cardImage
|
||||||
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
source: cardModel.isFaceDown ? "qrc:/img/playing_cards/backs/" + cardModel.backStyle + ".svg" : cardModel.card ? "qrc:/img/playing_cards/fronts/" + cardModel.card.suitString + "_" + cardModel.card.valueString + ".svg" : "qrc:/img/playing_cards/backs/blue.svg"
|
source: cardModel.isFaceDown ? "qrc:/img/playing_cards/backs/" + cardModel.backStyle + ".svg" : cardModel.card ? "qrc:/img/playing_cards/fronts/" + cardModel.card.suitString + "_" + cardModel.card.valueString + ".svg" : "qrc:/img/playing_cards/backs/blue.svg"
|
||||||
fillMode: Image.PreserveAspectFit
|
fillMode: Image.PreserveAspectFit
|
||||||
|
|
|
@ -3,7 +3,6 @@ import Solitare
|
||||||
|
|
||||||
// Shows the top card facing down
|
// Shows the top card facing down
|
||||||
// (or a blank card if the pile is empty)
|
// (or a blank card if the pile is empty)
|
||||||
|
|
||||||
CardModel {
|
CardModel {
|
||||||
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
|
card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null
|
||||||
isFaceDown: GameState.drawPile.length > 0 ? true : false
|
isFaceDown: GameState.drawPile.length > 0 ? true : false
|
||||||
|
|
|
@ -6,8 +6,10 @@ Row {
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: 4 // Each of the 4 suits
|
model: 4 // Each of the 4 suits
|
||||||
|
|
||||||
CardModel {
|
CardModel {
|
||||||
required property int index // passed from repeater
|
required property int index // passed from repeater
|
||||||
|
|
||||||
card: GameState.foundation[index].length > 0 ? GameState.foundation[index][0] : null
|
card: GameState.foundation[index].length > 0 ? GameState.foundation[index][0] : null
|
||||||
isFaceDown: false
|
isFaceDown: false
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
ScoreBar {
|
ScoreBar {
|
||||||
id: scoreBar
|
id: scoreBar
|
||||||
|
|
||||||
height: 50
|
height: 50
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -21,6 +22,7 @@ ApplicationWindow {
|
||||||
// Show the foundation piles, throwaway pile & the draw stack on the first row
|
// Show the foundation piles, throwaway pile & the draw stack on the first row
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: firstRow
|
id: firstRow
|
||||||
|
|
||||||
height: 135
|
height: 135
|
||||||
anchors.top: scoreBar.bottom
|
anchors.top: scoreBar.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -42,6 +44,7 @@ ApplicationWindow {
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
|
|
||||||
ThrowawayPile {}
|
ThrowawayPile {}
|
||||||
|
|
||||||
DrawPile {}
|
DrawPile {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,41 +2,19 @@ import QtQuick
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
id: scoreBarRoot
|
id: scoreBarRoot
|
||||||
width: parent.width
|
|
||||||
height: 60
|
|
||||||
color: "lightgray"
|
|
||||||
|
|
||||||
property int score: 0
|
property int score: 0
|
||||||
property int time: 0
|
property int time: 0
|
||||||
property int moves: 0
|
property int moves: 0
|
||||||
|
|
||||||
property int dynamicFontSize: Math.round(height * 0.35)
|
property int dynamicFontSize: Math.round(height * 0.35)
|
||||||
|
|
||||||
component ScoreItem: Column {
|
width: parent.width
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
height: 60
|
||||||
spacing: 4
|
color: "lightgray"
|
||||||
|
|
||||||
required property string title
|
|
||||||
required property string value
|
|
||||||
required property int fontPixelSize
|
|
||||||
|
|
||||||
Text {
|
|
||||||
text: parent.title
|
|
||||||
font.pixelSize: Math.round(parent.fontPixelSize * 0.4) // 40% of the dynamic font size
|
|
||||||
font.bold: true
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
|
||||||
Text {
|
|
||||||
text: parent.value
|
|
||||||
font.pixelSize: parent.fontPixelSize // 100% of the dynamic font size
|
|
||||||
horizontalAlignment: Text.AlignHCenter
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
id: scoreContainer
|
id: scoreContainer
|
||||||
|
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
spacing: 40
|
spacing: 40
|
||||||
|
@ -59,14 +37,12 @@ Rectangle {
|
||||||
var hours = Math.floor(seconds / 3600);
|
var hours = Math.floor(seconds / 3600);
|
||||||
var minutes = Math.floor((seconds % 3600) / 60);
|
var minutes = Math.floor((seconds % 3600) / 60);
|
||||||
var remainingSeconds = seconds % 60;
|
var remainingSeconds = seconds % 60;
|
||||||
|
|
||||||
// Format with leading zeros
|
// Format with leading zeros
|
||||||
var formattedTime = "";
|
var formattedTime = "";
|
||||||
if (hours > 0) {
|
if (hours > 0)
|
||||||
formattedTime = (hours < 10 ? "0" : "") + hours + ":"; // include hours if > 0
|
formattedTime = (hours < 10 ? "0" : "") + hours + ":";
|
||||||
}
|
|
||||||
formattedTime += (minutes < 10 ? "0" : "") + minutes + ":" + (remainingSeconds < 10 ? "0" : "") + remainingSeconds;
|
|
||||||
|
|
||||||
|
formattedTime += (minutes < 10 ? "0" : "") + minutes + ":" + (remainingSeconds < 10 ? "0" : "") + remainingSeconds;
|
||||||
return formattedTime;
|
return formattedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,4 +57,28 @@ Rectangle {
|
||||||
fontPixelSize: scoreBarRoot.dynamicFontSize
|
fontPixelSize: scoreBarRoot.dynamicFontSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component ScoreItem: Column {
|
||||||
|
required property string title
|
||||||
|
required property string value
|
||||||
|
required property int fontPixelSize
|
||||||
|
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
spacing: 4
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: parent.title
|
||||||
|
font.pixelSize: Math.round(parent.fontPixelSize * 0.4) // 40% of the dynamic font size
|
||||||
|
font.bold: true
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
text: parent.value
|
||||||
|
font.pixelSize: parent.fontPixelSize // 100% of the dynamic font size
|
||||||
|
horizontalAlignment: Text.AlignHCenter
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ import QtQuick
|
||||||
import Solitare
|
import Solitare
|
||||||
|
|
||||||
// In solitare, Tableau refers to the part of the board where all of the columns are placed
|
// In solitare, Tableau refers to the part of the board where all of the columns are placed
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
|
|
||||||
|
@ -11,10 +10,12 @@ Row {
|
||||||
|
|
||||||
delegate: Column {
|
delegate: Column {
|
||||||
required property int index // passed from repeater
|
required property int index // passed from repeater
|
||||||
|
|
||||||
spacing: -80 // Overlap
|
spacing: -80 // Overlap
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index].length : 1 // Render an empty slot for an empty column
|
model: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index].length : 1 // Render an empty slot for an empty column
|
||||||
|
|
||||||
delegate: CardModel {
|
delegate: CardModel {
|
||||||
required property int index
|
required property int index
|
||||||
property ColumnSlot col: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index][index] : null // empty column (single empty slot)
|
property ColumnSlot col: GameState.columns[parent.index].length > 0 ? GameState.columns[parent.index][index] : null // empty column (single empty slot)
|
||||||
|
@ -22,9 +23,8 @@ Row {
|
||||||
card: col ? col.card : null
|
card: col ? col.card : null
|
||||||
isFaceDown: col ? !col.revealed : false
|
isFaceDown: col ? !col.revealed : false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (col && col.revealed) {
|
if (col && col.revealed)
|
||||||
GameState.autoMoveColumnCard(parent.index, index);
|
GameState.autoMoveColumnCard(parent.index, index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,24 +2,24 @@ import QtQuick
|
||||||
import Solitare
|
import Solitare
|
||||||
|
|
||||||
// The throwaway pile (shows last 3 cards)
|
// The throwaway pile (shows last 3 cards)
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
// This allows makes the cards overlap
|
// This allows makes the cards overlap
|
||||||
spacing: -60
|
spacing: -60
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
model: Math.min(GameState.throwawayPile.length, 3)
|
model: Math.min(GameState.throwawayPile.length, 3)
|
||||||
|
|
||||||
delegate: CardModel {
|
delegate: CardModel {
|
||||||
required property int index // passed from repeater
|
required property int index // passed from repeater
|
||||||
property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index
|
property int reversedIndex: Math.min(GameState.throwawayPile.length, 3) - 1 - index
|
||||||
|
|
||||||
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex]
|
card: GameState.throwawayPile[GameState.throwawayPile.length - 1 - reversedIndex]
|
||||||
isFaceDown: false
|
isFaceDown: false
|
||||||
onClicked: {
|
onClicked: {
|
||||||
// Only auto-move the last card in the throwaway pile
|
// Only auto-move the last card in the throwaway pile
|
||||||
// cards below it are shown, but shouldn't have a click effect
|
// cards below it are shown, but shouldn't have a click effect
|
||||||
if (reversedIndex == 0) {
|
if (reversedIndex == 0)
|
||||||
GameState.autoMoveThrownCard();
|
GameState.autoMoveThrownCard();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue