diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp index cd91956..4ea2297 100644 --- a/src/widgets/printwidget.cpp +++ b/src/widgets/printwidget.cpp @@ -1,98 +1,125 @@ /* AtCore Test Client Copyright (C) <2018> Author: Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "printwidget.h" #include #include #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; sbPrintSpeed->setRange(1, 300); sbPrintSpeed->setValue(100); sbPrintSpeed->setSuffix(QStringLiteral("%")); newButton = new QPushButton(tr("Set")); connect(newButton, &QPushButton::clicked, [this] { emit(printSpeedChanged(sbPrintSpeed->value())); }); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel, 35); hBoxLayout->addWidget(sbPrintSpeed, 10); hBoxLayout->addWidget(newButton, 20); mainLayout->addLayout(hBoxLayout); newLabel = new QLabel(tr("Flow Rate")); sbFlowRate = new QSpinBox; sbFlowRate->setRange(1, 300); sbFlowRate->setValue(100); sbFlowRate->setSuffix(QStringLiteral("%")); newButton = new QPushButton(tr("Set")); connect(newButton, &QPushButton::clicked, [this] { emit(flowRateChanged(sbFlowRate->value())); }); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel, 35); hBoxLayout->addWidget(sbFlowRate, 10); 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); } QString PrintWidget::postPauseCommand(void) const { return linePostPause->text(); } void PrintWidget::setPrintText(const QString &text) { 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/printwidget.h b/src/widgets/printwidget.h index f7da570..e2bf339 100644 --- a/src/widgets/printwidget.h +++ b/src/widgets/printwidget.h @@ -1,50 +1,100 @@ /* AtCore Test Client Copyright (C) <2018> Author: Chris Rizzitello - rizzitello@kde.org This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once - +#include #include #include #include #include #include "atcorewidgets_export.h" /* Usage: * * Create a instance of the print widget. */ class ATCOREWIDGETS_EXPORT PrintWidget : public QWidget { 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; QLineEdit *linePostPause = nullptr; QSpinBox *sbFlowRate = nullptr; QSpinBox *sbPrintSpeed = nullptr; + QComboBox *comboFanSelect = nullptr; + QSpinBox *sbFanSpeed = nullptr; };