-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeckWidget.cpp
132 lines (110 loc) · 3.62 KB
/
DeckWidget.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <QFileInfo>
#include <QMessageBox>
#include <QSpacerItem>
#include "DeckWidget.h"
map<LocationInfo ,set<DeckWidget *>>DeckWidget::mapWidgetGroup_ = DeckWidget::CreatStaticMap();
DeckWidget::DeckWidget(CardSet * deckPtr , QWidget * eventFilterHub ,LocationInfo location ,CallBack &&callBack)
:eventFilterHub_(eventFilterHub),
layout_(new QGridLayout),
deckPtr_(deckPtr),
location_(location),
deckChangeCallBack_(callBack)
{
this->setLayout(layout_);
if (location == LocationInfo::Tab2MainDeck)
allyLocation_ = LocationInfo::Tab1MainDeck;
else allyLocation_ = location;
mapWidgetGroup_[allyLocation_].insert(this);
}
DeckWidget::~DeckWidget()
{
mapWidgetGroup_[allyLocation_].erase(this);
}
map<LocationInfo ,set<DeckWidget *>> DeckWidget::CreatStaticMap()
{
map<LocationInfo ,set<DeckWidget *>> tempMap;
return tempMap;
}
void DeckWidget::Refresh()
{
/*if (allyLocation_ != LocationInfo::Tab2EditDeck)
{
for (auto it : mapWidgetGroup_[allyLocation_])
it->InnerRefresh();
}else
InnerRefresh();*/
InnerRefresh();
if (deckChangeCallBack_ != nullptr)
deckChangeCallBack_();
}
void DeckWidget::Clear()
{
while (auto item = layout_->itemAt(0))
{
layout_->takeAt(0);
auto widget = item->widget();
if (widget == nullptr)
continue;
widget->removeEventFilter(eventFilterHub_);
widget->disconnect();
widget->setParent(nullptr);
}
}
void DeckWidget::AddCard(QString cardCode)
{
if (DataMgrIns.GetCardDataByCode(cardCode) == nullptr) return;
LocationInfo cardLocation = DataMgrIns.GetCardLocationByCode(cardCode);
if ((cardLocation == LocationInfo::Tab1ExtraDeck && allyLocation_ == LocationInfo::Tab1MainDeck)||
(cardLocation == LocationInfo::Tab1MainDeck && allyLocation_ == LocationInfo::Tab1ExtraDeck))
return ;
if ((allyLocation_ == LocationInfo::Tab1MainDeck && deckPtr_->size() > 64)||
(allyLocation_ == LocationInfo::Tab1ExtraDeck && deckPtr_->size() > 19)||
(allyLocation_ == LocationInfo::Tab1SideDeck && deckPtr_->size() > 19)||
(location_ == LocationInfo::Tab2EditDeck && deckPtr_->size() > 6))
return ;
QString picPath = DataMgrIns.GetCardPicPathByCardCode(cardCode);
QFileInfo file(picPath);
if (!file.isFile())
{
picPath = DataMgrIns.defaultCardPic_;
}
YGOCardPushButton * btn = new YGOCardPushButton(picPath, cardCode);
btn->setFixedHeight(DECK_CARD_HEIGHT);
btn->setFixedWidth(DECK_CARD_WIDTH);
QPixmap pixmap(picPath);
QPixmap fitpixmap = pixmap.scaled(DECK_CARD_WIDTH, DECK_CARD_HEIGHT, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
btn->setIcon(QIcon(fitpixmap));
btn->setIconSize(QSize(500, 500));
btn->setFlat(true);
deckPtr_->insert(btn ,true);
Refresh();
}
void DeckWidget::InnerRefresh()
{
Clear();
int col = 0;
int row = 0;
auto & targetSet = deckPtr_->GetInnerSet();
int columnLimit = 0;
if (location_ == LocationInfo::Tab2EditDeck)
columnLimit = TAB2_EDIT_DECK_COLUMN;
else if (location_ == LocationInfo::Tab2MainDeck)
columnLimit = TAB2_DECK_COLUMN;
else
columnLimit = DECK_FRAME_COLUMN;
for (auto ptr : targetSet)
{
layout_->addWidget(ptr ,row, col++);
ptr->installEventFilter(eventFilterHub_);
if (col == columnLimit)
{
col = 0;
++row;
}
}
if (targetSet.size() < columnLimit)
{
QSpacerItem *spaceItem = new QSpacerItem(668 , 0);
layout_->addItem(spaceItem,row,col);
}
}