QTfrontend/hedgehogerWidget.cpp
author unc0rr
Sat, 09 Sep 2006 17:59:25 +0000
changeset 141 ac3680be1f4b
parent 140 50ccde437ea1
child 147 52a3c431db8a
permissions -rw-r--r--
- Small fix for AI - Full-functional Multiplayer
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) :
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
     7
  QWidget(parent), numHedgehogs(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();
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    15
    if(numHedgehogs < 8) numHedgehogs++;
133
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();
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    18
    if(numHedgehogs > 3) numHedgehogs--;
133
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
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    32
  for(int i=0; i<numHedgehogs; i++) {
133
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
}
140
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    37
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    38
unsigned char CHedgehogerWidget::getHedgehogsNum()
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    39
{
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    40
  return numHedgehogs;
50ccde437ea1 teams and hedgedogs num selection added to HWgame
displacer
parents: 134
diff changeset
    41
}