diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index d5a0925..04f3565 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -1,30 +1,34 @@ include_directories(../dialogs) +include_directories(${QWT_INCLUDE_DIR}) set(widgets_SRCS gcodeeditorwidget.cpp axiscontrol.cpp bedextruderwidget.cpp plotwidget.cpp pushgcodewidget.cpp ratescontrolwidget.cpp printprogresswidget.cpp logwidget.cpp videomonitorwidget.cpp atcoreinstancewidget.cpp + thermowidget.cpp ) add_library(AtelierWidgets STATIC ${widgets_SRCS}) -target_link_libraries(AtelierWidgets - Qt5::Core - Qt5::Widgets +target_link_libraries(AtelierWidgets + Qt5::Core + Qt5::Widgets Qt5::SerialPort - KF5::Solid - KF5::I18n - KF5::TextEditor + KF5::Solid + KF5::I18n + KF5::TextEditor Qt5::Charts Qt5::Multimedia Qt5::MultimediaWidgets - AtCore::AtCore) + AtCore::AtCore + ${QWT_LIBRARY} + ) add_subdirectory(3dview) diff --git a/src/widgets/bedextruderwidget.cpp b/src/widgets/bedextruderwidget.cpp index f1ba3c7..6e7ecd7 100644 --- a/src/widgets/bedextruderwidget.cpp +++ b/src/widgets/bedextruderwidget.cpp @@ -1,128 +1,145 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodriguessilva@gmail.com - + 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 "bedextruderwidget.h" #include "ui_bedextruderwidget.h" #include #include +#include "thermowidget.h" +#include BedExtruderWidget::BedExtruderWidget(QWidget *parent) : QWidget(parent), - ui(new Ui::BedExtruderWidget) + m_bedThermo(new ThermoWidget(this)), + m_exturderThermo(new ThermoWidget(this)) { - ui->setupUi(this); + m_bedThermo->setScale(0, 150); + m_exturderThermo->setScale(0, 250); + + auto centralLayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight); + centralLayout->addWidget(m_bedThermo); + centralLayout->addWidget(m_exturderThermo); + setLayout(centralLayout); //Add Default Extruder setExtruderCount(1); +/* connect(ui->heatBedPB, &QPushButton::clicked, this, &BedExtruderWidget::heatBedClicked); connect(ui->heatExtPB, &QPushButton::clicked, this, &BedExtruderWidget::heatExtruderClicked); connect(ui->bedTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) { if (ui->heatBedPB->isChecked()) { emit bedTemperatureChanged(tmp,ui->bedAndWaitCB->isChecked()); } }); connect(ui->extTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) { if (ui->heatExtPB->isChecked()) { emit extTemperatureChanged(tmp, currentExtruder(),ui->extAndWaitCB->isChecked()); } }); +*/ } BedExtruderWidget::~BedExtruderWidget() { - delete ui; } void BedExtruderWidget::setExtruderCount(int value) { if (value == extruderCount) { return; } else if (extruderCount < value) { //loop for the new buttons for (int i = extruderCount; i < value; i++) { auto *rb = new QRadioButton(QString::number(i + 1)); - ui->extRadioButtonLayout->addWidget(rb); +// ui->extRadioButtonLayout->addWidget(rb); extruderMap.insert(i, rb); } } else { //remove buttons - need to test it! for (int i = extruderCount; i >= value; i--) { auto *rb = extruderMap.value(i); - ui->extRadioButtonLayout->removeWidget(rb); +// ui->extRadioButtonLayout->removeWidget(rb); extruderMap.remove(i); delete (rb); } } extruderCount = value; } void BedExtruderWidget::updateBedTemp(const float temp) { - ui->bedCurrTempLB->setText(QString::number(temp)); +// ui->bedCurrTempLB->setText(QString::number(temp)); } void BedExtruderWidget::updateExtTemp(const float temp) { - ui->extCurrTempLB->setText(QString::number(temp)); +// ui->extCurrTempLB->setText(QString::number(temp)); } void BedExtruderWidget::updateBedTargetTemp(const float temp) { - ui->bedTargetTempLB->setText(QString::number(temp) + " ºC"); +// ui->bedTargetTempLB->setText(QString::number(temp) + " ºC"); } void BedExtruderWidget::updateExtTargetTemp(const float temp) { - ui->extTargetTempLB->setText(QString::number(temp) + " ºC"); +// ui->extTargetTempLB->setText(QString::number(temp) + " ºC"); } void BedExtruderWidget::stopHeating() { + /* emit bedTemperatureChanged(0,ui->bedAndWaitCB->isChecked()); for (int i = 0; i < extruderCount; i++) { emit extTemperatureChanged(0, i,ui->extAndWaitCB->isChecked()); } ui->heatBedPB->setChecked(false); ui->heatExtPB->setChecked(false); + + */ } void BedExtruderWidget::heatExtruderClicked(bool clicked) { + /* int temp = ui->extTempSB->value() * clicked; emit extTemperatureChanged(temp, currentExtruder(),ui->extAndWaitCB->isChecked()); + + */ } void BedExtruderWidget::heatBedClicked(bool clicked) { + /* int temp = ui->bedTempSB->value() * clicked; emit bedTemperatureChanged(temp,ui->bedAndWaitCB->isChecked()); - + */ } int BedExtruderWidget::currentExtruder() { int currExt = 0; for (int i = 0; i < extruderMap.size(); i++) { if (extruderMap.value(i)->isChecked()) { currExt = i; break; } } return currExt; } diff --git a/src/widgets/bedextruderwidget.h b/src/widgets/bedextruderwidget.h index ee2c6fa..e8a7305 100644 --- a/src/widgets/bedextruderwidget.h +++ b/src/widgets/bedextruderwidget.h @@ -1,54 +1,54 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodriguessilva@gmail.com 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 -namespace Ui -{ -class BedExtruderWidget; -} +class ThermoWidget; class BedExtruderWidget : public QWidget { Q_OBJECT public: explicit BedExtruderWidget(QWidget *parent = nullptr); ~BedExtruderWidget(); void setExtruderCount(int value); void updateBedTemp(const float temp); void updateExtTemp(const float temp); void updateBedTargetTemp(const float temp); void updateExtTargetTemp(const float temp); void stopHeating(); private: - Ui::BedExtruderWidget *ui; +// Ui::BedExtruderWidget *ui; QMap extruderMap; void heatExtruderClicked(bool clicked); void heatBedClicked(bool clicked); int currentExtruder(); int extruderCount = 0; + ThermoWidget *m_exturderThermo; + ThermoWidget *m_bedThermo; + signals: void bedTemperatureChanged(int tmp, bool andWait); void extTemperatureChanged(int tmp, int currExt, bool andWait); }; diff --git a/src/widgets/thermowidget.cpp b/src/widgets/thermowidget.cpp new file mode 100644 index 0000000..8acc420 --- /dev/null +++ b/src/widgets/thermowidget.cpp @@ -0,0 +1,46 @@ +#include "thermowidget.h" + +ThermoWidget::ThermoWidget(QWidget *parent) : QwtDial(parent), + m_currentTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow)), + m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow)) +{ + setScaleArc(40, 320); + setNeedle(m_currentTemperatureNeedle); + + m_currentTemperature = 100; + m_targetTemperature = 120; + +} + +void ThermoWidget::drawNeedle( QPainter *painter, const QPointF ¢er, double radius, double dir, QPalette::ColorGroup colorGroup ) const +{ + Q_UNUSED( dir ); + + const double startAngle = minScaleArc(); + const double endAngle = maxScaleArc(); + + + const double minValue = lowerBound(); + const double maxValue = upperBound(); + + const double relativePercent = maxValue - minValue; + + const double currentTemperaturePercent = (m_currentTemperature - minValue) / relativePercent; + const double targetTemperaturePercent = (m_targetTemperature - minValue) / relativePercent; + + const double currentTemperatureAngle = (endAngle - startAngle) * currentTemperaturePercent + startAngle; + const double targetTemperatureAngle = (endAngle - startAngle) * targetTemperatureAngle + startAngle; + + m_targetTemperatureNeedle->draw(painter, center, radius, currentTemperatureAngle, colorGroup); + m_currentTemperatureNeedle->draw(painter, center, radius, targetTemperatureAngle, colorGroup); +} + +void ThermoWidget::setCurrentTemperature(double temperature) +{ + m_currentTemperature = temperature; +} + +void ThermoWidget::setTargetTemperature(double temperature) +{ + m_targetTemperature = temperature; +} diff --git a/src/widgets/thermowidget.h b/src/widgets/thermowidget.h new file mode 100644 index 0000000..3e596fe --- /dev/null +++ b/src/widgets/thermowidget.h @@ -0,0 +1,24 @@ +#ifndef THERMOWIDGET_H +#define THERMOWIDGET_H + +#include +#include + +class ThermoWidget : public QwtDial { + Q_OBJECT +public: + ThermoWidget(QWidget *parent); + void setTargetTemperature(double temperature); + void setCurrentTemperature(double temperature); + + void drawNeedle( QPainter *painter, const QPointF ¢er, + double radius, double dir, QPalette::ColorGroup colorGroup ) const; +private: + QwtDialSimpleNeedle *m_currentTemperatureNeedle; + QwtDialSimpleNeedle *m_targetTemperatureNeedle; + + double m_currentTemperature; + double m_targetTemperature; +}; + +#endif