132
|
1 |
#include "hedgehogerWidget.h"
|
|
2 |
|
|
3 |
#include <QMouseEvent>
|
|
4 |
#include <QPainter>
|
|
5 |
|
|
6 |
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
|
|
7 |
QWidget(parent), numHedgedogs(3)
|
|
8 |
{
|
|
9 |
}
|
|
10 |
|
|
11 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
|
|
12 |
{
|
|
13 |
if(event->button()==Qt::LeftButton) {
|
|
14 |
event->accept();
|
|
15 |
numHedgedogs++;
|
|
16 |
} else if (event->button()==Qt::RightButton) {
|
|
17 |
event->accept();
|
|
18 |
if(numHedgedogs!=0) numHedgedogs--;
|
|
19 |
} else {
|
|
20 |
event->ignore();
|
|
21 |
return;
|
|
22 |
}
|
|
23 |
repaint();
|
|
24 |
}
|
|
25 |
|
|
26 |
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
|
|
27 |
{
|
|
28 |
QRectF source(0.0, 0.0, 32.0, 32.0);
|
|
29 |
QImage image("../share/hedgewars/Data/Graphics/Hedgehog.png");
|
|
30 |
|
|
31 |
QPainter painter(this);
|
|
32 |
|
|
33 |
for(int i=0; i<numHedgedogs; i++) {
|
|
34 |
QRectF target(0.0+12.5*i, 0.0, 25.0, 25.0);
|
|
35 |
painter.drawImage(target, image, source);
|
|
36 |
}
|
|
37 |
}
|