diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -382,15 +382,15 @@ * @param arg the distance to move the axis or the place to move to depending on printer mode * @sa home(), home(uchar axis), move(QLatin1Char axis, int arg) */ - Q_INVOKABLE void move(AtCore::AXES axis, int arg); + Q_INVOKABLE void move(AtCore::AXES axis, double arg); /** * @brief move an axis of the printer * @param axis the axis to move AXES (X Y Z E ) * @param arg the distance to move the axis or the place to move to depending on printer mode * @sa home(), home(uchar axis), move(AtCore::AXES, int arg) */ - Q_INVOKABLE void move(QLatin1Char axis, int arg); + Q_INVOKABLE void move(QLatin1Char axis, double arg); /** * @brief Set the bed temperature diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -612,15 +612,15 @@ pushCommand(GCode::toCommand(GCode::M221, QString::number(speed))); } -void AtCore::move(AtCore::AXES axis, int arg) +void AtCore::move(AtCore::AXES axis, double arg) { const auto axisAsString = QMetaEnum::fromType().valueToKey(axis); move(QLatin1Char(axisAsString[0]), arg); } -void AtCore::move(QLatin1Char axis, int arg) +void AtCore::move(QLatin1Char axis, double arg) { - pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1 %2").arg(axis).arg(QString::number(arg)))); + pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1 %2").arg(axis).arg(QString::number(arg, 'g', 3)))); } int AtCore::extruderCount() const diff --git a/src/widgets/axiscontrol.h b/src/widgets/axiscontrol.h --- a/src/widgets/axiscontrol.h +++ b/src/widgets/axiscontrol.h @@ -28,7 +28,7 @@ { Q_OBJECT public: - PieButton(QLatin1Char &axis, int value, int size, int angle); + PieButton(QLatin1Char &axis, double value, int size, int angle); void setPalette(QPalette palette); protected: void mousePressEvent(QGraphicsSceneMouseEvent *); @@ -38,16 +38,16 @@ void clicked(QLatin1Char axis, int value); private: QLatin1Char _axis; - int _value; + double _value; QPalette _palette; }; class ATCOREWIDGETS_EXPORT RectButton : public QObject, public QGraphicsRectItem { Q_OBJECT public: - RectButton(QLatin1Char &axis, int value, int size); + RectButton(QLatin1Char &axis, double value, int size); void setPalette(QPalette palette); protected: void mousePressEvent(QGraphicsSceneMouseEvent *); @@ -57,7 +57,7 @@ void clicked(QLatin1Char axis, int value); private: QLatin1Char _axis; - int _value; + double _value; QPalette _palette; }; @@ -72,10 +72,10 @@ Q_OBJECT public: - explicit AxisControl(const QList &movementValues = {1, 10, 25}, QWidget *parent = nullptr); + explicit AxisControl(const QList &movementValues = {0.1, 1, 10}, QWidget *parent = nullptr); private: - void setLabels(QGraphicsItem *item, QLatin1Char &axis, int value); + void setLabels(QGraphicsItem *item, QLatin1Char &axis, double value); protected: void resizeEvent(QResizeEvent *); @@ -86,6 +86,6 @@ * @param axis: Axis to move * @param value: Amount to move */ - void clicked(QLatin1Char axis, int value); + void clicked(QLatin1Char axis, double value); }; diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp --- a/src/widgets/axiscontrol.cpp +++ b/src/widgets/axiscontrol.cpp @@ -19,7 +19,7 @@ #include "axiscontrol.h" #include -PieButton::PieButton(QLatin1Char &axis, int value, int size, int angle) : _axis(axis), _value(value) +PieButton::PieButton(QLatin1Char &axis, double value, int size, int angle) : _axis(axis), _value(value) { const int delta = 16; // Qt Docs: angle is 16th of a degree. setBrush(_palette.button()); @@ -51,7 +51,7 @@ setBrush(_palette.button()); } -RectButton::RectButton(QLatin1Char &axis, int value, int size) : _axis(axis), _value(value) +RectButton::RectButton(QLatin1Char &axis, double value, int size) : _axis(axis), _value(value) { setBrush(_palette.button()); setRect(QRect(QPoint(0, 0), QPoint(size, size))); @@ -91,36 +91,36 @@ in the scene. If you have a better solution, please share with us. Lays Rodrigues - Jan/2017 */ -AxisControl::AxisControl(const QList &movementValues, QWidget *parent) : +AxisControl::AxisControl(const QList &movementValues, QWidget *parent) : QGraphicsView(parent) { setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); setScene(new QGraphicsScene()); const int listSize = movementValues.size(); - int maxValue = *std::max_element(movementValues.begin(), movementValues.end()); - QList lessList = movementValues; - std::sort(lessList.begin(), lessList.end(), std::less()); - QList greaterList = movementValues; - std::sort(greaterList.begin(), greaterList.end(), std::greater()); + double maxValue = *std::max_element(movementValues.begin(), movementValues.end()); + QList lessList = movementValues; + std::sort(lessList.begin(), lessList.end(), std::less()); + QList greaterList = movementValues; + std::sort(greaterList.begin(), greaterList.end(), std::greater()); - auto createPie = [ this, maxValue ](QLatin1Char & axis, int value, int size, int angle) { + auto createPie = [ this, maxValue ](QLatin1Char & axis, double value, int size, int angle) { auto pie = new PieButton(axis, value, size, angle); pie->setPalette(this->palette()); connect(pie, &PieButton::clicked, this, &AxisControl::clicked); - if (abs(value) == maxValue) { + if (QString::number(abs(value)) == QString::number(maxValue)) { setLabels(pie, axis, value); } scene()->addItem(pie); }; - auto createRect = [ this, maxValue ](QLatin1Char & axis, int value, int size, int xPos, int yPos) { + auto createRect = [ this, maxValue ](QLatin1Char & axis, double value, int size, int xPos, int yPos) { auto z = new RectButton(axis, value, size); z->setPalette(this->palette()); z->setPos(xPos, yPos); connect(z, &RectButton::clicked, this, &AxisControl::clicked); - if (abs(value) == maxValue) { + if (QString::number(abs(value)) == QString::number(maxValue)) { setLabels(z, axis, value); } scene()->addItem(z); @@ -131,7 +131,7 @@ auto ychar = QLatin1Char('Y'); auto zchar = QLatin1Char('Z'); auto echar = QLatin1Char('E'); - for (const int &value : lessList) { + for (const double &value : lessList) { createPie(xchar, value, currPieSize, -45); // Left createPie(xchar, value * -1, currPieSize, 135); // Right createPie(ychar, value, currPieSize, 45); // Top @@ -144,13 +144,13 @@ int yPos = -(listSize * 25); //Align with the origin // Z+ - for (const int &value : greaterList) { + for (const double &value : greaterList) { createRect(zchar, value, currSize, xPos, yPos); yPos += currSize; } // Z- - for (const int &value : lessList) { + for (const double &value : lessList) { createRect(zchar, -value, currSize, xPos, yPos); yPos += currSize; } @@ -160,13 +160,13 @@ yPos = -(listSize * 25); //Align with the origin // E- - for (const int &value : greaterList) { + for (const double &value : greaterList) { createRect(echar, -value, currSize, xPos, yPos); yPos += currSize; } // E+ - for (const int &value : lessList) { + for (const double &value : lessList) { createRect(echar, value, currSize, xPos, yPos); yPos += currSize; } @@ -178,7 +178,7 @@ fitInView(sceneRect(), Qt::KeepAspectRatio); } -void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char &axis, int value) +void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char &axis, double value) { auto *lb = new QGraphicsSimpleTextItem(); lb->setBrush(palette().buttonText());