diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h
--- a/testclient/mainwindow.h
+++ b/testclient/mainwindow.h
@@ -64,7 +64,12 @@
private slots:
//ButtonEvents
-
+ /**
+ * @brief axisControlClicked Used to catch the axis control.
+ * @param axis The Axis clicked on (X |Y |Z)
+ * @param value Distance Value
+ */
+ void axisControlClicked(QChar axis, int value);
/**
* @brief the printing progress has changed
* @param progress: the new progress
diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp
--- a/testclient/mainwindow.cpp
+++ b/testclient/mainwindow.cpp
@@ -29,6 +29,7 @@
#include "mainwindow.h"
#include "seriallayer.h"
#include "gcodecommands.h"
+#include "widgets/printerhostpositionvisualcontroller.h"
Q_LOGGING_CATEGORY(TESTCLIENT_MAINWINDOW, "org.kde.atelier.core");
@@ -50,6 +51,9 @@
ui->pluginCB->addItem(tr("Autodetect"));
ui->pluginCB->addItems(core->availablePlugins());
+ PrinterHotendPositionVisualController *AxisControl = new PrinterHotendPositionVisualController;
+ ui->dockWidgetContents_5->layout()->addWidget(AxisControl);
+
addLog(tr("Attempting to locate Serial Ports"));
populateCBs();
@@ -81,13 +85,13 @@
connect(ui->printPB, &QPushButton::clicked, this, &MainWindow::printPBClicked);
connect(ui->printerSpeedPB, &QPushButton::clicked, this, &MainWindow::printerSpeedPBClicked);
connect(ui->flowRatePB, &QPushButton::clicked, this, &MainWindow::flowRatePBClicked);
- connect(ui->absoluteRB, &QRadioButton::toggled, this, &MainWindow::movementModeChanged);
connect(ui->showMessagePB, &QPushButton::clicked, this, &MainWindow::showMessage);
connect(ui->pluginCB, &QComboBox::currentTextChanged, this, &MainWindow::pluginCBChanged);
connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged);
connect(this, &MainWindow::printFile, core, &AtCore::print);
connect(ui->stopPB, &QPushButton::clicked, core, &AtCore::stop);
connect(ui->emergencyStopPB, &QPushButton::clicked, core, &AtCore::emergencyStop);
+ connect(AxisControl, &PrinterHotendPositionVisualController::clicked, this, &MainWindow::axisControlClicked);
//We love solid, but we need a release :/
QTimer *timer = new QTimer();
@@ -568,4 +572,9 @@
ui->printDock->setTitleBarWidget(new QWidget());
}
}
-
+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();
+}
diff --git a/testclient/mainwindow.ui b/testclient/mainwindow.ui
--- a/testclient/mainwindow.ui
+++ b/testclient/mainwindow.ui
@@ -744,34 +744,6 @@
- -
-
-
-
-
-
- Axis move
-
-
-
- -
-
-
- Absol&ute
-
-
- true
-
-
-
- -
-
-
- Relati&ve
-
-
-
-
-
diff --git a/testclient/widgets/CMakeLists.txt b/testclient/widgets/CMakeLists.txt
--- a/testclient/widgets/CMakeLists.txt
+++ b/testclient/widgets/CMakeLists.txt
@@ -1,5 +1,6 @@
set(widgets_SRCS
plotwidget.cpp
+ printerhostpositionvisualcontroller.cpp
)
add_library(AtCoreTestWidgets STATIC ${widgets_SRCS})
diff --git a/testclient/widgets/printerhostpositionvisualcontroller.h b/testclient/widgets/printerhostpositionvisualcontroller.h
new file mode 100644
--- /dev/null
+++ b/testclient/widgets/printerhostpositionvisualcontroller.h
@@ -0,0 +1,81 @@
+/* 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
+#include
+
+/* Usage:
+ *
+ * Create a instance of PrinterHotendPositionVisualController and
+ * connect the clicked signal, it will give you the axis and value
+ * that was clicked.
+ */
+
+class PieButton : public QObject, public QGraphicsEllipseItem
+{
+ Q_OBJECT
+public:
+ PieButton(QLatin1Char axis, int value, int size, int angle);
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+signals:
+ void clicked(QLatin1Char axis, int value);
+private:
+ QLatin1Char _axis;
+ int _value;
+};
+
+class RectButton : public QObject, public QGraphicsRectItem
+{
+ Q_OBJECT
+
+public:
+ RectButton(QLatin1Char axis, int value, int size);
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
+signals:
+ void clicked(QLatin1Char axis, int value);
+private:
+ QLatin1Char _axis;
+ int _value;
+};
+
+class PrinterHotendPositionVisualController : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ explicit PrinterHotendPositionVisualController(QWidget *parent = 0);
+
+private:
+ void setLabels(QGraphicsItem *item, QLatin1Char axis, int value);
+
+protected:
+ void resizeEvent(QResizeEvent *event);
+
+signals:
+ void clicked(QLatin1Char axis, int value);
+
+};
diff --git a/testclient/widgets/printerhostpositionvisualcontroller.cpp b/testclient/widgets/printerhostpositionvisualcontroller.cpp
new file mode 100644
--- /dev/null
+++ b/testclient/widgets/printerhostpositionvisualcontroller.cpp
@@ -0,0 +1,177 @@
+/* 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 "printerhostpositionvisualcontroller.h"
+#include
+#include
+
+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));
+ 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)
+{
+ Q_UNUSED(event);
+ emit clicked(_axis, _value);
+}
+
+void PieButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+ setBrush(QBrush(QColor(Qt::white).dark(150)));
+}
+
+void PieButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+ setBrush(QBrush(QColor(Qt::white)));
+}
+
+RectButton::RectButton(QLatin1Char axis, int value, int size) : _axis(axis), _value(value)
+{
+ setBrush(QBrush(Qt::white));
+ 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)
+{
+ Q_UNUSED(event);
+ emit clicked(_axis, _value);
+}
+
+void RectButton::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+ setBrush(QBrush(QColor(Qt::white).dark(150)));
+}
+
+void RectButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+ setBrush(QBrush(QColor(Qt::white)));
+}
+/* About the Magic Numbers
+ I don't have experience programming with QGraphicsScene,
+ Tomaz is helping me, but until we have a better solution, all the values
+ that are dividing or multiplying the items is based only in tests and errors.
+ Those values was choosen because it fit better on the alignment of the items
+ in the scene. If you have a better solution, please share with us.
+ Lays Rodrigues - Jan/2017
+*/
+PrinterHotendPositionVisualController::PrinterHotendPositionVisualController(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 == 25 || 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->setPos(xPos, yPos);
+ connect(z, &RectButton::clicked, this, &PrinterHotendPositionVisualController::clicked);
+ if (value == 25 || value == -25) {
+ setLabels(z, axis, value);
+ }
+ scene()->addItem(z);
+ };
+
+ int currPieSize = 25;
+ for (auto value : {
+ 1, 10, 25
+ }) {
+ createPie(QLatin1Char('X'), value, currPieSize, -45); // Left
+ createPie(QLatin1Char('X'), value * -1, currPieSize, 135); // Right
+ createPie(QLatin1Char('Y'), value, currPieSize, 45); // Top
+ createPie(QLatin1Char('Y'), value * -1, currPieSize, 225); // Bottom
+ currPieSize += 25;
+ }
+
+ int currZSize = 25;
+ int xPos = sceneRect().width() - 50;
+ int yPos = -75; //Align with the origin of the scene 3 * 25
+ for (auto value : {
+ 25, 10, 1
+ }) {
+ createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos);
+ yPos += currZSize;
+ }
+ for (auto value : {
+ -1, -10, -25
+ }) {
+ createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos);
+ yPos += currZSize;
+ }
+ setSceneRect(scene()->itemsBoundingRect());
+}
+
+void PrinterHotendPositionVisualController::resizeEvent(QResizeEvent *event)
+{
+ Q_UNUSED(event);
+ fitInView(sceneRect(), Qt::KeepAspectRatio);
+}
+
+void PrinterHotendPositionVisualController::setLabels(QGraphicsItem *item, QLatin1Char axis, int value)
+{
+ auto *lb = new QGraphicsSimpleTextItem();
+ lb->setText((value < 0) ? QStringLiteral("-") + axis : QString(axis));
+
+ if (axis.toLatin1() == 'X') {
+ lb->setY(item->y() - lb->boundingRect().width() / 2);
+ 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.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() / 6);
+ lb->setY(item->y() - lb->boundingRect().height() / 6);
+ } else {
+ lb->setX(item->x() + lb->boundingRect().width() / 6);
+ lb->setY(item->y() - lb->boundingRect().height() / 6);
+ }
+ }
+ scene()->addItem(lb);
+}