author | sheepluva |
Thu, 20 Oct 2011 02:56:58 +0200 | |
changeset 6157 | 9c474b8a8b5e |
parent 6153 | 3881126e06e8 |
child 6428 | 2d2b5e3c59a7 |
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 |
4976 | 3 |
* Copyright (c) 2006-2011 Igor Ulyanov <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 |
|
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
25 |
ItemNum::ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min, unsigned char max) : |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
26 |
QFrame(parent), m_im(im), m_img(img), infinityState(false), nonInteractive(false), minItems(min), maxItems(max), |
1904 | 27 |
numItems(min+2 >= max ? min : min+2) |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
28 |
{ |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
29 |
enabled = true; |
2098
c977d7f2aa09
Toggle for stars ("frontend effects") - also turns off optimisations for stars that were causing problems onone machine
nemo
parents:
2072
diff
changeset
|
30 |
if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true); |
612
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 |
ItemNum::~ItemNum() |
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 |
|
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
37 |
void ItemNum::mousePressEvent ( QMouseEvent * event ) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
38 |
{ |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
39 |
if(nonInteractive) return; |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
40 |
if(event->button()==Qt::LeftButton && enabled) { |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
41 |
event->accept(); |
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
42 |
if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) { |
640 | 43 |
incItems(); |
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
44 |
} else { |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
45 |
numItems = minItems+1; |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
46 |
// 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
|
47 |
decItems(); |
624 | 48 |
} |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
49 |
} else if (event->button()==Qt::RightButton && enabled) { |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
50 |
event->accept(); |
624 | 51 |
if(numItems > minItems) { |
52 |
decItems(); |
|
1886
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
53 |
} else { |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
54 |
numItems = maxItems+(infinityState?0:-1); |
0bb8f61e5630
patch by nemo: quick change from 0 to infinite and vice versa
unc0rr
parents:
1455
diff
changeset
|
55 |
incItems(); |
624 | 56 |
} |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
57 |
} else { |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
58 |
event->ignore(); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
59 |
return; |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
60 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
61 |
repaint(); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
62 |
} |
6153
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
63 |
void ItemNum::wheelEvent ( QWheelEvent * event ) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
64 |
{ |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
65 |
if (nonInteractive) return; |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
66 |
if (!enabled) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
67 |
{ |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
68 |
event->ignore(); |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
69 |
return; |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
70 |
} |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
71 |
event->accept(); |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
72 |
|
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
73 |
bool up = (event->delta() > 0); // positive delta is up, negative is down |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
74 |
|
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
75 |
// negative delta on horizontal wheel is not left, but right |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
76 |
if (event->orientation() == Qt::Horizontal) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
77 |
up = !up; |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
78 |
|
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
79 |
if(up) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
80 |
{ |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
81 |
if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
82 |
incItems(); |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
83 |
} |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
84 |
else |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
85 |
{ |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
86 |
if(numItems > minItems) |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
87 |
decItems(); |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
88 |
} |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
89 |
repaint(); |
3881126e06e8
allow changing number of hogs or weapons with mousewheel
sheepluva
parents:
6060
diff
changeset
|
90 |
} |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
91 |
|
643 | 92 |
QSize ItemNum::sizeHint () const |
93 |
{ |
|
94 |
return QSize((maxItems+1)*12, 32); |
|
95 |
} |
|
96 |
||
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
97 |
void ItemNum::paintEvent(QPaintEvent* event) |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
98 |
{ |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4416
diff
changeset
|
99 |
Q_UNUSED(event); |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4416
diff
changeset
|
100 |
|
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
101 |
QPainter painter(this); |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
102 |
|
640 | 103 |
if (numItems==maxItems+1) { |
642 | 104 |
QRect target(0, 0, 100, 32); |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
105 |
if (enabled) { |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
106 |
painter.drawImage(target, QImage(":/res/infinity.png")); |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
107 |
} else { |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
108 |
painter.drawImage(target, QImage(":/res/infinitygrey.png")); |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
109 |
} |
640 | 110 |
} else { |
111 |
for(int i=0; i<numItems; i++) { |
|
1455 | 112 |
QRect target(11 * i, i % 2, 25, 35); |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
113 |
if (enabled) { |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
114 |
painter.drawImage(target, m_im); |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
115 |
} else { |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
116 |
painter.drawImage(target, m_img); |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
117 |
} |
640 | 118 |
} |
612
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
119 |
} |
333d095319de
abstract class for items container (hedgehogs num, bullets, etc.)
displacer
parents:
diff
changeset
|
120 |
} |
624 | 121 |
|
122 |
unsigned char ItemNum::getItemsNum() const |
|
123 |
{ |
|
124 |
return numItems; |
|
125 |
} |
|
126 |
||
127 |
void ItemNum::setItemsNum(const unsigned char num) |
|
128 |
{ |
|
129 |
numItems=num; |
|
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
130 |
repaint(); |
624 | 131 |
} |
640 | 132 |
|
133 |
void ItemNum::setInfinityState(bool value) |
|
134 |
{ |
|
135 |
infinityState=value; |
|
136 |
} |
|
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
137 |
|
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
138 |
void ItemNum::setEnabled(bool value) |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
139 |
{ |
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
140 |
enabled=value; |
4416
29d2d1548387
adding a combobox to weapon editor as scheme editor, added a few notices for deleting and some buttons in this area.
Henek
parents:
4412
diff
changeset
|
141 |
repaint(); |
4412
c9a78ba03679
added disabling option to itemNum and grey images for that. also made default weapon sets uneditable and not deleteable.
Henek
parents:
2377
diff
changeset
|
142 |
} |