2
* Hedgewars, a free turn based strategy game
3
* Copyright (c) 2006-2011 Igor Ulyanov <iulyanov@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; version 2 of the License
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22
#include <QMouseEvent>
25
ItemNum::ItemNum(const QImage& im, const QImage& img, QWidget * parent, unsigned char min, unsigned char max) :
26
QFrame(parent), m_im(im), m_img(img), infinityState(false), nonInteractive(false), minItems(min), maxItems(max),
27
numItems(min+2 >= max ? min : min+2)
30
if(frontendEffects) setAttribute(Qt::WA_PaintOnScreen, true);
37
void ItemNum::mousePressEvent ( QMouseEvent * event )
39
if(nonInteractive) return;
40
if(event->button()==Qt::LeftButton && enabled) {
42
if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems)) {
45
numItems = minItems+1;
46
// appears there's an emit in there
49
} else if (event->button()==Qt::RightButton && enabled) {
51
if(numItems > minItems) {
54
numItems = maxItems+(infinityState?0:-1);
63
void ItemNum::wheelEvent ( QWheelEvent * event )
65
if (nonInteractive) return;
73
bool up = (event->delta() > 0); // positive delta is up, negative is down
75
// negative delta on horizontal wheel is not left, but right
76
if (event->orientation() == Qt::Horizontal)
81
if((infinityState && numItems <= maxItems) || (!infinityState && numItems < maxItems))
86
if(numItems > minItems)
92
QSize ItemNum::sizeHint () const
94
return QSize((maxItems+1)*12, 32);
97
void ItemNum::paintEvent(QPaintEvent* event)
101
QPainter painter(this);
103
if (numItems==maxItems+1) {
104
QRect target(0, 0, 100, 32);
106
painter.drawImage(target, QImage(":/res/infinity.png"));
108
painter.drawImage(target, QImage(":/res/infinitygrey.png"));
111
for(int i=0; i<numItems; i++) {
112
QRect target(11 * i, i % 2, 25, 35);
114
painter.drawImage(target, m_im);
116
painter.drawImage(target, m_img);
122
unsigned char ItemNum::getItemsNum() const
127
void ItemNum::setItemsNum(const unsigned char num)
133
void ItemNum::setInfinityState(bool value)
138
void ItemNum::setEnabled(bool value)