-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.cpp
62 lines (53 loc) · 1.13 KB
/
card.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
#include "card.h"
#include "cardfield.h"
#include <QGridLayout>
#include <ctime>
#include <thread>
Card::Card(QWidget* parent, int _id, QString backSidePath, QString frontSidePath, int w, int h, CardField* f) :
QWidget(parent), id(_id), width(w), height(h), field(f)
{
QGridLayout* mainLayout = new QGridLayout(this);
QSize s(w, h);
frontSide = new QIcon(QPixmap(frontSidePath));
backSide = new QIcon(QPixmap(backSidePath));
card = new QPushButton();
connect(card, SIGNAL(clicked()), SLOT(pushed()));
card->setIcon(*backSide);
card->setFixedSize(s);
card->setIconSize(s);
mainLayout->addWidget(card, 0, 0, 3, 2, Qt::AlignCenter);
state = false;
}
Card::~Card()
{
delete card;
delete backSide;
delete frontSide;
}
bool Card::getState() const
{
return state;
}
void Card::changeState()
{
state = !state;
}
int Card::getId() const
{
return id;
}
void Card::pushed()
{
if(!state)
{
card->setIcon(*frontSide);
changeState();
field->check();
}
else
{
card->setIcon(*backSide);
changeState();
//field->check();
}
}