[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [atelier] src/widgets: First version of the PrinterHostPositionVisualController
From:       Tomaz Canabrava <tcanabrava () kde ! org>
Date:       2016-11-25 10:51:43
Message-ID: E1cAE6Z-0005RP-Io () code ! kde ! org
[Download RAW message or body]

Git commit b075d4a7483dddbaa8271f4f52356b37e304e8c4 by Tomaz Canabrava.
Committed on 24/11/2016 at 18:47.
Pushed by tcanabrava into branch 'master'.

First version of the PrinterHostPositionVisualController

Summary:
create an instance of that class, connect to the clicked method
Profit.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>

Differential Revision: https://phabricator.kde.org/D3490

M  +1    -0    src/widgets/CMakeLists.txt
A  +62   -0    src/widgets/printerhostpositionvisualcontroller.cpp     [License: \
UNKNOWN]  * A  +42   -0    src/widgets/printerhostpositionvisualcontroller.h     \
[License: UNKNOWN]  *

The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.


https://commits.kde.org/atelier/b075d4a7483dddbaa8271f4f52356b37e304e8c4

diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt
index 345e575..6f43248 100644
--- a/src/widgets/CMakeLists.txt
+++ b/src/widgets/CMakeLists.txt
@@ -2,6 +2,7 @@ set(widgets_SRCS
     toolbarwidget.cpp
     gcodeeditorwidget.cpp
     temporaryprintercontrolwidget.cpp
+    printerhostpositionvisualcontroller.cpp
     )
 
 add_library(AtelierWidgets STATIC ${widgets_SRCS})
diff --git a/src/widgets/printerhostpositionvisualcontroller.cpp \
b/src/widgets/printerhostpositionvisualcontroller.cpp new file mode 100644
index 0000000..f5794da
--- /dev/null
+++ b/src/widgets/printerhostpositionvisualcontroller.cpp
@@ -0,0 +1,62 @@
+#include "printerhostpositionvisualcontroller.h"
+#include <QDebug>
+#include <QResizeEvent>
+
+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)));
+}
+
+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);
+        scene()->addItem(pie);
+        connect(pie, &PieButton::clicked, this, \
&PrinterHotendPositionVisualController::clicked); +    };
+
+    int currPieSize = 25;
+    for(auto value : {1, 10, 100, 1000}) {
+        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;
+    }
+    setSceneRect(scene()->itemsBoundingRect());
+}
+
+void PrinterHotendPositionVisualController::resizeEvent(QResizeEvent *event)
+{
+    Q_UNUSED(event);
+    fitInView(sceneRect(), Qt::KeepAspectRatio);
+}
diff --git a/src/widgets/printerhostpositionvisualcontroller.h \
b/src/widgets/printerhostpositionvisualcontroller.h new file mode 100644
index 0000000..a4a5acb
--- /dev/null
+++ b/src/widgets/printerhostpositionvisualcontroller.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <QObject>
+#include <QGraphicsView>
+#include <QGraphicsEllipseItem>
+
+/* 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 PrinterHotendPositionVisualController : public QGraphicsView
+{
+    Q_OBJECT
+
+public:
+    explicit PrinterHotendPositionVisualController(QWidget *parent = 0);
+
+protected:
+    void resizeEvent(QResizeEvent *event);
+
+signals:
+    void clicked(QLatin1Char axis, int value);
+
+};


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic