QTfrontend/itemNum.cpp
changeset 624 e7673b036db5
parent 612 333d095319de
child 640 e69b651bb336
equal deleted inserted replaced
623:ca1c1bd15915 624:e7673b036db5
    19 #include "itemNum.h"
    19 #include "itemNum.h"
    20 
    20 
    21 #include <QMouseEvent>
    21 #include <QMouseEvent>
    22 #include <QPainter>
    22 #include <QPainter>
    23 
    23 
    24 ItemNum::ItemNum(const QImage& im, QWidget * parent) :
    24 ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) :
    25     m_im(im), QWidget(parent), nonInteractive(false)
    25   m_im(im), QWidget(parent), nonInteractive(false), minItems(min), maxItems(max), numItems(min)
    26 {
    26 {
    27 }
    27 }
    28 
    28 
    29 ItemNum::~ItemNum()
    29 ItemNum::~ItemNum()
    30 {
    30 {
    33 void ItemNum::mousePressEvent ( QMouseEvent * event )
    33 void ItemNum::mousePressEvent ( QMouseEvent * event )
    34 {
    34 {
    35   if(nonInteractive) return;
    35   if(nonInteractive) return;
    36   if(event->button()==Qt::LeftButton) {
    36   if(event->button()==Qt::LeftButton) {
    37     event->accept();
    37     event->accept();
    38     incItems();
    38     if(numItems < maxItems) {
       
    39       incItems();
       
    40     }
    39   } else if (event->button()==Qt::RightButton) {
    41   } else if (event->button()==Qt::RightButton) {
    40     event->accept();
    42     event->accept();
    41     decItems();
    43     if(numItems > minItems) {
       
    44       decItems();
       
    45     }
    42   } else {
    46   } else {
    43     event->ignore();
    47     event->ignore();
    44     return;
    48     return;
    45   }
    49   }
    46   repaint();
    50   repaint();
    53   for(int i=0; i<numItems; i++) {
    57   for(int i=0; i<numItems; i++) {
    54     QRect target(11 * i, i % 2, 25, 25);
    58     QRect target(11 * i, i % 2, 25, 25);
    55     painter.drawImage(target, m_im);
    59     painter.drawImage(target, m_im);
    56   }
    60   }
    57 }
    61 }
       
    62 
       
    63 unsigned char ItemNum::getItemsNum() const
       
    64 {
       
    65   return numItems;
       
    66 }
       
    67 
       
    68 void ItemNum::setItemsNum(const unsigned char num)
       
    69 {
       
    70   numItems=num;
       
    71 }