QTfrontend/hedgehogerWidget.cpp
author unc0rr
Sun, 03 Sep 2006 18:01:34 +0000
changeset 139 340ded7cc336
parent 134 3d87d8e58020
child 140 50ccde437ea1
permissions -rw-r--r--
Fixed AI bug, introduced by previous changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     1
#include "hedgehogerWidget.h"
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     2
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     3
#include <QMouseEvent>
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     4
#include <QPainter>
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     5
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     6
CHedgehogerWidget::CHedgehogerWidget(QWidget * parent) :
134
3d87d8e58020 spacing reduced, 4 hedgehog per team by default
displacer
parents: 133
diff changeset
     7
  QWidget(parent), numHedgedogs(4)
133
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     8
{
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
     9
}
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    10
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    11
void CHedgehogerWidget::mousePressEvent ( QMouseEvent * event )
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    12
{
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    13
  if(event->button()==Qt::LeftButton) {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    14
    event->accept();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    15
    if(numHedgedogs < 8) numHedgedogs++;
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    16
  } else if (event->button()==Qt::RightButton) {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    17
    event->accept();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    18
    if(numHedgedogs > 3) numHedgedogs--;
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    19
  } else {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    20
    event->ignore();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    21
    return;
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    22
  }
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    23
  repaint();
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    24
}
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    25
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    26
void CHedgehogerWidget::paintEvent(QPaintEvent* event)
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    27
{
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    28
  QImage image(":/res/hh25x25.png");
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    29
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    30
  QPainter painter(this);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    31
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    32
  for(int i=0; i<numHedgedogs; i++) {
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    33
    QRect target(11 * i, i % 2, 25, 25);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    34
    painter.drawImage(target, image);
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    35
  }
c79cb5e5b24a - Multiplayer game start button
unc0rr
parents: 132
diff changeset
    36
}