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