133
|
1 |
#include "hedgehogerWidget.h"
|
|
2 |
|
|
3 |
#include <QMouseEvent>
|
|
4 |
#include <QPainter>
|
|
5 |
|
|
6 |
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
|
134
|
7 |
QWidget(parent), numHedgedogs(4)
|
133
|
8 |
{
|
|
9 |
}
|
|
10 |
|
|
11 |
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
|
|
12 |
{
|
|
13 |
if(event->button()==Qt::LeftButton) {
|
|
14 |
event->accept();
|
|
15 |
if(numHedgedogs < 8) numHedgedogs++;
|
|
16 |
} else if (event->button()==Qt::RightButton) {
|
|
17 |
event->accept();
|
|
18 |
if(numHedgedogs > 3) numHedgedogs--;
|
|
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 |
|
|
32 |
for(int i=0; i<numHedgedogs; i++) {
|
|
33 |
QRect target(11 * i, i % 2, 25, 25);
|
|
34 |
painter.drawImage(target, image);
|
|
35 |
}
|
|
36 |
}
|