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 SPDX-FileCopyrightText: 2020 Tomaz Canabrava <tcanabrava@kde.org> 0006 */ 0007 0008 #include <QComboBox> 0009 #include <QDoubleSpinBox> 0010 #include <QHBoxLayout> 0011 #include <QPushButton> 0012 #include <QVBoxLayout> 0013 0014 #include "axiscontrol.h" 0015 #include "movementwidget.h" 0016 0017 class MovementWidget::MovementWidgetPrivate { 0018 public: 0019 QComboBox *comboMoveAxis = nullptr; 0020 QDoubleSpinBox *sbMoveAxis = nullptr; 0021 AxisControl *axisControl = nullptr; 0022 0023 QPushButton *disableMotors = nullptr; 0024 QPushButton *homeAll = nullptr; 0025 QPushButton *homeX = nullptr; 0026 QPushButton *homeY = nullptr; 0027 QPushButton *homeZ = nullptr; 0028 QPushButton *move = nullptr; 0029 0030 QList<int> _axisMaxes {200, 200, 200}; 0031 }; 0032 0033 MovementWidget::MovementWidget(QWidget *parent) 0034 : QWidget(parent) 0035 , d(new MovementWidgetPrivate()) 0036 { 0037 initialize(); 0038 } 0039 0040 MovementWidget::~MovementWidget() { 0041 delete d; 0042 } 0043 0044 void MovementWidget::initialize() 0045 { 0046 auto *mainLayout = new QVBoxLayout; 0047 auto *hBoxLayout = new QHBoxLayout; 0048 0049 d->homeAll = new QPushButton(tr("Home All"), this); 0050 hBoxLayout->addWidget(d->homeAll); 0051 connect(d->homeAll, &QPushButton::clicked, this, &MovementWidget::homeAllPressed); 0052 0053 d->homeX = new QPushButton(tr("Home X"), this); 0054 hBoxLayout->addWidget(d->homeX); 0055 connect(d->homeX, &QPushButton::clicked, this, &MovementWidget::homeXPressed); 0056 0057 d->homeY = new QPushButton(tr("Home Y"), this); 0058 hBoxLayout->addWidget(d->homeY); 0059 connect(d->homeY, &QPushButton::clicked, this, &MovementWidget::homeYPressed); 0060 0061 d->homeZ = new QPushButton(tr("Home Z"), this); 0062 hBoxLayout->addWidget(d->homeZ); 0063 connect(d->homeZ, &QPushButton::clicked, this, &MovementWidget::homeZPressed); 0064 0065 mainLayout->addLayout(hBoxLayout); 0066 0067 d->disableMotors = new QPushButton(tr("Disable Motors"), this); 0068 mainLayout->addWidget(d->disableMotors); 0069 connect(d->disableMotors, &QPushButton::clicked, this, &MovementWidget::disableMotorsPressed); 0070 0071 d->comboMoveAxis = new QComboBox(this); 0072 d->comboMoveAxis->addItem(tr("Move X Axis to")); 0073 d->comboMoveAxis->addItem(tr("Move Y Axis to")); 0074 d->comboMoveAxis->addItem(tr("Move Z Axis to")); 0075 0076 d->sbMoveAxis = new QDoubleSpinBox(this); 0077 d->sbMoveAxis->setRange(0, d->_axisMaxes.at(d->comboMoveAxis->currentIndex())); 0078 0079 connect(d->comboMoveAxis, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this] (int index) { 0080 d->sbMoveAxis->setMaximum(d->_axisMaxes.at(index)); 0081 }); 0082 0083 d->move = new QPushButton(tr("Go"), this); 0084 connect(d->move, &QPushButton::clicked, this, [this] { 0085 if (d->comboMoveAxis->currentIndex() == 0) { 0086 Q_EMIT absoluteMove(QLatin1Char('X'), d->sbMoveAxis->value()); 0087 } else if (d->comboMoveAxis->currentIndex() == 1) { 0088 Q_EMIT absoluteMove(QLatin1Char('Y'), d->sbMoveAxis->value()); 0089 } else if (d->comboMoveAxis->currentIndex() == 2) { 0090 Q_EMIT absoluteMove(QLatin1Char('Z'), d->sbMoveAxis->value()); 0091 } 0092 }); 0093 0094 hBoxLayout = new QHBoxLayout; 0095 hBoxLayout->addWidget(d->comboMoveAxis); 0096 hBoxLayout->addWidget(d->sbMoveAxis); 0097 hBoxLayout->addWidget(d->move); 0098 mainLayout->addLayout(hBoxLayout); 0099 0100 d->axisControl = new AxisControl(this); 0101 mainLayout->addWidget(d->axisControl); 0102 connect(d->axisControl, &AxisControl::clicked, this, &MovementWidget::relativeMove); 0103 connect(d->axisControl, &AxisControl::unitsChanged, this, &MovementWidget::unitsChanged); 0104 0105 setLayout(mainLayout); 0106 } 0107 0108 void MovementWidget::setHomeButtonsVisible(bool visible) 0109 { 0110 d->homeAll->setVisible(visible); 0111 d->homeX->setVisible(visible); 0112 d->homeY->setVisible(visible); 0113 d->homeZ->setVisible(visible); 0114 } 0115 0116 void MovementWidget::setDisableMotorsButtonVisible(bool visible) 0117 { 0118 d->disableMotors->setVisible(visible); 0119 } 0120 0121 void MovementWidget::setAxisMax(int xMax, int yMax, int zMax) 0122 { 0123 xMax = std::max(0, xMax); 0124 yMax = std::max(0, yMax); 0125 zMax = std::max(0, zMax); 0126 d->_axisMaxes = QList<int> {xMax, yMax, zMax}; 0127 d->sbMoveAxis->setMaximum(d->comboMoveAxis->currentIndex()); 0128 }