-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcardbutton.hh
More file actions
115 lines (102 loc) · 3.13 KB
/
cardbutton.hh
File metadata and controls
115 lines (102 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* Class CardButton
* ----------
* COMP.CS.110 SPRING 2021
* ----------
* Class for modeling a GUI button component for the playing field cards.
* Derived from QPushButton
* */
#ifndef CARDBUTTON_HH
#define CARDBUTTON_HH
#include "utils.hh"
#include <QPushButton>
#include <QVariant>
#include <QStyle>
//constants for sizes
const int ICON_WIDTH = 100;
const int ICON_HEIGHT = 100;
const int CARDBUTTON_WIDTH = 110;
const int CARDBUTTON_HEIGHT = 110;
//css styles for card buttons in different states
const QString STYLE_SHEET = ""
"/* Base style for all QPushButtons */"
"QPushButton {"
" border-radius: 10px;"
"}"
""
"/* Styles for different states */"
"QPushButton[state='default'] {"
" background-color: transparent;"
" border: 1px solid lightblue;"
"}"
"QPushButton[state='turned'] {"
" background-color: rgba(0, 255, 0, 150);"
" border: 1px solid green"
"}"
"QPushButton[state='turned_no_pair'] {"
" background-color: rgba(255, 0, 0, 150);"
" border: 1px solid red;"
"}"
"QPushButton[state='disabled'] {"
" background-color: transparent;"
" border: 1px solid lightblue;"
"}"
""
"/* Hover styles for different states */"
"QPushButton[state='default']:hover {"
" background-color: rgba(0, 247, 255, 60);"
"}"
"QPushButton[state='disabled']:hover {"
" background-color: rgba(255, 0, 0, 60);"
" border: 1px solid red;"
"}"
""
"/* Pressed styles for different states */"
"QPushButton[state='default']:pressed {"
" background: rgba(0, 247, 255, 100);"
"}";
//QVariants for the above css property values
const QVariant DEFAULT_STATE = QVariant("default");
const QVariant TURNED_STATE = QVariant("turned");
const QVariant TURNED_NO_PAIR_STATE = QVariant("turned_no_pair");
const QVariant DISABLED_STATE = QVariant("disabled");
class CardButton : public QPushButton
{
Q_OBJECT
public:
/**
* Constructor. Creates a CardButton object for the playing field cards.
*
* \param icon int icon to give this card
* \param parent QWidget* parent for this object, default to nullptr
* \return CardButton object
*/
explicit CardButton(int icon, QWidget* parent = Q_NULLPTR);
//turns this card
void turn();
//sets this card as disabled, optionally don't change the style state
void set_disabled(bool change_style_state = true);
//enable this card
void set_enabled();
//set to a state where this card was turned around without a matching pair
void set_turned_no_pair_state();
//returns whether or not this card is turned, true if turned
bool get_turned_state() const;
signals:
//custom signal with an int parameter
void cardbutton_clicked(int);
private slots:
//handles the default click signal from a QPushButton
void handle_click();
private:
//this card's icon
int icon_;
//turned state, true for turned
bool turned_{};
/**
* Sets the specified style state to this button.
*
* \param state QVariant state
*/
void set_style_state(const QVariant& state);
};
#endif // CARDBUTTON_HH