diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,15 @@ project(atelier) find_package(ECM REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH}) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(KDECompilerSettings) include(KDEInstallDirs) include(KDECMakeSettings) include(ECMInstallIcons) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) set(QT_MIN_VERSION "5.9.0") set(KF5_DEP_VERSION "5.30.0") @@ -27,6 +28,8 @@ AtCore ) +find_package(Qwt6 REQUIRED) + find_package(KF5 ${KF5_DEP_VERSION} REQUIRED COMPONENTS I18n XmlGui @@ -48,7 +51,7 @@ Multimedia MultimediaWidgets ) - + if(BUILD_TESTING) find_package(Qt5Test ${QT_MIN_VERSION} CONFIG REQUIRED) endif() diff --git a/cmake/FindQwt6.cmake b/cmake/FindQwt6.cmake new file mode 100644 --- /dev/null +++ b/cmake/FindQwt6.cmake @@ -0,0 +1,112 @@ +# Qt Widgets for Technical Applications +# available at http://www.http://qwt.sourceforge.net/ +# +# The module defines the following variables: +# QWT_FOUND - the system has Qwt +# QWT_INCLUDE_DIR - where to find qwt_plot.h +# QWT_INCLUDE_DIRS - qwt includes +# QWT_LIBRARY - where to find the Qwt library +# QWT_LIBRARIES - aditional libraries +# QWT_MAJOR_VERSION - major version +# QWT_MINOR_VERSION - minor version +# QWT_PATCH_VERSION - patch version +# QWT_VERSION_STRING - version (ex. 5.2.1) +# QWT_ROOT_DIR - root dir (ex. /usr/local) + +#============================================================================= +# Copyright 2010-2013, Julien Schueller +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# The views and conclusions contained in the software and documentation are those +# of the authors and should not be interpreted as representing official policies, +# either expressed or implied, of the FreeBSD Project. +#============================================================================= + + +find_path ( QWT_INCLUDE_DIR + NAMES qwt_plot.h + HINTS ${QT_INCLUDE_DIR} + PATH_SUFFIXES qwt qwt-qt3 qwt-qt4 qwt-qt5 + ) + +set ( QWT_INCLUDE_DIRS ${QWT_INCLUDE_DIR} ) + +# version +set ( _VERSION_FILE ${QWT_INCLUDE_DIR}/qwt_global.h ) +if ( EXISTS ${_VERSION_FILE} ) + file ( STRINGS ${_VERSION_FILE} _VERSION_LINE REGEX "define[ ]+QWT_VERSION_STR" ) + if ( _VERSION_LINE ) + string ( REGEX REPLACE ".*define[ ]+QWT_VERSION_STR[ ]+\"(.*)\".*" "\\1" QWT_VERSION_STRING "${_VERSION_LINE}" ) + string ( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" QWT_MAJOR_VERSION "${QWT_VERSION_STRING}" ) + string ( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" QWT_MINOR_VERSION "${QWT_VERSION_STRING}" ) + string ( REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\3" QWT_PATCH_VERSION "${QWT_VERSION_STRING}" ) + endif () +endif () + + +# check version +set ( _QWT_VERSION_MATCH TRUE ) +if ( Qwt_FIND_VERSION AND QWT_VERSION_STRING ) + if ( Qwt_FIND_VERSION_EXACT ) + if ( NOT Qwt_FIND_VERSION VERSION_EQUAL QWT_VERSION_STRING ) + set ( _QWT_VERSION_MATCH FALSE ) + endif () + else () + if ( QWT_VERSION_STRING VERSION_LESS Qwt_FIND_VERSION ) + set ( _QWT_VERSION_MATCH FALSE ) + endif () + endif () +endif () + + +find_library ( QWT_LIBRARY + NAMES qwt qwt-qt3 qwt-qt4 qwt-qt5 + ) + +set ( QWT_LIBRARIES ${QWT_LIBRARY} ) + + +# try to guess root dir from include dir +if ( QWT_INCLUDE_DIR ) + string ( REGEX REPLACE "(.*)/include.*" "\\1" QWT_ROOT_DIR ${QWT_INCLUDE_DIR} ) + # try to guess root dir from library dir +elseif ( QWT_LIBRARY ) + string ( REGEX REPLACE "(.*)/lib[/|32|64].*" "\\1" QWT_ROOT_DIR ${QWT_LIBRARY} ) +endif () + + +# handle the QUIETLY and REQUIRED arguments +include ( FindPackageHandleStandardArgs ) +find_package_handle_standard_args( Qwt6 DEFAULT_MSG QWT_LIBRARY QWT_INCLUDE_DIR _QWT_VERSION_MATCH ) + +mark_as_advanced ( + QWT_LIBRARY + QWT_LIBRARIES + QWT_INCLUDE_DIR + QWT_INCLUDE_DIRS + QWT_MAJOR_VERSION + QWT_MINOR_VERSION + QWT_PATCH_VERSION + QWT_VERSION_STRING + QWT_ROOT_DIR + ) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -1,4 +1,5 @@ include_directories(../dialogs) +include_directories(${QWT_INCLUDE_DIR}) set(widgets_SRCS gcodeeditorwidget.cpp @@ -11,20 +12,23 @@ 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.h b/src/widgets/bedextruderwidget.h --- a/src/widgets/bedextruderwidget.h +++ b/src/widgets/bedextruderwidget.h @@ -1,6 +1,7 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodriguessilva@gmail.com + 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 @@ -20,11 +21,9 @@ #include #include #include +#include -namespace Ui -{ -class BedExtruderWidget; -} +class ThermoWidget; class BedExtruderWidget : public QWidget { @@ -38,15 +37,16 @@ void updateExtTemp(const float temp); void updateBedTargetTemp(const float temp); void updateExtTargetTemp(const float temp); - void stopHeating(); private: - Ui::BedExtruderWidget *ui; QMap extruderMap; - void heatExtruderClicked(bool clicked); - void heatBedClicked(bool clicked); int currentExtruder(); - int extruderCount = 0; + + int m_extruderCount = 0; + ThermoWidget *m_bedThermo=nullptr; + ThermoWidget *m_extruderThermo=nullptr; + QWidget *m_extruderBox=nullptr; + QHBoxLayout *m_extrudersLayout=nullptr; signals: void bedTemperatureChanged(int tmp, bool andWait); diff --git a/src/widgets/bedextruderwidget.cpp b/src/widgets/bedextruderwidget.cpp --- a/src/widgets/bedextruderwidget.cpp +++ b/src/widgets/bedextruderwidget.cpp @@ -1,7 +1,8 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Lays Rodrigues - laysrodriguessilva@gmail.com - + 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 @@ -16,103 +17,94 @@ along with this program. If not, see . */ #include "bedextruderwidget.h" -#include "ui_bedextruderwidget.h" -#include #include +#include + +#include "thermowidget.h" + BedExtruderWidget::BedExtruderWidget(QWidget *parent) : QWidget(parent), - ui(new Ui::BedExtruderWidget) + m_bedThermo(new ThermoWidget(this, QString(i18n("Bed")))), + m_extruderThermo(new ThermoWidget(this, QString(i18n("HotEnd")))), + m_extruderBox(new QWidget(this)), + m_extrudersLayout(new QHBoxLayout) { - ui->setupUi(this); + m_bedThermo->setScale(0, 150); + m_extruderThermo->setScale(0, 250); + m_extruderBox->setLayout(m_extrudersLayout); + + auto *layout = new QGridLayout; + + auto *label = new QLabel(i18n("Active Extruder:")); + m_extrudersLayout->addWidget(label); + + layout->addWidget(m_extruderBox, 0, 0, 1, -1); + layout->addWidget(m_bedThermo, 1, 0); + layout->addWidget(m_extruderThermo, 1, 1); + + setLayout(layout); //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(m_bedThermo, &ThermoWidget::targetTemperatureChanged, [this](double v) { + qDebug() << "Receiving the temperature change for bed"; + emit bedTemperatureChanged((int)v, false); + }); - connect(ui->extTempSB, static_cast(&QDoubleSpinBox::valueChanged), [ = ](double tmp) { - if (ui->heatExtPB->isChecked()) { - emit extTemperatureChanged(tmp, currentExtruder(),ui->extAndWaitCB->isChecked()); - } - }); + connect(m_extruderThermo, &ThermoWidget::targetTemperatureChanged, [this](double v) { + qDebug() << "Receiving the temperature changed for thermo"; + emit extTemperatureChanged((int)v, currentExtruder(), false); + }); } BedExtruderWidget::~BedExtruderWidget() { - delete ui; } void BedExtruderWidget::setExtruderCount(int value) { - if (value == extruderCount) { + value > 1 ? m_extruderBox->setVisible(true) : m_extruderBox->setVisible(false); + if (value == m_extruderCount) { return; - } else if (extruderCount < value) { + } else if (m_extruderCount < value) { //loop for the new buttons - for (int i = extruderCount; i < value; i++) { + for (int i = m_extruderCount; i < value; i++) { auto *rb = new QRadioButton(QString::number(i + 1)); - ui->extRadioButtonLayout->addWidget(rb); + m_extrudersLayout->addWidget(rb); extruderMap.insert(i, rb); } } else { //remove buttons - need to test it! - for (int i = extruderCount; i >= value; i--) { + for (int i = m_extruderCount; i >= value; i--) { auto *rb = extruderMap.value(i); - ui->extRadioButtonLayout->removeWidget(rb); + m_extrudersLayout->removeWidget(rb); extruderMap.remove(i); delete (rb); } } - extruderCount = value; + m_extruderCount = value; } void BedExtruderWidget::updateBedTemp(const float temp) { - ui->bedCurrTempLB->setText(QString::number(temp)); + m_bedThermo->setCurrentTemperature(temp); } void BedExtruderWidget::updateExtTemp(const float temp) { - ui->extCurrTempLB->setText(QString::number(temp)); + m_extruderThermo->setCurrentTemperature(temp); } void BedExtruderWidget::updateBedTargetTemp(const float temp) { - ui->bedTargetTempLB->setText(QString::number(temp) + " ºC"); + m_bedThermo->setTargetTemperature(temp); } void BedExtruderWidget::updateExtTargetTemp(const float temp) { - 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()); - + m_extruderThermo->setTargetTemperature(temp); } int BedExtruderWidget::currentExtruder() diff --git a/src/widgets/bedextruderwidget.ui b/src/widgets/bedextruderwidget.ui deleted file mode 100644 --- a/src/widgets/bedextruderwidget.ui +++ /dev/null @@ -1,182 +0,0 @@ - - - BedExtruderWidget - - - - 0 - 0 - 266 - 247 - - - - Form - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - ºC - - - 0 - - - 150.000000000000000 - - - - - - - Heat - - - true - - - - - - - Target Temperature: - - - - - - - 0 ºC - - - - - - - Current Temperature: - - - - - - - 0 ºC - - - - - - - Qt::Horizontal - - - - - - - Hotend - - - Qt::AlignCenter - - - - - - - ºC - - - 0 - - - 250.000000000000000 - - - - - - - Bed - - - Qt::AlignCenter - - - - - - - Heat - - - true - - - - - - - Target Temperature: - - - - - - - 0 ºC - - - - - - - Current Temperature: - - - - - - - 0 ºC - - - - - - - - - - andWait - - - - - - - andWait - - - - - - - - diff --git a/src/widgets/thermowidget.h b/src/widgets/thermowidget.h new file mode 100644 --- /dev/null +++ b/src/widgets/thermowidget.h @@ -0,0 +1,62 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2018> + Author: Tomaz Canabrava - tcanabrava@kde.org + Chris Rizzitello - rizzitello@kde.org + 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 . +*/ +#ifndef THERMOWIDGET_H +#define THERMOWIDGET_H + +#include +#include + +class QKeyEvent; +class QPaintEvent; +class QFocusEvent; +class QWheelEvent; + +class ThermoWidget : public QwtDial { + Q_OBJECT + +public: + ThermoWidget(QWidget *parent, QString name); + void setTargetTemperature(double temperature); + void setCurrentTemperature(double temperature); + + void drawNeedle( QPainter *painter, const QPointF ¢er, + double radius, double dir, QPalette::ColorGroup colorGroup ) const; + +signals: + void targetTemperatureChanged(double targetTemperature); + +protected: + void keyPressEvent (QKeyEvent *); + void paintEvent(QPaintEvent *); + void focusOutEvent(QFocusEvent *); + void wheelEvent(QWheelEvent *event); + +private: + QwtDialSimpleNeedle *m_currentTemperatureNeedle; + QwtDialSimpleNeedle *m_targetTemperatureNeedle; + + double m_currentTemperature; + double m_targetTemperature; + + QString m_currentTemperatureTextFromEditor; + QString m_name; +}; + +#endif diff --git a/src/widgets/thermowidget.cpp b/src/widgets/thermowidget.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/thermowidget.cpp @@ -0,0 +1,209 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2018> + Author: Tomaz Canabrava - tcanabrava@kde.org + Chris Rizzitello - rizzitello@kde.org + 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 "thermowidget.h" +#include +#include +#include +#include +#include +#include +#include + +ThermoWidget::ThermoWidget(QWidget *parent, QString name) : QwtDial(parent), + m_currentTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow)), + m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, Qt::red, Qt::darkRed)), + m_name(name) +{ + setScaleArc(40, 320); + setNeedle(m_currentTemperatureNeedle); + setReadOnly(false); + setFocusPolicy(Qt::StrongFocus); + + m_currentTemperature = 0; + m_targetTemperature = 0; +} + +void ThermoWidget::keyPressEvent(QKeyEvent* ev) +{ + if (ev->key() >= Qt::Key_0 && ev->key() <= Qt::Key_9) { + auto tmp = m_currentTemperatureTextFromEditor + ev->key(); + if (tmp.toInt() <= upperBound() && tmp.toInt() >= lowerBound()) { + m_currentTemperatureTextFromEditor = tmp; + } + } else if (ev->key() == Qt::Key_Backspace && m_currentTemperatureTextFromEditor.count()) { + m_currentTemperatureTextFromEditor.remove(m_currentTemperatureTextFromEditor.count() - 1, 1); + } else if (ev->key() == Qt::Key_Enter) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + } else if (ev->key() == Qt::Key_Escape) { + m_currentTemperatureTextFromEditor = '0'; + } else if (ev->key() == Qt::Key_Up || ev->key() == Qt::Key_Right) { + if (m_targetTemperature != upperBound()) { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature + 1); + } + } else if (ev->key() == Qt::Key_Down || ev->key() == Qt::Key_Left) { + if (m_targetTemperature != lowerBound()) { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature - 1); + } + } else if (ev->key() == Qt::Key_PageUp) { + if (m_targetTemperature + 10 > upperBound()) { + m_currentTemperatureTextFromEditor = QString::number(upperBound()); + } else { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature + 10); + } + } else if (ev->key() == Qt::Key_PageDown) { + if (m_targetTemperature - 10 < lowerBound()) { + m_currentTemperatureTextFromEditor = QString::number(lowerBound()); + } else { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature - 10); + } + } + + else { + QwtDial::keyPressEvent(ev); + return; + } + + if (m_targetTemperature != m_currentTemperatureTextFromEditor.toInt()) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + emit targetTemperatureChanged(m_targetTemperature); + update(); + ev->accept(); + } +} + +void ThermoWidget::focusOutEvent(QFocusEvent* ev) +{ + if (m_targetTemperature != m_currentTemperatureTextFromEditor.toInt()) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + emit targetTemperatureChanged(m_targetTemperature); + update(); + ev->accept(); + } +} + + +void ThermoWidget::paintEvent(QPaintEvent* ev) +{ + QwtDial::paintEvent(ev); + const QString currentText = QString::number(m_currentTemperature); + + QFontMetrics fm(font()); + const double targetWidth = fm.width(m_currentTemperatureTextFromEditor); + const double currentWidth = fm.width(currentText); + const double nameWidth = fm.width(m_name); + + const double height = fm.height(); + const double halfWidth = geometry().width() / 2; + const double xposTarget = halfWidth - (targetWidth / 2); + const double xposCurrent = halfWidth - (currentWidth / 2); + const double xposName = halfWidth - (nameWidth / 2); + double ypos = geometry().height() / 2 + height * 2; + QPainter p(this); + QColor color = palette().color(QPalette::Text); + + p.setPen(Qt::red); + p.drawText(xposTarget, ypos, m_currentTemperatureTextFromEditor); + + ypos += height + 2; + + p.setPen(color); + p.drawText(xposCurrent, ypos, QString::number(m_currentTemperature)); + + ypos += height + 2; + + p.setPen(color); + p.drawText(xposName, ypos, m_name); +} + +void ThermoWidget::wheelEvent(QWheelEvent* ev) +{ + if (ev->angleDelta().y() > 0) { + if (m_targetTemperature + 10 > upperBound()) { + m_currentTemperatureTextFromEditor = QString::number(upperBound()); + } else { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature + 10); + } + } else if (ev->angleDelta().y() < 0) { + if (m_targetTemperature - 10 < lowerBound()) { + m_currentTemperatureTextFromEditor = QString::number(lowerBound()); + } else { + m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature - 10); + } + } + + if (m_targetTemperature != m_currentTemperatureTextFromEditor.toInt()) { + m_targetTemperature = m_currentTemperatureTextFromEditor.toInt(); + emit targetTemperatureChanged(m_targetTemperature); + update(); + } + ev->accept(); +} + + +void ThermoWidget::drawNeedle( QPainter *painter, const QPointF ¢er, double radius, double dir, QPalette::ColorGroup colorGroup ) const +{ + Q_UNUSED( dir ); + + const double relativePercent = upperBound() - lowerBound(); + const double currentTemperaturePercent = (m_currentTemperature - lowerBound()) / relativePercent; + const double targetTemperaturePercent = (m_targetTemperature - lowerBound()) / relativePercent; + const double currentTemperatureAngle = (maxScaleArc() - minScaleArc()) * currentTemperaturePercent + minScaleArc(); + const double targetTemperatureAngle = (maxScaleArc() - minScaleArc()) * targetTemperaturePercent + minScaleArc(); + + // Qt coordinates and Qwt coordinates differ. + // the "begin" of our coordinates in Qt: -130 + // the "span" of our coordinates in Qt: -180 + // Negative values means clockwise in Qt dialect. + const double qtBeginAngle = -130; + const double coolZone = - (targetTemperatureAngle - minScaleArc()); + int yPos = geometry().height() / 2 - radius; + int xPos = geometry().width() / 2 - radius; + + QRadialGradient grad(center,radius); + grad.setColorAt(0.75,QColor(0,0,0,0)); + grad.setColorAt(0.85,QColor(255,0,0,196)); + grad.setColorAt(0.95,QColor(255,110,60,196)); + + painter->setBrush(grad); + painter->drawPie(xPos,yPos, radius * 2, radius * 2, qtBeginAngle * 16, coolZone* 16); + + m_targetTemperatureNeedle->draw(painter, center, radius * 1.3, 360 - targetTemperatureAngle - origin(), colorGroup); + m_currentTemperatureNeedle->draw(painter, center, radius, 360 - currentTemperatureAngle - origin(), colorGroup); + + +} + +void ThermoWidget::setCurrentTemperature(double temperature) +{ + if (m_currentTemperature != temperature) { + m_currentTemperature = temperature; + update(); + } +} + +void ThermoWidget::setTargetTemperature(double temperature) +{ + if (m_targetTemperature != temperature) { + m_currentTemperatureTextFromEditor = QString::number(temperature); + m_targetTemperature = temperature; + emit targetTemperatureChanged(m_targetTemperature); + update(); + } +}