Git commit 2b316297878ef4fa437910bdfd6b9df0506a1d2d by Tomaz Canabrava. Committed on 30/11/2015 at 22:55. Pushed by tcanabrava into branch 'master'. Fix multiple issues with BigButton 1 - don't pass QString or QIcon via value, pass them via const-ref 2 - do not use default arguments when you need real arguments. 3 - do not pass '0' as parent, parent is the owner of the widget. 4 - be carefull with the code style 5 - use tr() between strings that you need translated 6 - do not \n an string on a push button, it knows how to handle itself. 7 - use proper names for functions/methods, isChecked() is good, getChecked= Status isn't. Signed-off-by: Tomaz Canabrava M +12 -8 BigButton.cpp M +4 -4 BigButton.h M +8 -8 brprint3d.cpp http://commits.kde.org/brprint3d/2b316297878ef4fa437910bdfd6b9df0506a1d2d diff --git a/BigButton.cpp b/BigButton.cpp index 3f9eb7d..1170319 100755 --- a/BigButton.cpp +++ b/BigButton.cpp @@ -23,31 +23,35 @@ #include "BigButton.h" #include "ui_BigButton.h" = -BigButton::BigButton(QWidget *parent, QString name, bool isCheckable, QStr= ing iconPath) : +BigButton::BigButton(QWidget *parent, const QString& name,const QString& i= conPath, bool isCheckable) : QWidget(parent), ui(new Ui::BigButton) -{ QPixmap pix(iconPath); +{ = + QPixmap pix(iconPath); ui->setupUi(this); ui->label->setText(name); ui->pushButton->setCheckable(isCheckable); - connect(ui->pushButton,&QPushButton::clicked,this,&BigButton::clicked); ui->pushButton->setIcon(QIcon(pix)); - ui->pushButton->setIconSize(QSize(50,50)); + ui->pushButton->setIconSize(QSize(50,50)); //TODO: Hardcoded value, ch= ange this to something calculated for the current display. + connect(ui->pushButton, &QPushButton::clicked, this, &BigButton::click= ed); } = BigButton::~BigButton() { delete ui; } -bool BigButton::getCheckedStatus(){ = +bool BigButton::isChecked() +{ return ui->pushButton->isChecked(); - } -void BigButton::setIcon(QIcon icon){ = +void BigButton::setIcon(const QIcon& icon) +{ ui->pushButton->setIcon(icon); } -void BigButton::setChecked(bool b){ + +void BigButton::setChecked(bool b) +{ ui->pushButton->setChecked(b); } diff --git a/BigButton.h b/BigButton.h index a2beb39..d5ea784 100755 --- a/BigButton.h +++ b/BigButton.h @@ -35,11 +35,11 @@ class BigButton : public QWidget Q_OBJECT = public: - explicit BigButton(QWidget *parent =3D 0, QString name =3D "", bool is= Checkable =3D false, QString pix =3D ""); + explicit BigButton(QWidget *parent, const QString& name, const QString= & pix, bool isCheckable =3D false); ~BigButton(); -public slots: - bool getCheckedStatus(); - void setIcon(QIcon icon); + + bool isChecked(); + void setIcon(const QIcon& icon); void setChecked(bool b); = private: diff --git a/brprint3d.cpp b/brprint3d.cpp index 9a25c0e..c0021d6 100755 --- a/brprint3d.cpp +++ b/brprint3d.cpp @@ -28,18 +28,18 @@ BrPrint3D::BrPrint3D(QWidget *parent) : QMainWindow(par= ent), ui(new Ui::BrPrint3D) { ui->setupUi(this); - bt_import =3D new BigButton(0,"Import \nGCode",false,":/Icons/Icons/im= port.png"); - bt_open =3D new BigButton(0,"Open File",false,":/Icons/Icons/openFile.= png"); - bt_connect =3D new BigButton(0,"Connect",true,":/Icons/Icons/connect.p= ng"); + bt_import =3D new BigButton(this,tr("Import GCode"),":/Icons/Icons/imp= ort.png", false); + bt_open =3D new BigButton(this,tr("Open File"),":/Icons/Icons/openFile= .png", false); + bt_connect =3D new BigButton(this,tr("Connect"),":/Icons/Icons/connect= .png", true); = ui->ly_ConteinerLeft->addWidget(bt_import); ui->ly_ConteinerLeft->addWidget(bt_open); ui->ly_ConteinerLeft->addWidget(bt_connect); = - bt_play =3D new BigButton(0,"Play",true,":/Icons/Icons/play.png"); - bt_pause =3D new BigButton(0,"Pause",true,":/Icons/Icons/pause.png"); - bt_stop =3D new BigButton(0,"Stop",false,":/Icons/Icons/stop.png"); - bt_stopOnEmergency =3D new BigButton(0,"Emergency \nStop",false,":/Ico= ns/Icons/emergency.png"); + bt_play =3D new BigButton(this,tr("Play"),":/Icons/Icons/play.png", tr= ue); + bt_pause =3D new BigButton(this,tr("Pause"),":/Icons/Icons/pause.png",= true); + bt_stop =3D new BigButton(this,tr("Stop"),":/Icons/Icons/stop.png", fa= lse); + bt_stopOnEmergency =3D new BigButton(this,tr("Emergency Stop"),":/Icon= s/Icons/emergency.png", false); = ui->ly_ConteinerRight->addWidget(bt_play); ui->ly_ConteinerRight->addWidget(bt_pause); @@ -110,7 +110,7 @@ void BrPrint3D::openFile() vtkView->renderGcode(text); gcode.close(); ui->_ManualControl->setGcodePreview(text); - if (bt_connect->getCheckedStatus()) + if (bt_connect->isChecked()) bt_play->setEnabled(true); = }