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