QTfrontend/hedgehogerWidget.cpp
author displacer
Sun, 03 Sep 2006 14:15:41 +0000
changeset 134 3d87d8e58020
parent 133 c79cb5e5b24a
child 140 50ccde437ea1
permissions -rw-r--r--
spacing reduced, 4 hedgehog per team by default

#include "hedgehogerWidget.h"

#include <QMouseEvent>
#include <QPainter>

CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
  QWidget(parent), numHedgedogs(4)
{
}

void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
{
  if(event->button()==Qt::LeftButton) {
    event->accept();
    if(numHedgedogs < 8) numHedgedogs++;
  } else if (event->button()==Qt::RightButton) {
    event->accept();
    if(numHedgedogs > 3) numHedgedogs--;
  } else {
    event->ignore();
    return;
  }
  repaint();
}

void CHedgehogerWidget::paintEvent(QPaintEvent* event)
{
  QImage image(":/res/hh25x25.png");

  QPainter painter(this);

  for(int i=0; i<numHedgedogs; i++) {
    QRect target(11 * i, i % 2, 25, 25);
    painter.drawImage(target, image);
  }
}