diff --git a/src/widgets/printwidget.h b/src/widgets/printwidget.h --- a/src/widgets/printwidget.h +++ b/src/widgets/printwidget.h @@ -16,7 +16,7 @@ along with this program. If not, see . */ #pragma once - +#include #include #include #include @@ -32,19 +32,69 @@ { Q_OBJECT public: - PrintWidget(QWidget *parent = nullptr); + /** + * @brief Make a new PrintWidget. + * @param showAllControls: if true show Print , Emergency Stop and On Pause Controls + * @param parent: Parent of this widget. + */ + PrintWidget(bool showAllControls = true, QWidget *parent = nullptr); + + /** + * @brief Get post pause string + * @return The Post Pause string. + */ QString postPauseCommand() const; + + /** + * @brief set Post Pause string text. + * @param text: text to set to. + */ void setPrintText(const QString &text); + /** + * @brief Update Fan count. + * @param count new fan count + */ + void updateFanCount(const int count); + signals: + /** + * @brief emergencyStopPressed + * Connect to AtCore::emergencyStop + */ void emergencyStopPressed(); + + /** + * @brief flowRateChanged + * Connect to AtCore::setFlowRate + * @param rate + */ void flowRateChanged(const int rate); + + /** + * @brief printPressed + */ void printPressed(); + + /** + * @brief printSpeedChanged + * Connect to AtCore::setPrinterSpeed + * @param speed + */ void printSpeedChanged(const int speed); + /** + * @brief The Fan Speed has Changed. + * @param speed : new Speed. + * @param fanNum : fan to set the speed on. + */ + void fanSpeedChanged(const int speed, const int fanNum); + private: QPushButton *buttonPrint = nullptr; + QComboBox *comboFanSelect = nullptr; QLineEdit *linePostPause = nullptr; QSpinBox *sbFlowRate = nullptr; QSpinBox *sbPrintSpeed = nullptr; + QSpinBox *sbFanSpeed = nullptr; }; diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp --- a/src/widgets/printwidget.cpp +++ b/src/widgets/printwidget.cpp @@ -21,35 +21,39 @@ #include #include -PrintWidget::PrintWidget(QWidget *parent) : +PrintWidget::PrintWidget(bool showAllControls, QWidget *parent) : QWidget(parent) { auto mainLayout = new QVBoxLayout; - - buttonPrint = new QPushButton(tr("Print File")); - connect(buttonPrint, &QPushButton::clicked, [this] { - emit(printPressed()); - }); - - auto newButton = new QPushButton(tr("Emergency Stop")); - connect(newButton, &QPushButton::clicked, [this] { - emit(emergencyStopPressed()); - }); - - auto hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(buttonPrint); - hBoxLayout->addWidget(newButton); - mainLayout->addLayout(hBoxLayout); - - auto newLabel = new QLabel(tr("On Pause:")); - - linePostPause = new QLineEdit; - linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); - - hBoxLayout = new QHBoxLayout; - hBoxLayout->addWidget(newLabel); - hBoxLayout->addWidget(linePostPause); - mainLayout->addLayout(hBoxLayout); + QPushButton *newButton = nullptr; + QLabel *newLabel = nullptr; + QHBoxLayout *hBoxLayout =nullptr; + if(showAllControls) { + buttonPrint = new QPushButton(tr("Print File")); + connect(buttonPrint, &QPushButton::clicked, [this] { + emit(printPressed()); + }); + + newButton = new QPushButton(tr("Emergency Stop")); + connect(newButton, &QPushButton::clicked, [this] { + emit(emergencyStopPressed()); + }); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(buttonPrint); + hBoxLayout->addWidget(newButton); + mainLayout->addLayout(hBoxLayout); + + newLabel = new QLabel(tr("On Pause:")); + + linePostPause = new QLineEdit; + linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(newLabel); + hBoxLayout->addWidget(linePostPause); + mainLayout->addLayout(hBoxLayout); + } newLabel = new QLabel(tr("Printer Speed")); sbPrintSpeed = new QSpinBox; @@ -84,6 +88,22 @@ hBoxLayout->addWidget(newButton, 20); mainLayout->addLayout(hBoxLayout); + comboFanSelect = new QComboBox; + sbFanSpeed = new QSpinBox; + sbFanSpeed->setRange(0, 100); + sbFanSpeed->setSuffix(QStringLiteral("%")); + + newButton = new QPushButton(tr("Set")); + connect(newButton, &QPushButton::clicked, [this] { + emit(fanSpeedChanged(sbFanSpeed->value(), comboFanSelect->currentIndex())); + }); + + hBoxLayout = new QHBoxLayout; + hBoxLayout->addWidget(comboFanSelect, 80); + hBoxLayout->addWidget(sbFanSpeed); + hBoxLayout->addWidget(newButton); + mainLayout->addLayout(hBoxLayout); + setLayout(mainLayout); } @@ -96,3 +116,10 @@ { buttonPrint->setText(text); } + +void PrintWidget::updateFanCount(const int count) +{ + for (int i = 0; i < count; i++) { + comboFanSelect->insertItem(i, tr("Fan %1 speed").arg(i)); + } +} diff --git a/src/widgets/temperaturewidget.h b/src/widgets/temperaturewidget.h --- a/src/widgets/temperaturewidget.h +++ b/src/widgets/temperaturewidget.h @@ -34,18 +34,14 @@ public: TemperatureWidget(QWidget *parent = nullptr); void updateExtruderCount(const int count); - void updateFanCount(const int count); signals: void bedTempChanged(const int temperature, bool andWait); void extTempChanged(const int temperature, const int extNum, bool andWait); - void fanSpeedChanged(const int speed, const int fanNum); private: QCheckBox *checkAndWait = nullptr; QComboBox *comboExtruderSelect; - QComboBox *comboFanSelect; QSpinBox *sbBedTemp = nullptr; QSpinBox *sbExtruderTemp; - QSpinBox *sbFanSpeed; }; diff --git a/src/widgets/temperaturewidget.cpp b/src/widgets/temperaturewidget.cpp --- a/src/widgets/temperaturewidget.cpp +++ b/src/widgets/temperaturewidget.cpp @@ -61,22 +61,6 @@ hboxLayout->addWidget(newButton); mainLayout->addItem(hboxLayout); - comboFanSelect = new QComboBox; - sbFanSpeed = new QSpinBox; - sbFanSpeed->setRange(0, 100); - sbFanSpeed->setSuffix(QStringLiteral("%")); - - newButton = new QPushButton(tr("Set")); - connect(newButton, &QPushButton::clicked, [this] { - emit(fanSpeedChanged(sbFanSpeed->value(), comboFanSelect->currentIndex())); - }); - - hboxLayout = new QHBoxLayout; - hboxLayout->addWidget(comboFanSelect, 80); - hboxLayout->addWidget(sbFanSpeed); - hboxLayout->addWidget(newButton); - mainLayout->addItem(hboxLayout); - setLayout(mainLayout); } @@ -86,10 +70,3 @@ comboExtruderSelect->insertItem(i, tr("Extruder %1").arg(i)); } } - -void TemperatureWidget::updateFanCount(const int count) -{ - for (int i = 0; i < count; i++) { - comboFanSelect->insertItem(i, tr("Fan %1 speed").arg(i)); - } -} diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -171,6 +171,7 @@ printWidget = new PrintWidget; connect(printWidget, &PrintWidget::printPressed, this, &MainWindow::printPBClicked); connect(printWidget, &PrintWidget::emergencyStopPressed, core, &AtCore::emergencyStop); + connect(printWidget, &PrintWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); connect(printWidget, &PrintWidget::printSpeedChanged, [this](const int speed) { core->setPrinterSpeed(speed); @@ -305,7 +306,6 @@ temperatureWidget = new TemperatureWidget; connect(temperatureWidget, &TemperatureWidget::bedTempChanged, core, &AtCore::setBedTemp); connect(temperatureWidget, &TemperatureWidget::extTempChanged, core, &AtCore::setExtruderTemp); - connect(temperatureWidget, &TemperatureWidget::fanSpeedChanged, core, &AtCore::setFanSpeed); tempControlsDock = new QDockWidget(tr("Temperatures"), this); tempControlsDock->setWidget(temperatureWidget); @@ -564,6 +564,6 @@ if (!disabled) { temperatureWidget->updateExtruderCount(core->extruderCount()); - temperatureWidget->updateFanCount(fanCount); + printWidget->updateFanCount(fanCount); } }