From cb75fde6d7c27043228960c05e2eda4b32fb06b9 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 5 Dec 2024 01:22:18 +0100 Subject: [PATCH] Move all qml files to qml/ dir --- CMakeLists.txt | 21 +++++++------- CardModel.qml | 28 ------------------- qml/CardModel.qml | 25 +++++++++++++++++ DrawPile.qml => qml/DrawPile.qml | 3 +- .../FoundationPiles.qml | 3 +- Main.qml => qml/Main.qml | 1 + ScoreBar.qml => qml/ScoreBar.qml | 0 Tableau.qml => qml/Tableau.qml | 11 +++----- ThrowawayPile.qml => qml/ThrowawayPile.qml | 7 +++-- 9 files changed, 49 insertions(+), 50 deletions(-) delete mode 100644 CardModel.qml create mode 100644 qml/CardModel.qml rename DrawPile.qml => qml/DrawPile.qml (85%) rename FoundationPiles.qml => qml/FoundationPiles.qml (76%) rename Main.qml => qml/Main.qml (98%) rename ScoreBar.qml => qml/ScoreBar.qml (100%) rename Tableau.qml => qml/Tableau.qml (72%) rename ThrowawayPile.qml => qml/ThrowawayPile.qml (77%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7100663..bcc5714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,16 +19,17 @@ qt_add_qml_module(appSolitare URI Solitare VERSION 1.0 QML_FILES - Main.qml - QML_FILES ScoreBar.qml - QML_FILES CardModel.qml - QML_FILES Tableau.qml - QML_FILES ThrowawayPile.qml - QML_FILES DrawPile.qml - QML_FILES FoundationPiles.qml - SOURCES playingcard.h playingcard.cpp - SOURCES gamestate.h gamestate.cpp - SOURCES columnslot.h columnslot.cpp + qml/Main.qml + qml/CardModel.qml + qml/DrawPile.qml + qml/FoundationPiles.qml + qml/ScoreBar.qml + qml/Tableau.qml + qml/ThrowawayPile.qml + SOURCES + playingcard.h playingcard.cpp + gamestate.h gamestate.cpp + columnslot.h columnslot.cpp ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. diff --git a/CardModel.qml b/CardModel.qml deleted file mode 100644 index a8193c5..0000000 --- a/CardModel.qml +++ /dev/null @@ -1,28 +0,0 @@ -import QtQuick - -Item { - id: cardModel - width: 80 - height: width * 1.4 // Maintian the aspect ratio of a playing card - - required property PlayingCard card; - required property bool isFaceDown; - property string backStyle: "red" - signal clicked(); - - Image { - id: cardImage - 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" - fillMode: Image.PreserveAspectFit - - MouseArea { - anchors.fill: parent - onClicked: cardModel.clicked() - } - } -} diff --git a/qml/CardModel.qml b/qml/CardModel.qml new file mode 100644 index 0000000..86d9ce0 --- /dev/null +++ b/qml/CardModel.qml @@ -0,0 +1,25 @@ +import QtQuick +import Solitare + +Item { + id: cardModel + width: 80 + height: width * 1.4 // Maintian the aspect ratio of a playing card + + required property PlayingCard card + required property bool isFaceDown + property string backStyle: "red" + signal clicked + + Image { + id: cardImage + 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" + fillMode: Image.PreserveAspectFit + + MouseArea { + anchors.fill: parent + onClicked: cardModel.clicked() + } + } +} diff --git a/DrawPile.qml b/qml/DrawPile.qml similarity index 85% rename from DrawPile.qml rename to qml/DrawPile.qml index 978dacf..8c3da9f 100644 --- a/DrawPile.qml +++ b/qml/DrawPile.qml @@ -1,4 +1,5 @@ import QtQuick +import Solitare // Shows the top card facing down // (or a blank card if the pile is empty) @@ -7,6 +8,6 @@ CardModel { card: GameState.drawPile.length > 0 ? GameState.drawPile[GameState.drawPile.length - 1] : null isFaceDown: GameState.drawPile.length > 0 ? true : false onClicked: { - GameState.drawNextCard() + GameState.drawNextCard(); } } diff --git a/FoundationPiles.qml b/qml/FoundationPiles.qml similarity index 76% rename from FoundationPiles.qml rename to qml/FoundationPiles.qml index c4776cd..5ad49fd 100644 --- a/FoundationPiles.qml +++ b/qml/FoundationPiles.qml @@ -1,4 +1,5 @@ import QtQuick +import Solitare Row { spacing: 15 @@ -6,7 +7,7 @@ Row { Repeater { model: 4 // Each of the 4 suits 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 isFaceDown: false } diff --git a/Main.qml b/qml/Main.qml similarity index 98% rename from Main.qml rename to qml/Main.qml index 1ed1388..37190b2 100644 --- a/Main.qml +++ b/qml/Main.qml @@ -1,6 +1,7 @@ import QtQuick import QtQuick.Controls import QtQuick.Layouts +import Solitare ApplicationWindow { width: 750 diff --git a/ScoreBar.qml b/qml/ScoreBar.qml similarity index 100% rename from ScoreBar.qml rename to qml/ScoreBar.qml diff --git a/Tableau.qml b/qml/Tableau.qml similarity index 72% rename from Tableau.qml rename to qml/Tableau.qml index 32245cc..3c57050 100644 --- a/Tableau.qml +++ b/qml/Tableau.qml @@ -1,4 +1,5 @@ import QtQuick +import Solitare // In solitare, Tableau refers to the part of the board where all of the columns are placed @@ -13,20 +14,16 @@ Row { spacing: -80 // Overlap 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 { 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) card: col ? col.card : null isFaceDown: col ? !col.revealed : false onClicked: { if (col && col.revealed) { - GameState.autoMoveColumnCard(parent.index, index) + GameState.autoMoveColumnCard(parent.index, index); } } } diff --git a/ThrowawayPile.qml b/qml/ThrowawayPile.qml similarity index 77% rename from ThrowawayPile.qml rename to qml/ThrowawayPile.qml index f73b750..edf544e 100644 --- a/ThrowawayPile.qml +++ b/qml/ThrowawayPile.qml @@ -1,4 +1,5 @@ import QtQuick +import Solitare // The throwaway pile (shows last 3 cards) @@ -8,16 +9,16 @@ Row { Repeater { model: Math.min(GameState.throwawayPile.length, 3) - delegate: CardModel { + delegate: CardModel { 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] isFaceDown: false onClicked: { // Only auto-move the last card in the throwaway pile // cards below it are shown, but shouldn't have a click effect if (reversedIndex == 0) { - GameState.autoMoveThrownCard() + GameState.autoMoveThrownCard(); } } }