1 #include "hedgehogerWidget.h" |
1 #include "hedgehogerWidget.h" |
2 |
2 |
3 #include <QMouseEvent> |
3 #include <QMouseEvent> |
4 #include <QPainter> |
4 #include <QPainter> |
5 |
5 |
6 int overallHedgehogs=0; |
6 #include "frameTeam.h" |
7 |
7 |
8 CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) : |
8 CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) : |
9 QWidget(parent), numHedgehogs(4) |
9 QWidget(parent) |
10 { |
10 { |
11 overallHedgehogs+=numHedgehogs; |
11 if(parent) { |
|
12 pOurFrameTeams=dynamic_cast<FrameTeams*>(parent->parentWidget()); |
|
13 } |
|
14 if(pOurFrameTeams->overallHedgehogs+4>pOurFrameTeams->maxHedgehogsPerGame) { |
|
15 numHedgehogs=pOurFrameTeams->maxHedgehogsPerGame-pOurFrameTeams->overallHedgehogs; |
|
16 } else numHedgehogs=4; |
|
17 pOurFrameTeams->overallHedgehogs+=numHedgehogs; |
12 } |
18 } |
13 |
19 |
14 CHedgehogerWidget::~CHedgehogerWidget() |
20 CHedgehogerWidget::~CHedgehogerWidget() |
15 { |
21 { |
16 overallHedgehogs-=numHedgehogs; |
22 pOurFrameTeams->overallHedgehogs-=numHedgehogs; |
17 } |
23 } |
18 |
24 |
19 void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event ) |
25 void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event ) |
20 { |
26 { |
21 if(event->button()==Qt::LeftButton) { |
27 if(event->button()==Qt::LeftButton) { |
22 event->accept(); |
28 event->accept(); |
23 if(numHedgehogs < 8 && overallHedgehogs<18) { |
29 if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) { |
24 numHedgehogs++; |
30 numHedgehogs++; |
25 overallHedgehogs++; |
31 pOurFrameTeams->overallHedgehogs++; |
26 } |
32 } |
27 } else if (event->button()==Qt::RightButton) { |
33 } else if (event->button()==Qt::RightButton) { |
28 event->accept(); |
34 event->accept(); |
29 if(numHedgehogs > 3) { |
35 if(numHedgehogs > 3) { |
30 numHedgehogs--; |
36 numHedgehogs--; |
31 overallHedgehogs--; |
37 pOurFrameTeams->overallHedgehogs--; |
32 } |
38 } |
33 } else { |
39 } else { |
34 event->ignore(); |
40 event->ignore(); |
35 return; |
41 return; |
36 } |
42 } |