Changeset View
Changeset View
Standalone View
Standalone View
src/part/canvaselement.h
Show All 18 Lines | |||||
19 | /* | 19 | /* | ||
20 | * Canvas Subgraph (subgraph node view) | 20 | * Canvas Subgraph (subgraph node view) | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #ifndef CANVAS_ELEMENT_H | 23 | #ifndef CANVAS_ELEMENT_H | ||
24 | #define CANVAS_ELEMENT_H | 24 | #define CANVAS_ELEMENT_H | ||
25 | 25 | | |||
26 | #include <QAbstractGraphicsShapeItem> | 26 | #include <QAbstractGraphicsShapeItem> | ||
27 | #include <QPen> | | |||
28 | #include <QBrush> | 27 | #include <QBrush> | ||
28 | #include <QPen> | ||||
29 | 29 | | |||
30 | #include "dotgrammar.h" | 30 | #include "dotgrammar.h" | ||
31 | 31 | | |||
32 | class QMenu; | 32 | class QMenu; | ||
33 | class QGraphicsScene; | 33 | class QGraphicsScene; | ||
34 | 34 | | |||
35 | 35 | namespace KGraphViewer { | |||
36 | namespace KGraphViewer | | |||
37 | { | | |||
38 | class GraphElement; | 36 | class GraphElement; | ||
39 | class DotGraphView; | 37 | class DotGraphView; | ||
40 | 38 | | |||
41 | class CanvasElement: public QObject, public QAbstractGraphicsShapeItem | 39 | class CanvasElement : public QObject, public QAbstractGraphicsShapeItem { | ||
42 | { | | |||
43 | Q_OBJECT | 40 | Q_OBJECT | ||
44 | public: | 41 | public: | ||
45 | CanvasElement( | 42 | CanvasElement(DotGraphView *v, GraphElement *s, QGraphicsScene *c, | ||
46 | DotGraphView* v, | | |||
47 | GraphElement* s, | | |||
48 | QGraphicsScene* c, | | |||
49 | QGraphicsItem* parent = nullptr); | 43 | QGraphicsItem *parent = nullptr); | ||
50 | 44 | | |||
51 | ~CanvasElement() override; | 45 | ~CanvasElement() override; | ||
52 | 46 | | |||
53 | GraphElement* element() { return m_element; } | 47 | GraphElement *element() { return m_element; } | ||
54 | 48 | | |||
55 | void paint(QPainter* p, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override; | 49 | void paint(QPainter *p, const QStyleOptionGraphicsItem *option, | ||
50 | QWidget *widget = nullptr) override; | ||||
56 | 51 | | |||
57 | QRectF boundingRect() const override; | 52 | QRectF boundingRect() const override; | ||
58 | 53 | | |||
59 | void computeBoundingRect(); | 54 | void computeBoundingRect(); | ||
60 | 55 | | |||
61 | void initialize(qreal scaleX, qreal scaleY, | 56 | void initialize(qreal scaleX, qreal scaleY, qreal xMargin, qreal yMargin, | ||
62 | qreal xMargin, qreal yMargin, qreal gh); | 57 | qreal gh); | ||
63 | 58 | | |||
64 | inline void setGh(qreal gh) {m_gh = gh;} | 59 | inline void setGh(qreal gh) { m_gh = gh; } | ||
65 | 60 | | |||
66 | protected: | 61 | protected: | ||
67 | void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override; | 62 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override; | ||
68 | void mousePressEvent(QGraphicsSceneMouseEvent* event) override; | 63 | void mousePressEvent(QGraphicsSceneMouseEvent *event) override; | ||
69 | void mouseReleaseEvent(QGraphicsSceneMouseEvent* event) override; | 64 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; | ||
70 | void hoverEnterEvent(QGraphicsSceneHoverEvent* event) override; | 65 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override; | ||
71 | void hoverLeaveEvent(QGraphicsSceneHoverEvent* event) override; | 66 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override; | ||
72 | 67 | | |||
73 | qreal m_scaleX, m_scaleY; | 68 | qreal m_scaleX, m_scaleY; | ||
74 | qreal m_xMargin, m_yMargin, m_gh; | 69 | qreal m_xMargin, m_yMargin, m_gh; | ||
75 | GraphElement* m_element; | 70 | GraphElement *m_element; | ||
76 | DotGraphView* m_view; | 71 | DotGraphView *m_view; | ||
77 | QFont* m_font; | 72 | QFont *m_font; | ||
78 | QPen m_pen; | 73 | QPen m_pen; | ||
79 | QBrush m_brush; | 74 | QBrush m_brush; | ||
80 | QRectF m_boundingRect; | 75 | QRectF m_boundingRect; | ||
81 | QMenu* m_popup; | 76 | QMenu *m_popup; | ||
82 | 77 | | |||
83 | bool m_hovered; | 78 | bool m_hovered; | ||
84 | 79 | | |||
85 | quint32 m_lastRenderOpRev; | 80 | quint32 m_lastRenderOpRev; | ||
86 | typedef QHash<int, QPair<int, int> > FontSizeCache; | 81 | typedef QHash<int, QPair<int, int>> FontSizeCache; | ||
87 | FontSizeCache m_fontSizeCache; | 82 | FontSizeCache m_fontSizeCache; | ||
88 | Q_SIGNALS: | 83 | Q_SIGNALS: | ||
89 | void selected(CanvasElement*, Qt::KeyboardModifiers); | 84 | void selected(CanvasElement *, Qt::KeyboardModifiers); | ||
90 | void elementContextMenuEvent(const QString&, const QPoint&); | 85 | void elementContextMenuEvent(const QString &, const QPoint &); | ||
91 | void hoverEnter(CanvasElement*); | 86 | void hoverEnter(CanvasElement *); | ||
92 | void hoverLeave(CanvasElement*); | 87 | void hoverLeave(CanvasElement *); | ||
93 | 88 | | |||
94 | public Q_SLOTS: | 89 | public Q_SLOTS: | ||
95 | void modelChanged(); | 90 | void modelChanged(); | ||
96 | void slotRemoveElement(); | 91 | void slotRemoveElement(); | ||
97 | }; | 92 | }; | ||
98 | 93 | | |||
99 | } | 94 | } // namespace KGraphViewer | ||
100 | 95 | | |||
101 | #endif // CANVAS_ELEMENT_H | 96 | #endif // CANVAS_ELEMENT_H | ||
102 | | ||||
103 | | ||||
104 | |