QTfrontend/togglebutton.cpp
changeset 3061 e129e4c3f30e
parent 2948 3f21a9dc93d0
child 4560 5d6c7f88db73
equal deleted inserted replaced
3060:0c5f5f13eef4 3061:e129e4c3f30e
    18 
    18 
    19 #include "togglebutton.h"
    19 #include "togglebutton.h"
    20 
    20 
    21 ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img)
    21 ToggleButtonWidget::ToggleButtonWidget(QWidget * parent, QString img)
    22 {
    22 {
    23     QVBoxLayout * l = new QVBoxLayout(this);
    23     setCheckable(true);
    24     setLayout(l);
       
    25 
       
    26     pbMain = new QPushButton(this);
       
    27     pbMain->setCheckable(true);
       
    28 
    24 
    29     QPixmap pm(":/res/btnDisabled.png");
    25     QPixmap pm(":/res/btnDisabled.png");
    30     QPainter * painter = new QPainter();
    26     QPainter * painter = new QPainter();
    31 
    27 
    32     pmChecked.load(img);
    28     pmChecked.load(img);
    33     pmDisabled.load(img);
    29     pmDisabled.load(img);
    34 
    30 
    35     pbMain->setMaximumWidth(pmChecked.width() + 6);
    31     setMaximumWidth(pmChecked.width() + 6);
    36 
       
    37     l->addWidget(pbMain);
       
    38 
    32 
    39     painter->begin(&pmDisabled);
    33     painter->begin(&pmDisabled);
    40     painter->drawPixmap(pmDisabled.rect(), pm);
    34     painter->drawPixmap(pmDisabled.rect(), pm);
    41     painter->end();
    35     painter->end();
    42 
    36 
    43     pbMain->setIconSize(pmDisabled.size());
    37     setIconSize(pmDisabled.size());
    44     pbMain->setIcon(pmDisabled);
    38     setIcon(pmDisabled);
    45 
    39 
    46     connect(pbMain, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
    40     connect(this, SIGNAL(toggled(bool)), this, SLOT(eventToggled(bool)));
    47 
       
    48     lbMain = new QLabel(this);
       
    49     lbMain->setWordWrap(true);
       
    50 //  lbMain->setFixedHeight(32);
       
    51 
       
    52     l->addWidget(lbMain);
       
    53 }
    41 }
    54 
    42 
    55 ToggleButtonWidget::~ToggleButtonWidget()
    43 ToggleButtonWidget::~ToggleButtonWidget()
    56 {
    44 {
    57     delete pbMain;
       
    58     delete lbMain;
       
    59 }
       
    60 
       
    61 bool ToggleButtonWidget::isChecked()
       
    62 {
       
    63     return pbMain->isChecked();
       
    64 }
       
    65 
       
    66 void ToggleButtonWidget::setChecked(bool checked)
       
    67 {
       
    68     pbMain->setChecked(checked);
       
    69 }
       
    70 
       
    71 void ToggleButtonWidget::setText(QString s)
       
    72 {
       
    73     lbMain->setText(s);
       
    74 }
    45 }
    75 
    46 
    76 void ToggleButtonWidget::eventToggled(bool checked)
    47 void ToggleButtonWidget::eventToggled(bool checked)
    77 {
    48 {
    78     if (checked) pbMain->setIcon(pmChecked); else pbMain->setIcon(pmDisabled);
    49     setIcon(checked ? pmChecked : pmDisabled);
    79 }
    50 }