-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcardbutton.cpp
77 lines (68 loc) · 1.94 KB
/
cardbutton.cpp
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
#include "cardbutton.hh"
CardButton::CardButton(const int icon, QWidget* parent)
: QPushButton(parent), icon_(icon)
{
connect(this, &QPushButton::clicked, this, &CardButton::handle_click);
this->setProperty("state", DEFAULT_STATE);
this->setStyleSheet(STYLE_SHEET);
this->setIcon(get_icon(utils::back));
this->setIconSize(QSize(ICON_WIDTH, ICON_HEIGHT));
this->setCursor(Qt::PointingHandCursor);
this->setFixedSize(CARDBUTTON_WIDTH, CARDBUTTON_HEIGHT);
auto size_policy = this->sizePolicy();
size_policy.setRetainSizeWhenHidden(true);
this->setSizePolicy(size_policy);
}
void CardButton::turn()
{
if (turned_)
{
//if card was already turned, it's being turned back
this->setIcon(get_icon(utils::back));
set_enabled();
}
else
{
this->setIcon(utils::get_icon(icon_));
this->set_style_state(TURNED_STATE);
set_disabled(false);
}
turned_ = !turned_;
}
void CardButton::set_disabled(const bool change_style_state)
{
//optionally don't set the style state
if (change_style_state)
{
this->set_style_state(DISABLED_STATE);
}
this->setCursor(Qt::ForbiddenCursor);
//block signals so further presses of the button don't do anything
this->blockSignals(true);
}
void CardButton::set_enabled()
{
this->set_style_state(DEFAULT_STATE);
this->setCursor(Qt::PointingHandCursor);
this->blockSignals(false);
}
void CardButton::set_turned_no_pair_state()
{
set_style_state(TURNED_NO_PAIR_STATE);
}
bool CardButton::get_turned_state() const
{
return turned_;
}
void CardButton::handle_click()
{
//emit custom signal with an argument
emit cardbutton_clicked(icon_);
}
void CardButton::set_style_state(const QVariant& state)
{
//style has to unpolished and polished for a property change to effect
this->setProperty("state", state);
this->style()->unpolish(this);
this->style()->polish(this);
}