QTfrontend/itemNum.cpp
changeset 640 e69b651bb336
parent 624 e7673b036db5
child 642 3178a83c7043
equal deleted inserted replaced
639:69d7ff3ab6f0 640:e69b651bb336
    20 
    20 
    21 #include <QMouseEvent>
    21 #include <QMouseEvent>
    22 #include <QPainter>
    22 #include <QPainter>
    23 
    23 
    24 ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) :
    24 ItemNum::ItemNum(const QImage& im, QWidget * parent, unsigned char min, unsigned char max) :
    25   m_im(im), QWidget(parent), nonInteractive(false), minItems(min), maxItems(max), numItems(min)
    25   m_im(im), QWidget(parent), nonInteractive(false), minItems(min), maxItems(max), numItems(min),
       
    26   infinityState(false)
    26 {
    27 {
    27 }
    28 }
    28 
    29 
    29 ItemNum::~ItemNum()
    30 ItemNum::~ItemNum()
    30 {
    31 {
    33 void ItemNum::mousePressEvent ( QMouseEvent * event )
    34 void ItemNum::mousePressEvent ( QMouseEvent * event )
    34 {
    35 {
    35   if(nonInteractive) return;
    36   if(nonInteractive) return;
    36   if(event->button()==Qt::LeftButton) {
    37   if(event->button()==Qt::LeftButton) {
    37     event->accept();
    38     event->accept();
       
    39     if(infinityState && numItems==maxItems) {
       
    40       incItems();
       
    41     }
    38     if(numItems < maxItems) {
    42     if(numItems < maxItems) {
    39       incItems();
    43       incItems();
    40     }
    44     }
    41   } else if (event->button()==Qt::RightButton) {
    45   } else if (event->button()==Qt::RightButton) {
    42     event->accept();
    46     event->accept();
    52 
    56 
    53 void ItemNum::paintEvent(QPaintEvent* event)
    57 void ItemNum::paintEvent(QPaintEvent* event)
    54 {
    58 {
    55   QPainter painter(this);
    59   QPainter painter(this);
    56 
    60 
    57   for(int i=0; i<numItems; i++) {
    61   if (numItems==maxItems+1) {
    58     QRect target(11 * i, i % 2, 25, 25);
    62     QRect target(0, 0, 250, 32);
    59     painter.drawImage(target, m_im);
    63     painter.drawImage(target, QImage(":/res/infinity.png"));
       
    64   } else {
       
    65     for(int i=0; i<numItems; i++) {
       
    66       QRect target(11 * i, i % 2, 25, 25);
       
    67       painter.drawImage(target, m_im);
       
    68     }
    60   }
    69   }
    61 }
    70 }
    62 
    71 
    63 unsigned char ItemNum::getItemsNum() const
    72 unsigned char ItemNum::getItemsNum() const
    64 {
    73 {
    67 
    76 
    68 void ItemNum::setItemsNum(const unsigned char num)
    77 void ItemNum::setItemsNum(const unsigned char num)
    69 {
    78 {
    70   numItems=num;
    79   numItems=num;
    71 }
    80 }
       
    81 
       
    82 void ItemNum::setInfinityState(bool value)
       
    83 {
       
    84   infinityState=value;
       
    85 }