solitare/playingcard.h

71 lines
1.5 KiB
C
Raw Normal View History

2024-12-01 18:43:49 +00:00
#ifndef PLAYINGCARD_H
#define PLAYINGCARD_H
#include <QObject>
#include <qqmlintegration.h>
2024-12-01 18:43:49 +00:00
class PlayingCard : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_UNCREATABLE("Use C++ logic to instantiate")
Q_ENUMS(Value)
Q_ENUMS(Suit)
2024-12-02 23:33:22 +00:00
Q_PROPERTY(Suit suit READ suit WRITE setSuit NOTIFY suitChanged REQUIRED)
Q_PROPERTY(Value value READ value WRITE setValue NOTIFY valueChanged REQUIRED)
2024-12-01 18:43:49 +00:00
2024-12-02 23:33:22 +00:00
Q_PROPERTY(QString valueString READ valueString NOTIFY valueChanged)
Q_PROPERTY(QString suitString READ suitString NOTIFY suitChanged)
2024-12-01 18:43:49 +00:00
public:
enum Value {
Ace = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13,
};
2024-12-01 18:43:49 +00:00
enum Suit {
Clubs,
Diamonds,
Hearts,
Spades,
};
2024-12-01 18:43:49 +00:00
explicit PlayingCard(const Suit &suit = Suit::Clubs, const Value &value = Value::Ace, QObject *parent = nullptr);
Suit suit() const;
QString suitString() const;
void setSuit(const Suit &suit);
Value value() const;
QString valueString() const;
void setValue(const Value &value);
2024-12-01 18:43:49 +00:00
2024-12-03 14:14:27 +00:00
QString toString() const;
static QList<PlayingCard*> createDeck();
2024-12-01 21:40:42 +00:00
static bool areOppositeColors(const PlayingCard &card1, const PlayingCard &card2);
2024-12-01 18:43:49 +00:00
signals:
2024-12-02 23:33:22 +00:00
void suitChanged();
void valueChanged();
2024-12-01 18:43:49 +00:00
private:
Suit m_suit;
Value m_value;
2024-12-01 18:43:49 +00:00
};
#endif // PLAYINGCARD_H