author | displacer |
Sat, 16 Sep 2006 17:24:41 +0000 | |
changeset 150 | d9e8a336195c |
parent 147 | 52a3c431db8a |
child 153 | dc10da2a73f9 |
permissions | -rw-r--r-- |
133 | 1 |
#include "hedgehogerWidget.h" |
2 |
||
3 |
#include <QMouseEvent> |
|
4 |
#include <QPainter> |
|
5 |
||
150 | 6 |
#include "frameTeam.h" |
147 | 7 |
|
133 | 8 |
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) : |
150 | 9 |
QWidget(parent) |
133 | 10 |
{ |
150 | 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; |
|
147 | 18 |
} |
19 |
||
20 |
CHedgehogerWidget::~CHedgehogerWidget() |
|
21 |
{ |
|
150 | 22 |
pOurFrameTeams->overallHedgehogs-=numHedgehogs; |
133 | 23 |
} |
24 |
||
25 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event ) |
|
26 |
{ |
|
27 |
if(event->button()==Qt::LeftButton) { |
|
28 |
event->accept(); |
|
150 | 29 |
if(numHedgehogs < 8 && pOurFrameTeams->overallHedgehogs<18) { |
147 | 30 |
numHedgehogs++; |
150 | 31 |
pOurFrameTeams->overallHedgehogs++; |
147 | 32 |
} |
133 | 33 |
} else if (event->button()==Qt::RightButton) { |
34 |
event->accept(); |
|
147 | 35 |
if(numHedgehogs > 3) { |
36 |
numHedgehogs--; |
|
150 | 37 |
pOurFrameTeams->overallHedgehogs--; |
147 | 38 |
} |
133 | 39 |
} else { |
40 |
event->ignore(); |
|
41 |
return; |
|
42 |
} |
|
43 |
repaint(); |
|
44 |
} |
|
45 |
||
46 |
void CHedgehogerWidget::paintEvent(QPaintEvent* event) |
|
47 |
{ |
|
48 |
QImage image(":/res/hh25x25.png"); |
|
49 |
||
50 |
QPainter painter(this); |
|
51 |
||
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
52 |
for(int i=0; i<numHedgehogs; i++) { |
133 | 53 |
QRect target(11 * i, i % 2, 25, 25); |
54 |
painter.drawImage(target, image); |
|
55 |
} |
|
56 |
} |
|
140
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
57 |
|
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
58 |
unsigned char CHedgehogerWidget::getHedgehogsNum() |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
59 |
{ |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
60 |
return numHedgehogs; |
50ccde437ea1
teams and hedgedogs num selection added to HWgame
displacer
parents:
134
diff
changeset
|
61 |
} |