-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcardlist.cpp
78 lines (75 loc) · 2.9 KB
/
qcardlist.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
78
#include "qcardlist.h"
#include "mainwindow.h"
#include <cstdlib>
QCardList::QCardList(char type, QPoint offset, QWidget *parent, MainWindow *window) : QLabel()
{
this->type = type;
this->offset = offset;
this->parentWindow = window;
this->cardList = new TDALISTA<QSolitaireCard*>();
this->relations = new TDALISTA<QCardList*>();
this->lockedcardoffset = QPoint(0, 7);
this->releasedcardoffset = QPoint(0, 20);
this->setFixedHeight(105);
this->setFixedWidth(79);
setParent(parent);
move(offset);
}
void QCardList::mousePressEvent(QMouseEvent *event)
{
event->type();
if(type == 'M'){
if(cardList->size() != 0){
cardList->end()->offset.setX(relations->get(0)->offset.x());
cardList->end()->offset.setY(relations->get(0)->offset.y());
cardList->end()->move(cardList->end()->offset);
cardList->end()->flip();
cardList->end()->raise();
relations->get(0)->cardList->add(cardList->end());
cardList->remove(cardList->size()-1);
}else{
while(relations->get(0)->cardList->size()!= 0){
relations->get(0)->cardList->end()->offset = offset;
relations->get(0)->cardList->end()->offset.setX(offset.x());
relations->get(0)->cardList->end()->offset.setY(offset.y());
relations->get(0)->cardList->end()->move(relations->get(0)->cardList->end()->offset);
relations->get(0)->cardList->end()->flip();
relations->get(0)->cardList->end()->raise();
cardList->add(relations->get(0)->cardList->end());
relations->get(0)->cardList->remove(relations->get(0)->cardList->size()-1);
}
raise();
}
relations->get(0)->updateList();
parentWindow->checkGameStatus();
}
}
void QCardList::populate()
{
if(isdigit(type)){
int torepeat = atoi(&type);
QPoint extraoffset(0, 0);
for(int i = 0; i < torepeat; i++){
relations->get(0)->cardList->end()->offset.setX((offset.x()) + (extraoffset.x()));
relations->get(0)->cardList->end()->offset.setY((offset.y()) + (extraoffset.y()));
relations->get(0)->cardList->end()->move(relations->get(0)->cardList->end()->offset);
relations->get(0)->cardList->end()->raise();
cardList->add(relations->get(0)->cardList->end());
relations->get(0)->cardList->remove(relations->get(0)->cardList->size()-1);
extraoffset += lockedcardoffset;
}
relations->remove(0);
cardList->end()->flip();
}
}
void QCardList::updateList()
{
if(cardList->size()==0)
return;
if(cardList->end()->islocked)
cardList->end()->flip();
for(int i = 0; i < cardList->size(); i++){
cardList->get(i)->relations = this->relations;
cardList->get(i)->parentList = this;
}
}