author | unc0rr |
Thu, 14 Aug 2008 14:04:45 +0000 | |
changeset 1210 | bfed1b89bc85 |
parent 1066 | 1f1b3686a2b0 |
child 1455 | 7d0a4ecd8210 |
permissions | -rw-r--r-- |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2006-2008 Ulyanov Igor <iulyanov@gmail.com> |
612
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 |
|
624 | 24 |
ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) : |
642 | 25 |
m_im(im), QWidget(parent), nonInteractive(false), minItems(min), maxItems(max), |
26 |
numItems(min+2 >= max ? min : min+2), |
|
640 | 27 |
infinityState(false) |
612
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 |
} |
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 |
ItemNum::~ItemNum() |
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 |
} |
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 |
void ItemNum::mousePressEvent ( QMouseEvent * event ) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
36 |
{ |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
37 |
if(nonInteractive) return; |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
38 |
if(event->button()==Qt::LeftButton) { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
39 |
event->accept(); |
640 | 40 |
if(infinityState && numItems==maxItems) { |
41 |
incItems(); |
|
42 |
} |
|
624 | 43 |
if(numItems < maxItems) { |
44 |
incItems(); |
|
45 |
} |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
46 |
} else if (event->button()==Qt::RightButton) { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
47 |
event->accept(); |
624 | 48 |
if(numItems > minItems) { |
49 |
decItems(); |
|
50 |
} |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
51 |
} else { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
52 |
event->ignore(); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
53 |
return; |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
54 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
55 |
repaint(); |
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 |
|
643 | 58 |
QSize ItemNum::sizeHint () const |
59 |
{ |
|
60 |
return QSize((maxItems+1)*12, 32); |
|
61 |
} |
|
62 |
||
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
63 |
void ItemNum::paintEvent(QPaintEvent* event) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
64 |
{ |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
65 |
QPainter painter(this); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
66 |
|
640 | 67 |
if (numItems==maxItems+1) { |
642 | 68 |
QRect target(0, 0, 100, 32); |
640 | 69 |
painter.drawImage(target, QImage(":/res/infinity.png")); |
70 |
} else { |
|
71 |
for(int i=0; i<numItems; i++) { |
|
72 |
QRect target(11 * i, i % 2, 25, 25); |
|
73 |
painter.drawImage(target, m_im); |
|
74 |
} |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
75 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
76 |
} |
624 | 77 |
|
78 |
unsigned char ItemNum::getItemsNum() const |
|
79 |
{ |
|
80 |
return numItems; |
|
81 |
} |
|
82 |
||
83 |
void ItemNum::setItemsNum(const unsigned char num) |
|
84 |
{ |
|
85 |
numItems=num; |
|
86 |
} |
|
640 | 87 |
|
88 |
void ItemNum::setInfinityState(bool value) |
|
89 |
{ |
|
90 |
infinityState=value; |
|
91 |
} |