Index: src/mainwindow.h =================================================================== --- src/mainwindow.h +++ src/mainwindow.h @@ -58,6 +58,7 @@ void checkPushedCommands(QByteArray bmsg); void handlePrinterStatusChanged(AtCore::STATES newState); void checkTemperature(uint sensorType, uint number, uint temp); + void axisControlClicked(QChar axis, int value); signals: void extruderCountChanged(int count); Index: src/mainwindow.cpp =================================================================== --- src/mainwindow.cpp +++ src/mainwindow.cpp @@ -95,6 +95,7 @@ connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &core, &AtCore::setFanSpeed); connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &core, &AtCore::setFlowRate); connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &core, &AtCore::setPrinterSpeed); + connect(ui->axisViewWidget, &AxisControl::clicked, this, &MainWindow::axisControlClicked); } @@ -295,3 +296,10 @@ msg.replace(_return, QStringLiteral("\\r")); logDialog->addSLog(msg); } + +void MainWindow::axisControlClicked(QChar axis, int value) +{ + core.setRelativePosition(); + core.pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1%2").arg(axis, QString::number(value)))); + core.setAbsolutePosition(); +} Index: src/mainwindow.ui =================================================================== --- src/mainwindow.ui +++ src/mainwindow.ui @@ -88,7 +88,7 @@ - + @@ -187,9 +187,9 @@ 1 - PrinterHotendPositionVisualController + AxisControl QGraphicsView -
widgets/printerhostpositionvisualcontroller.h
+
widgets/axiscontrol.h
BedExtruderWidget Index: src/widgets/CMakeLists.txt =================================================================== --- src/widgets/CMakeLists.txt +++ src/widgets/CMakeLists.txt @@ -1,6 +1,6 @@ set(widgets_SRCS gcodeeditorwidget.cpp - printerhostpositionvisualcontroller.cpp + axiscontrol.cpp bedextruderwidget.cpp plotwidget.cpp pushgcodewidget.cpp Index: src/widgets/axiscontrol.h =================================================================== --- src/widgets/axiscontrol.h +++ src/widgets/axiscontrol.h @@ -20,7 +20,6 @@ #include #include #include -#include /* Usage: * @@ -34,46 +33,50 @@ Q_OBJECT public: PieButton(QLatin1Char axis, int value, int size, int angle); + void setPalette(QPalette palette); protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *); + void hoverEnterEvent(QGraphicsSceneHoverEvent *); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *); signals: void clicked(QLatin1Char axis, int value); private: QLatin1Char _axis; int _value; + QPalette _palette; }; class RectButton : public QObject, public QGraphicsRectItem { Q_OBJECT public: RectButton(QLatin1Char axis, int value, int size); + void setPalette(QPalette palette); protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *); + void hoverEnterEvent(QGraphicsSceneHoverEvent *); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *); signals: void clicked(QLatin1Char axis, int value); private: QLatin1Char _axis; int _value; + QPalette _palette; }; -class PrinterHotendPositionVisualController : public QGraphicsView +class AxisControl : public QGraphicsView { Q_OBJECT public: - explicit PrinterHotendPositionVisualController(QWidget *parent = 0); + explicit AxisControl(QWidget *parent = nullptr); private: void setLabels(QGraphicsItem *item, QLatin1Char axis, int value); protected: - void resizeEvent(QResizeEvent *event); + void resizeEvent(QResizeEvent *); signals: void clicked(QLatin1Char axis, int value); Index: src/widgets/axiscontrol.cpp =================================================================== --- src/widgets/axiscontrol.cpp +++ src/widgets/axiscontrol.cpp @@ -15,65 +15,67 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "printerhostpositionvisualcontroller.h" -#include -#include +#include "axiscontrol.h" PieButton::PieButton(QLatin1Char axis, int value, int size, int angle) : _axis(axis), _value(value) { const int delta = 16; // Qt Docs: angle is 16th of a degree. - setBrush(QBrush(Qt::white)); + setBrush(_palette.button()); setStartAngle(angle * delta); setSpanAngle(90 * delta); setRect(QRect(QPoint(size * -1, size * -1), QPoint(size, size))); setZValue(size * -1); setAcceptHoverEvents(true); setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); } -void PieButton::mousePressEvent(QGraphicsSceneMouseEvent *event) +void PieButton::setPalette(QPalette palette) +{ + _palette = palette; +} + +void PieButton::mousePressEvent(QGraphicsSceneMouseEvent *) { - Q_UNUSED(event); emit clicked(_axis, _value); } -void PieButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +void PieButton::hoverEnterEvent(QGraphicsSceneHoverEvent *) { - Q_UNUSED(event); - setBrush(QBrush(QColor(Qt::white).dark(150))); + setBrush(_palette.highlight()); } -void PieButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +void PieButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { - Q_UNUSED(event); - setBrush(QBrush(QColor(Qt::white))); + setBrush(_palette.button()); } RectButton::RectButton(QLatin1Char axis, int value, int size) : _axis(axis), _value(value) { - setBrush(QBrush(Qt::white)); + setBrush(_palette.button()); setRect(QRect(QPoint(0, 0), QPoint(size, size))); setAcceptHoverEvents(true); setZValue(size * -1); setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); } -void RectButton::mousePressEvent(QGraphicsSceneMouseEvent *event) +void RectButton::setPalette(QPalette palette) +{ + _palette = palette; +} + +void RectButton::mousePressEvent(QGraphicsSceneMouseEvent *) { - Q_UNUSED(event); emit clicked(_axis, _value); } -void RectButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +void RectButton::hoverEnterEvent(QGraphicsSceneHoverEvent *) { - Q_UNUSED(event); - setBrush(QBrush(QColor(Qt::white).dark(150))); + setBrush(_palette.highlight()); } -void RectButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +void RectButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *) { - Q_UNUSED(event); - setBrush(QBrush(QColor(Qt::white))); + setBrush(_palette.button()); } /* About the Magic Numbers I don't have experience programming with QGraphicsScene, @@ -83,35 +85,37 @@ in the scene. If you have a better solution, please share with us. Lays Rodrigues - Jan/2017 */ -PrinterHotendPositionVisualController::PrinterHotendPositionVisualController(QWidget *parent) : +AxisControl::AxisControl(QWidget *parent) : QGraphicsView(parent) { setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); setScene(new QGraphicsScene()); auto createPie = [ = ](QLatin1Char axis, int value, int size, int angle) { auto pie = new PieButton(axis, value, size, angle); - connect(pie, &PieButton::clicked, this, &PrinterHotendPositionVisualController::clicked); - if (value == 1000 || value == -1000) { + pie->setPalette(this->palette()); + connect(pie, &PieButton::clicked, this, &AxisControl::clicked); + if (abs(value) == 25) { setLabels(pie, axis, value); } scene()->addItem(pie); }; auto createRect = [ = ](QLatin1Char axis, int 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, &PrinterHotendPositionVisualController::clicked); - if (value == 1000 || value == -1000) { + connect(z, &RectButton::clicked, this, &AxisControl::clicked); + if (abs(value) == 25) { setLabels(z, axis, value); } scene()->addItem(z); }; int currPieSize = 25; for (auto value : { - 10, 100, 1000 + 1, 10, 25 }) { createPie(QLatin1Char('X'), value, currPieSize, -45); // Left createPie(QLatin1Char('X'), value * -1, currPieSize, 135); // Right @@ -124,54 +128,53 @@ int xPos = sceneRect().width() - 50; int yPos = -75; //Align with the origin of the scene 3 * 25 for (auto value : { - 1000, 100, 10 - }) { - createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos); - yPos += currZSize; - } - for (auto value : { - -10, -100, -1000 + 25, 10, 1, -1, -10, -25 }) { createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos); yPos += currZSize; } setSceneRect(scene()->itemsBoundingRect()); } -void PrinterHotendPositionVisualController::resizeEvent(QResizeEvent *event) +void AxisControl::resizeEvent(QResizeEvent *) { - Q_UNUSED(event); fitInView(sceneRect(), Qt::KeepAspectRatio); } -void PrinterHotendPositionVisualController::setLabels(QGraphicsItem *item, QLatin1Char axis, int value) +void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char axis, int value) { auto *lb = new QGraphicsSimpleTextItem(); - lb->setText((value < 0) ? "-" + axis : QString(axis)); + lb->setBrush(palette().buttonText()); + + if (this->logicalDpiX() <= 96) { + lb->setText((value < 0) ? QStringLiteral(" -") + axis : QStringLiteral(" ") + axis); + } else { + lb->setText((value < 0) ? QStringLiteral("-") + axis : QStringLiteral(" ") + axis); + } - if (axis == 'X') { - lb->setY(item->y() - lb->boundingRect().width() / 2); + if (axis.toLatin1() == 'X') { + lb->setY(item->y() - lb->boundingRect().width()); if (value < 0) { lb->setX(item->x() - item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); } else { lb->setX(item->x() + item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); } - } else if (axis == 'Y') { + } else if (axis.toLatin1() == 'Y') { lb->setX(item->x() - lb->boundingRect().width() / 2); if (value < 0) { lb->setY(item->y() + item->boundingRect().height() / 1.5); } else { lb->setY(item->y() - item->boundingRect().height()); } } else { - if (value < 0) { - lb->setX(item->x() + lb->boundingRect().width() / 2); - lb->setY(item->y() + lb->boundingRect().height() / 2); - } else { - lb->setX(item->x() + lb->boundingRect().width() * 1.25); - lb->setY(item->y()); - } + lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); + +#ifndef Q_OS_WIN + lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); +#else + lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().height()); +#endif } scene()->addItem(lb); }