author | nemo |
Sat, 06 Mar 2010 01:26:12 +0000 | |
changeset 2946 | 1d9e0a541c62 |
parent 2377 | f3fab2b09e0c |
child 4412 | c9a78ba03679 |
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 |
*/ |
2377 | 18 |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
19 |
#include "itemNum.h" |
2098
c977d7f2aa09
Toggle for stars ("frontend effects") - also turns off optimisations for stars that were causing problems onone machine
nemo
parents:
2072
diff
changeset
|
20 |
#include "hwform.h" |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
21 |
|
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
22 |
#include <QMouseEvent> |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
23 |
#include <QPainter> |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
24 |
|
624 | 25 |
ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) : |
1904 | 26 |
QFrame(parent), m_im(im), infinityState(false), nonInteractive(false), minItems(min), maxItems(max), |
27 |
numItems(min+2 >= max ? min : min+2) |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
28 |
{ |
2098
c977d7f2aa09
Toggle for stars ("frontend effects") - also turns off optimisations for stars that were causing problems onone machine
nemo
parents:
2072
diff
changeset
|
29 |
if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); |
612
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 |
ItemNum::~ItemNum() |
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 |
|
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
36 |
void ItemNum::mousePressEvent ( QMouseEvent * event ) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
37 |
{ |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
38 |
if(nonInteractive) return; |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
39 |
if(event->button()==Qt::LeftButton) { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
40 |
event->accept(); |
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
41 |
if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) { |
640 | 42 |
incItems(); |
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
43 |
} else { |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
44 |
numItems = minItems+1; |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
45 |
// appears there's an emit in there |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
46 |
decItems(); |
624 | 47 |
} |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
48 |
} else if (event->button()==Qt::RightButton) { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
49 |
event->accept(); |
624 | 50 |
if(numItems > minItems) { |
51 |
decItems(); |
|
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
52 |
} else { |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
53 |
numItems = maxItems+(infinityState?0:-1); |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
54 |
incItems(); |
624 | 55 |
} |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
56 |
} else { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
57 |
event->ignore(); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
58 |
return; |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
59 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
60 |
repaint(); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
61 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
62 |
|
643 | 63 |
QSize ItemNum::sizeHint () const |
64 |
{ |
|
65 |
return QSize((maxItems+1)*12, 32); |
|
66 |
} |
|
67 |
||
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
68 |
void ItemNum::paintEvent(QPaintEvent* event) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
69 |
{ |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
70 |
QPainter painter(this); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
71 |
|
640 | 72 |
if (numItems==maxItems+1) { |
642 | 73 |
QRect target(0, 0, 100, 32); |
640 | 74 |
painter.drawImage(target, QImage(":/res/infinity.png")); |
75 |
} else { |
|
76 |
for(int i=0; i<numItems; i++) { |
|
1455 | 77 |
QRect target(11 * i, i % 2, 25, 35); |
640 | 78 |
painter.drawImage(target, m_im); |
79 |
} |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
80 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
81 |
} |
624 | 82 |
|
83 |
unsigned char ItemNum::getItemsNum() const |
|
84 |
{ |
|
85 |
return numItems; |
|
86 |
} |
|
87 |
||
88 |
void ItemNum::setItemsNum(const unsigned char num) |
|
89 |
{ |
|
90 |
numItems=num; |
|
91 |
} |
|
640 | 92 |
|
93 |
void ItemNum::setInfinityState(bool value) |
|
94 |
{ |
|
95 |
infinityState=value; |
|
96 |
} |