diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(QT_MIN_VERSION "5.9.0") set(KF5_DEP_VERSION "5.30.0") -set(KDE_APPLICATIONS_VERSION_MAJOR "1") -set(KDE_APPLICATIONS_VERSION_MINOR "0") +set(KDE_APPLICATIONS_VERSION_MAJOR "0") +set(KDE_APPLICATIONS_VERSION_MINOR "70") set(KDE_APPLICATIONS_VERSION_MICRO "0") set(KDE_APPLICATIONS_VERSION "${KDE_APPLICATIONS_VERSION_MAJOR}.${KDE_APPLICATIONS_VERSION_MINOR}.${KDE_APPLICATIONS_VERSION_MICRO}") diff --git a/src/dialogs/profilesdialog.cpp b/src/dialogs/profilesdialog.cpp --- a/src/dialogs/profilesdialog.cpp +++ b/src/dialogs/profilesdialog.cpp @@ -54,11 +54,8 @@ }); connect(ui->removeProfilePB, &QPushButton::clicked, this, &ProfilesDialog::removeProfile); -#ifdef Q_OS_LINUX - ui->removeProfilePB->setIcon(QIcon::fromTheme("edit-delete")); -#else - ui->removeProfilePB->setIcon(style()->standardIcon(QStyle::SP_TrashIcon)); -#endif + ui->removeProfilePB->setIcon(QIcon::fromTheme(QStringLiteral("edit-delete"), style()->standardIcon(QStyle::SP_TrashIcon))); + //if any control is modifed and no load / save has happend contents are not saved. auto modify = [this] {setModified(true);}; connect(ui->baudCB, &QComboBox::currentTextChanged, modify); @@ -174,8 +171,8 @@ ui->printerTypeStack->setCurrentIndex(0); ui->deltaRB->setChecked(true); ui->cartesianRB->setChecked(false); - ui->radiusSB->setValue(m_settings.value(QStringLiteral("radius"), QStringLiteral("0")).toFloat()); - ui->z_delta_dimensionSB->setValue(m_settings.value(QStringLiteral("z_delta_dimension"), QStringLiteral("0")).toFloat()); + ui->radiusSB->setValue(m_settings.value(QStringLiteral("radius"), QStringLiteral("0")).toInt()); + ui->z_delta_dimensionSB->setValue(m_settings.value(QStringLiteral("z_delta_dimension"), QStringLiteral("0")).toInt()); } ui->heatedBedCK->setChecked(m_settings.value(QStringLiteral("heatedBed"), QStringLiteral("true")).toBool()); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -251,7 +251,7 @@ auto *viewer3D = new Viewer3D(this); connect(viewer3D, &Viewer3D::droppedUrls, this, &MainWindow::processDropEvent); - connect(m_gcodeEditor, &GCodeEditorWidget::currentFileChanged, this, [this, viewer3D](const QUrl & url) { + connect(m_gcodeEditor, &GCodeEditorWidget::currentFileChanged, this, [viewer3D](const QUrl & url) { viewer3D->drawModel(url.toString()); }); diff --git a/src/widgets/3dview/fileloader.cpp b/src/widgets/3dview/fileloader.cpp --- a/src/widgets/3dview/fileloader.cpp +++ b/src/widgets/3dview/fileloader.cpp @@ -54,15 +54,15 @@ qint64 stillSize = totalSize; if (_file.open(QIODevice::ReadOnly)) { - float lastPerc = 0.0; + int lastPerc = 0; QTextStream in(&_file); while (!in.atEnd()) { //Get each line QString line = in.readLine(); stillSize -= line.size() + 1; // +1 endl - const float perc = (totalSize - stillSize) * 100.0 / totalSize; + const int perc = int((totalSize - stillSize) * 100.0 / totalSize); if (perc - lastPerc > 1) { - emit percentUpdate((int)perc); + emit percentUpdate(perc); lastPerc = perc; } line = line.simplified(); diff --git a/src/widgets/3dview/linemesh.cpp b/src/widgets/3dview/linemesh.cpp --- a/src/widgets/3dview/linemesh.cpp +++ b/src/widgets/3dview/linemesh.cpp @@ -58,11 +58,9 @@ { QVector vertices; vertices.reserve(pos.size()); - std::transform(pos.cbegin(), pos.cend(), - std::back_inserter(vertices), - [](const QVector4D & x) { - return x.toVector3D(); - }); + std::transform(pos.cbegin(), pos.cend(), std::back_inserter(vertices), [](const QVector4D & x) { + return x.toVector3D(); + }); _lineMeshGeo = new LineMeshGeometry(vertices, this); setVertexCount(_lineMeshGeo->vertexCount()); diff --git a/src/widgets/atcoreinstancewidget.h b/src/widgets/atcoreinstancewidget.h --- a/src/widgets/atcoreinstancewidget.h +++ b/src/widgets/atcoreinstancewidget.h @@ -81,7 +81,7 @@ QWidget *m_connectWidget; void buildConnectionToolbar(); void buildToolbar(); - void checkTemperature(uint sensorType, uint number, uint temp); + void checkTemperature(uint sensorType, uint number, float temp); void connectButtonClicked(); void connectBedTemperatureData(bool connected); void connectExtruderTemperatureData(bool connected); diff --git a/src/widgets/atcoreinstancewidget.cpp b/src/widgets/atcoreinstancewidget.cpp --- a/src/widgets/atcoreinstancewidget.cpp +++ b/src/widgets/atcoreinstancewidget.cpp @@ -118,7 +118,7 @@ for (auto homes : std::map {{"X", AtCore::X}, {"Y", AtCore::Y}, {"Z", AtCore::Z}}) { auto home = new QAction(homes.first); connect(home, &QAction::triggered, this, [this, homes] { - m_core.home(homes.second); + m_core.home(uchar(homes.second)); }); m_toolBar->addAction(home); } @@ -443,7 +443,7 @@ m_statusWidget->setState(stateString); } -void AtCoreInstanceWidget::checkTemperature(uint sensorType, uint number, uint temp) +void AtCoreInstanceWidget::checkTemperature(uint sensorType, uint number, float temp) { static QString msg; switch (sensorType) { @@ -474,7 +474,7 @@ msg.append(QString::fromLatin1("[%1] : %2")); msg = msg.arg(QString::number(number)) - .arg(QString::number(temp)); + .arg(QString::number(temp, 'f', 2)); m_logWidget->appendLog(msg); } diff --git a/src/widgets/bedextruderwidget.h b/src/widgets/bedextruderwidget.h --- a/src/widgets/bedextruderwidget.h +++ b/src/widgets/bedextruderwidget.h @@ -37,8 +37,8 @@ void setExtruderMaxTemperature(int value); void updateBedTemp(const float temp); void updateExtTemp(const float temp); - void updateBedTargetTemp(const float temp); - void updateExtTargetTemp(const float temp); + void updateBedTargetTemp(const int temp); + void updateExtTargetTemp(const int temp); void setBedThermoHidden(bool hidden); private: diff --git a/src/widgets/bedextruderwidget.cpp b/src/widgets/bedextruderwidget.cpp --- a/src/widgets/bedextruderwidget.cpp +++ b/src/widgets/bedextruderwidget.cpp @@ -47,14 +47,14 @@ //Add Default Extruder setExtruderCount(1); - connect(m_bedThermo, &ThermoWidget::targetTemperatureChanged, this, [this](double v) { + connect(m_bedThermo, &ThermoWidget::targetTemperatureChanged, this, [this](int v) { qDebug() << "Receiving the temperature change for bed"; - emit bedTemperatureChanged((int)v, false); + emit bedTemperatureChanged(v, false); }); - connect(m_extruderThermo, &ThermoWidget::targetTemperatureChanged, this, [this](double v) { + connect(m_extruderThermo, &ThermoWidget::targetTemperatureChanged, this, [this](int v) { qDebug() << "Receiving the temperature changed for thermo"; - emit extTemperatureChanged((int)v, currentExtruder(), false); + emit extTemperatureChanged(v, currentExtruder(), false); }); } @@ -84,20 +84,20 @@ void BedExtruderWidget::updateBedTemp(const float temp) { - m_bedThermo->setCurrentTemperature(temp); + m_bedThermo->setCurrentTemperature(double(temp)); } void BedExtruderWidget::updateExtTemp(const float temp) { - m_extruderThermo->setCurrentTemperature(temp); + m_extruderThermo->setCurrentTemperature(double(temp)); } -void BedExtruderWidget::updateBedTargetTemp(const float temp) +void BedExtruderWidget::updateBedTargetTemp(const int temp) { m_bedThermo->setTargetTemperature(temp); } -void BedExtruderWidget::updateExtTargetTemp(const float temp) +void BedExtruderWidget::updateExtTargetTemp(const int temp) { m_extruderThermo->setTargetTemperature(temp); } diff --git a/src/widgets/thermowidget.h b/src/widgets/thermowidget.h --- a/src/widgets/thermowidget.h +++ b/src/widgets/thermowidget.h @@ -38,7 +38,7 @@ double radius, double dir, QPalette::ColorGroup colorGroup) const; void setCurrentTemperature(double temperature); - void setTargetTemperature(double temperature); + void setTargetTemperature(int temperature); signals: void targetTemperatureChanged(double targetTemperature); @@ -51,6 +51,7 @@ void wheelEvent(QWheelEvent *event); private: + bool isEqual(double a = 0, double b = 0); QwtDialSimpleNeedle *m_currentTemperatureNeedle; QwtDialSimpleNeedle *m_targetTemperatureNeedle; QString m_currentTemperatureTextFromEditor = QString("-"); @@ -60,6 +61,6 @@ bool m_paintCursor = false; int m_cursorPos = 0; double m_currentTemperature; - double m_targetTemperature; + int m_targetTemperature; void resetTimer(); }; diff --git a/src/widgets/thermowidget.cpp b/src/widgets/thermowidget.cpp --- a/src/widgets/thermowidget.cpp +++ b/src/widgets/thermowidget.cpp @@ -29,7 +29,7 @@ ThermoWidget::ThermoWidget(QWidget *parent, QString name) : QwtDial(parent) - , m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, Qt::red, Qt::darkRed)) + , m_targetTemperatureNeedle(new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, false, Qt::red, Qt::darkRed)) , m_name(name) , m_tempChangedTimer(new QTimer()) , m_currentTemperature(0) @@ -106,11 +106,11 @@ } else if (event->key() == Qt::Key_Escape) { m_currentTemperatureTextFromEditor = '0'; } else if (event->key() == Qt::Key_Up || event->key() == Qt::Key_Plus) { - if (m_targetTemperature != upperBound()) { + if (!isEqual(m_targetTemperature, upperBound())) { m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature + 1); } } else if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Minus) { - if (m_targetTemperature != lowerBound()) { + if (!isEqual(m_targetTemperature, lowerBound())) { m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature - 1); } } else if (event->key() == Qt::Key_PageUp) { @@ -125,9 +125,7 @@ } else { m_currentTemperatureTextFromEditor = QString::number(m_targetTemperature - 10); } - } - - else if (event->key() == Qt::Key_Right) { + } else if (event->key() == Qt::Key_Right) { if (m_cursorPos < slen) { m_cursorPos++; } @@ -196,22 +194,22 @@ 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 wWidth = fm.width('W'); - const double cursorWidth = fm.width('0'); - 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); - const double xposCursor = xposTarget + (cursorWidth * m_cursorPos); - double ypos = geometry().height() / 2 + height * 2; + const int targetWidth = fm.width(m_currentTemperatureTextFromEditor); + const int currentWidth = fm.width(currentText); + const int nameWidth = fm.width(m_name); + const int wWidth = fm.width('W'); + const int cursorWidth = fm.width('0'); + const int height = fm.height(); + const int halfWidth = geometry().width() / 2; + const int xposTarget = int(halfWidth - (targetWidth / 2)); + const int xposCurrent = int(halfWidth - (currentWidth / 2)); + const int xposName = halfWidth - (nameWidth / 2); + const int xposCursor = xposTarget + (cursorWidth * m_cursorPos); + int ypos = geometry().height() / 2 + height * 2; QPainter p(this); QColor color = palette().color(QPalette::Text); //draw a box to put our target into as a user hint. - p.fillRect(QRect(halfWidth - wWidth, ypos - (height * 0.66), wWidth * 2, (height * 0.9)), palette().color(QPalette::AlternateBase)); + p.fillRect(QRect(int(halfWidth - wWidth), int(ypos - (height * 0.66)), int(wWidth * 2), int(height * 0.9)), palette().color(QPalette::AlternateBase)); if (m_paintCursor) { p.setPen(palette().color(QPalette::Text)); @@ -238,6 +236,8 @@ void ThermoWidget::drawNeedle(QPainter *painter, const QPointF ¢er, double radius, double dir, QPalette::ColorGroup colorGroup) const { Q_UNUSED(dir); + //save a copy of radius as int to avoid casting it several times. + int radiusAsInt = int(radius); const double relativePercent = upperBound() - lowerBound(); const double currentTemperaturePercent = (m_currentTemperature - lowerBound()) / relativePercent; const double targetTemperaturePercent = (m_targetTemperature - lowerBound()) / relativePercent; @@ -247,32 +247,32 @@ // 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; + const int qtBeginAngle = -130; + const int coolZone = int (- (targetTemperatureAngle - minScaleArc())); + int yPos = geometry().height() / 2 - radiusAsInt; + int xPos = geometry().width() / 2 - radiusAsInt; 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); + painter->drawPie(xPos, yPos, radiusAsInt * 2, radiusAsInt * 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) { + if (!isEqual(m_currentTemperature, temperature)) { m_currentTemperature = temperature; update(); } } -void ThermoWidget::setTargetTemperature(double temperature) +void ThermoWidget::setTargetTemperature(int temperature) { if (m_targetTemperature != temperature) { m_currentTemperatureTextFromEditor = QString::number(temperature); @@ -286,3 +286,21 @@ { m_tempChangedTimer->start(500); } + +bool ThermoWidget::isEqual(double a, double b) +{ +//qFuzzyCompare always returns false if a || b ==0 + if (qFuzzyIsNull(a) || qFuzzyIsNull(b)) { + if (a < 0.0 || b < 0.0) { + //One number is 0 and the other negative + //to prevent a issue if a or b == -1 and the other 0 + //we will subtract one from each value + a -= 1; + b -= 1; + } else { + a += 1; + b += 1; + } + } + return qFuzzyCompare(a, b); +}