File indexing completed on 2024-05-12 04:41:11

0001 /* AtCore KDE Libary for 3D Printers
0002     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003     SPDX-FileCopyrightText: 2018-2020 Chris Rizzitello <rizzitello@kde.org>
0004     SPDX-FileCopyrightText: 2018 Patrick José Pereira <patrickjp@kde.org>
0005 */
0006 
0007 #include "printwidget.h"
0008 
0009 #include <QComboBox>
0010 #include <QHBoxLayout>
0011 #include <QLabel>
0012 #include <QLineEdit>
0013 #include <QPushButton>
0014 #include <QSpinBox>
0015 #include <QVBoxLayout>
0016 
0017 PrintWidget::PrintWidget(bool showAllControls, QWidget *parent)
0018     : QWidget(parent)
0019 {
0020     auto mainLayout = new QVBoxLayout;
0021     QPushButton *newButton = nullptr;
0022     QLabel *newLabel = nullptr;
0023     QHBoxLayout *hBoxLayout = nullptr;
0024     if (showAllControls) {
0025         buttonPrint = new QPushButton(tr("Print File"), this);
0026         connect(buttonPrint, &QPushButton::clicked, this, &PrintWidget::printPressed);
0027 
0028         newButton = new QPushButton(tr("Emergency Stop"), this);
0029         connect(newButton, &QPushButton::clicked, this, &PrintWidget::emergencyStopPressed);
0030 
0031         hBoxLayout = new QHBoxLayout;
0032         hBoxLayout->addWidget(buttonPrint);
0033         hBoxLayout->addWidget(newButton);
0034         mainLayout->addLayout(hBoxLayout);
0035     }
0036 
0037     newLabel = new QLabel(tr("Printer Speed"), this);
0038     sbPrintSpeed = new QSpinBox(this);
0039     sbPrintSpeed->setRange(1, 300);
0040     sbPrintSpeed->setValue(100);
0041     sbPrintSpeed->setSuffix(QStringLiteral("%"));
0042 
0043     newButton = new QPushButton(tr("Set"), this);
0044     connect(newButton, &QPushButton::clicked, this, [this] { Q_EMIT printSpeedChanged(sbPrintSpeed->value()); });
0045 
0046     hBoxLayout = new QHBoxLayout;
0047     hBoxLayout->addWidget(newLabel, 60);
0048     hBoxLayout->addWidget(sbPrintSpeed, 20);
0049     hBoxLayout->addWidget(newButton, 20);
0050     mainLayout->addLayout(hBoxLayout);
0051 
0052     newLabel = new QLabel(tr("Flow Rate"), this);
0053     sbFlowRate = new QSpinBox(this);
0054     sbFlowRate->setRange(1, 300);
0055     sbFlowRate->setValue(100);
0056     sbFlowRate->setSuffix(QStringLiteral("%"));
0057 
0058     newButton = new QPushButton(tr("Set"), this);
0059     connect(newButton, &QPushButton::clicked, this, [this] { Q_EMIT flowRateChanged(sbFlowRate->value()); });
0060     hBoxLayout = new QHBoxLayout;
0061     hBoxLayout->addWidget(newLabel, 60);
0062     hBoxLayout->addWidget(sbFlowRate, 20);
0063     hBoxLayout->addWidget(newButton, 20);
0064     mainLayout->addLayout(hBoxLayout);
0065 
0066     comboFanSelect = new QComboBox(this);
0067     sbFanSpeed = new QSpinBox(this);
0068     sbFanSpeed->setRange(0, 100);
0069     sbFanSpeed->setSuffix(QStringLiteral("%"));
0070 
0071     newButton = new QPushButton(tr("Set"), this);
0072     connect(newButton, &QPushButton::clicked, this, [this] {
0073         // Fan speed has a range of 0-255.
0074         int speed = sbFanSpeed->value() * 255 / 100;
0075         Q_EMIT fanSpeedChanged(speed, comboFanSelect->currentIndex());
0076     });
0077 
0078     hBoxLayout = new QHBoxLayout;
0079     hBoxLayout->addWidget(comboFanSelect, 60);
0080     hBoxLayout->addWidget(sbFanSpeed, 20);
0081     hBoxLayout->addWidget(newButton, 20);
0082     mainLayout->addLayout(hBoxLayout);
0083 
0084     setLayout(mainLayout);
0085 }
0086 
0087 void PrintWidget::setPrintText(const QString &text)
0088 {
0089     buttonPrint->setText(text);
0090 }
0091 
0092 void PrintWidget::updateFanCount(const int count)
0093 {
0094     comboFanSelect->clear();
0095     for (int i = 0; i < count; i++) {
0096         comboFanSelect->insertItem(i, tr("Fan %1 speed").arg(i));
0097     }
0098 }