Skui 0.0.1
Build fast and easy to use control software with Skui.
 
Loading...
Searching...
No Matches
cable.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <QCursor>
4#include <QGraphicsObject>
5#include <QGraphicsScene>
6#include <QGraphicsSceneMouseEvent>
7#include <QGuiApplication>
8#include <QPainter>
9
10#include "pad.hpp"
11
18
20{
23 QPoint end_point;
24 // @TODO: Cable segments should also have a next and previous pointers and a mechansim for special
25 // cases like connection split or the end of a cable. This would make it easier to manage the segments and their connections.
26};
27
28class Cable : public QGraphicsObject
29{
30 Q_OBJECT
31
32public:
33 explicit Cable(QGraphicsItem *parent, const Pad *start_pad);
34
35 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override;
36 QRectF boundingRect() const override;
37
51 void setEditable(bool editable);
52
63 inline bool isEditable() const { return m_editable; }
64
65protected:
79 void previewCable(QPoint point);
80
88 void corner();
89
96 void endCorner(QPoint point);
97
98 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
99 void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override;
100 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
101 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
102
103private slots:
104 void updateStartCablePosition();
105 void updateEndCablePosition();
106
107private:
108 void updateBoundingRect(QRectF new_rect);
109 Pad *getPadAtScenePos(const QPointF &scene_pos) const;
110 void initiateConnection(Pad *end_pad);
111
112 QList<CableSegment> m_cable_segments;
113 const Pad *m_start_pad = nullptr;
114 Pad *m_end_pad = nullptr;
115 Pad *m_hovered_pad = nullptr;
116 bool m_editable = true;
117 bool m_first_scene = true;
118 // Do not access directly, use updateBoundingRect() to update repaint.
119 QRectF m_bounding_rect;
120};
DirectionalPlane
Definition cable.hpp:12
@ Vertical
Definition cable.hpp:12
@ Horizontal
Definition cable.hpp:12
DirectionalPlane & operator!(DirectionalPlane &plane)
Definition cable.hpp:13
bool isEditable() const
Returns whether the Cable is editable.
Definition cable.hpp:63
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
Definition cable.cpp:156
Cable(QGraphicsItem *parent, const Pad *start_pad)
Definition cable.cpp:4
void previewCable(QPoint point)
Previews the current position of the cable.
Definition cable.cpp:115
void endCorner(QPoint point)
For the last corner before ending the Cable.
Definition cable.cpp:150
void corner()
Locks a point as a new corner or moves the latest corner.
Definition cable.cpp:141
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
Definition cable.cpp:92
void setEditable(bool editable)
Sets whether the Cable is editable.
Definition cable.cpp:72
void mousePressEvent(QGraphicsSceneMouseEvent *event) override
Definition cable.cpp:235
QRectF boundingRect() const override
Definition cable.cpp:110
void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override
Definition cable.cpp:202
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override
Definition cable.cpp:225
Definition pad.hpp:18
Definition cable.hpp:20
QPoint end_point
Definition cable.hpp:23
QPoint start_point
Definition cable.hpp:22
DirectionalPlane plane
Definition cable.hpp:21