diff --git a/src/widgets/statuswidget.h b/src/widgets/statuswidget.h --- a/src/widgets/statuswidget.h +++ b/src/widgets/statuswidget.h @@ -18,6 +18,7 @@ #pragma once #include #include +#include #include #include @@ -31,11 +32,31 @@ { Q_OBJECT public: - StatusWidget(QWidget *parent = nullptr); - + /** + * @brief Make A new Status widget + * @param showStop: Set False if your client has the print job stop in another widget. + * @param parent: parent of this widget. + */ + StatusWidget(bool showStop = true, QWidget *parent = nullptr); + /** + * @brief Set if the status area should show SD card inserted. + * @param hasSd + */ void setSD(bool hasSd); + /** + * @brief Set the State String + * @param state: String to be shown + */ void setState(const QString &state); + /** + * @brief Show or hide the Print progress and time + * @param visible : true for show + */ void showPrintArea(bool visible); + /** + * @brief Update the progres to the new progress + * @param progress: new progress. + */ void updatePrintProgress(const float &progress); signals: @@ -51,6 +72,7 @@ QLabel *lblTimeLeft = nullptr; QTime *printTime = nullptr; QTimer *printTimer = nullptr; + QSpacerItem *spacer = nullptr; QProgressBar *printingProgress = nullptr; QWidget *printProgressWidget = nullptr; }; diff --git a/src/widgets/statuswidget.cpp b/src/widgets/statuswidget.cpp --- a/src/widgets/statuswidget.cpp +++ b/src/widgets/statuswidget.cpp @@ -23,26 +23,30 @@ #include "statuswidget.h" -StatusWidget::StatusWidget(QWidget *parent) : +StatusWidget::StatusWidget(bool showStop, QWidget *parent) : QWidget(parent) { //first create the item for the print Progress. + auto hBoxLayout = new QHBoxLayout; + printingProgress = new QProgressBar; + printingProgress->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + hBoxLayout->addWidget(printingProgress); - auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); - connect(newButton, &QPushButton::clicked, [this] { - emit(stopPressed()); - }); + if(showStop) { + auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); + connect(newButton, &QPushButton::clicked, [this] { + emit(stopPressed()); + }); + hBoxLayout->addWidget(newButton); + } lblTime = new QLabel(QStringLiteral("00:00:00")); lblTime->setAlignment(Qt::AlignHCenter); auto newLabel = new QLabel(QStringLiteral(" / ")); lblTimeLeft = new QLabel(QStringLiteral("??:??:??")); lblTimeLeft->setAlignment(Qt::AlignHCenter); - auto hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(printingProgress); - hBoxLayout->addWidget(newButton); hBoxLayout->addWidget(lblTime); hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(lblTimeLeft); @@ -54,12 +58,14 @@ lblState = new QLabel(tr("Not Connected")); lblSd = new QLabel(); + spacer = new QSpacerItem(10, 20,QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(lblState); - hBoxLayout->addSpacerItem(new QSpacerItem(10, 20, QSizePolicy::Fixed)); + hBoxLayout->addSpacerItem(new QSpacerItem(5, 20, QSizePolicy::Fixed)); hBoxLayout->addWidget(lblSd); - hBoxLayout->addSpacerItem(new QSpacerItem(40, 20, QSizePolicy::Expanding)); + hBoxLayout->addSpacerItem(spacer); hBoxLayout->addWidget(printProgressWidget); setLayout(hBoxLayout); @@ -85,10 +91,12 @@ { printProgressWidget->setVisible(visible); if (visible) { + layout()->removeItem(spacer); printTime->start(); printTimer->start(); } else { printTimer->stop(); + layout()->addItem(spacer); } }