QTfrontend/itemNum.cpp
author displacer
Mon, 24 Sep 2007 20:34:28 +0000
changeset 612 333d095319de
child 624 e7673b036db5
permissions -rw-r--r--
abstract class for items container (hedgehogs num, bullets, etc.)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
612
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     1
/*
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     2
 * Hedgewars, a worms-like game
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     3
 * Copyright (c) 2006, 2007 Ulyanov Igor <iulyanov@gmail.com>
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     4
 *
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     8
 *
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    12
 * GNU General Public License for more details.
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    13
 *
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    17
 */
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    18
 
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    19
#include "itemNum.h"
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    20
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    21
#include <QMouseEvent>
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    22
#include <QPainter>
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    23
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    24
ItemNum::ItemNum(const QImage& im, QWidget * parent) :
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    25
    m_im(im), QWidget(parent), nonInteractive(false)
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    26
{
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    27
}
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    28
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    29
ItemNum::~ItemNum()
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    30
{
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    31
}
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    32
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    33
void ItemNum::mousePressEvent ( QMouseEvent * event )
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    34
{
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    35
  if(nonInteractive) return;
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    36
  if(event->button()==Qt::LeftButton) {
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    37
    event->accept();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    38
    incItems();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    39
  } else if (event->button()==Qt::RightButton) {
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    40
    event->accept();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    41
    decItems();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    42
  } else {
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    43
    event->ignore();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    44
    return;
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    45
  }
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    46
  repaint();
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    47
}
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    48
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    49
void ItemNum::paintEvent(QPaintEvent* event)
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    50
{
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    51
  QPainter painter(this);
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    52
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    53
  for(int i=0; i<numItems; i++) {
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    54
    QRect target(11 * i, i % 2, 25, 25);
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    55
    painter.drawImage(target, m_im);
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    56
  }
333d095319de abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff changeset
    57
}