diff --git a/CardModel.qml b/CardModel.qml index a26e50f..5aa9c26 100644 --- a/CardModel.qml +++ b/CardModel.qml @@ -7,16 +7,13 @@ Item { height: width * 1.4 // Maintian the aspect ratio of a playing card required property PlayingCard card; + required property bool isFaceDown; property string backStyle: "red" - // 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. - Image { id: cardImage anchors.fill: parent - source: cardModel.card.isFaceDown + source: cardModel.isFaceDown ? "qrc:/img/playing_cards/backs/" + cardModel.backStyle + ".svg" : "qrc:/img/playing_cards/fronts/" + cardModel.card.suitString + "_" + cardModel.card.valueString + ".svg" fillMode: Image.PreserveAspectFit diff --git a/Main.qml b/Main.qml index 1d83025..0408694 100644 --- a/Main.qml +++ b/Main.qml @@ -21,5 +21,6 @@ ApplicationWindow { CardModel { anchors.centerIn: parent card: myCard + isFaceDown: false } } diff --git a/playingcard.cpp b/playingcard.cpp index 6981c67..b69345f 100644 --- a/playingcard.cpp +++ b/playingcard.cpp @@ -1,7 +1,7 @@ #include "playingcard.h" -PlayingCard::PlayingCard(const PlayingCard::Suit &suit, const PlayingCard::Value &value, bool isFaceDown, QObject *parent) - : QObject{parent}, m_suit{suit}, m_value{value}, m_isFaceDown{isFaceDown} +PlayingCard::PlayingCard(const PlayingCard::Suit &suit, const PlayingCard::Value &value, QObject *parent) + : QObject{parent}, m_suit{suit}, m_value{value} { } PlayingCard::Suit PlayingCard::suit() const @@ -63,20 +63,6 @@ void PlayingCard::setValue(const PlayingCard::Value &value) emit onValueChanged(); } -bool PlayingCard::isFaceDown() const -{ - return m_isFaceDown; -} - -void PlayingCard::setIsFaceDown(bool faceDown) -{ - if (m_isFaceDown == faceDown) - return; - - m_isFaceDown = faceDown; - emit onIsFaceDownChanged(); -} - QList PlayingCard::createDeck() { QList deck; @@ -86,7 +72,6 @@ QList PlayingCard::createDeck() PlayingCard *card = new PlayingCard(); card->setSuit(static_cast(suitIndex)); card->setValue(static_cast(valueIndex)); - card->setIsFaceDown(true); // All cards are face down initially deck.append(card); } } diff --git a/playingcard.h b/playingcard.h index 18bf36b..3ebbda5 100644 --- a/playingcard.h +++ b/playingcard.h @@ -12,7 +12,6 @@ class PlayingCard : public QObject Q_PROPERTY(Suit suit READ suit WRITE setSuit NOTIFY onSuitChanged REQUIRED) Q_PROPERTY(Value value READ value WRITE setValue NOTIFY onValueChanged REQUIRED) - Q_PROPERTY(bool isFaceDown READ isFaceDown WRITE setIsFaceDown NOTIFY onIsFaceDownChanged) Q_PROPERTY(QString valueString READ valueString NOTIFY onValueChanged) Q_PROPERTY(QString suitString READ suitString NOTIFY onSuitChanged) @@ -41,7 +40,7 @@ public: Spades, }; - explicit PlayingCard(const Suit &suit = Suit::Clubs, const Value &value = Value::Ace, bool isFaceDown = false, QObject *parent = nullptr); + explicit PlayingCard(const Suit &suit = Suit::Clubs, const Value &value = Value::Ace, QObject *parent = nullptr); Suit suit() const; QString suitString() const; @@ -51,21 +50,15 @@ public: QString valueString() const; void setValue(const Value &value); - bool isFaceDown() const; - void setIsFaceDown(bool faceDown); - static QList createDeck(); signals: void onSuitChanged(); void onValueChanged(); - void onIsFaceDownChanged(); private: Suit m_suit; Value m_value; - bool m_isFaceDown; - QString m_imgUrl; }; #endif // PLAYINGCARD_H