QTfrontend/hedgehogerWidget.cpp
author displacer
Sun, 03 Sep 2006 12:56:13 +0000
changeset 132 2d0f404cdf05
child 133 c79cb5e5b24a
permissions -rw-r--r--
first hedgehogs number selection added
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
132
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     1
#include "hedgehogerWidget.h"
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     2
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     3
#include <QMouseEvent>
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     4
#include <QPainter>
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     5
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     6
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     7
  QWidget(parent), numHedgedogs(3)
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     8
{
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
     9
}
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    10
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    11
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    12
{
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    13
  if(event->button()==Qt::LeftButton) {
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    14
    event->accept();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    15
    numHedgedogs++;
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    16
  } else if (event->button()==Qt::RightButton) {
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    17
    event->accept();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    18
    if(numHedgedogs!=0) numHedgedogs--;
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    19
  } else {
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    20
    event->ignore();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    21
    return;
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    22
  }
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    23
  repaint();
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    24
}
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    25
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    26
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    27
{
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    28
  QRectF source(0.0, 0.0, 32.0, 32.0);
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    29
  QImage image("../share/hedgewars/Data/Graphics/Hedgehog.png");
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    30
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    31
  QPainter painter(this);
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    32
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    33
  for(int i=0; i<numHedgedogs; i++) {
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    34
    QRectF target(0.0+12.5*i, 0.0, 25.0, 25.0);
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    35
    painter.drawImage(target, image, source);
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    36
  }
2d0f404cdf05 first hedgehogs number selection added
displacer
parents:
diff changeset
    37
}