-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShapeGraphicsItem.h
More file actions
62 lines (51 loc) · 2.11 KB
/
Copy pathShapeGraphicsItem.h
File metadata and controls
62 lines (51 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef SHAPEGRAPHICSITEM_H
#define SHAPEGRAPHICSITEM_H
#include <QGraphicsItem>
#include <QPainter>
class Shape;
class SelectionController;
class DocumentController;
class ShapeGraphicsItem : public QGraphicsItem
{
public:
explicit ShapeGraphicsItem(Shape *shape, QGraphicsItem *parent = nullptr);
~ShapeGraphicsItem() override;
Shape *modelShape() const { return m_shape; }
void setModelShape(Shape *shape);
void setSelectionController(SelectionController *ctrl) { m_selCtrl = ctrl; }
void setDocumentController(DocumentController *ctrl) { m_docCtrl = ctrl; }
DocumentController *documentController() const { return m_docCtrl; }
QRectF localBounds() const;
void updateFromModel();
QRectF boundingRect() const override;
QPainterPath shape() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget) override;
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override;
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) override;
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override;
private:
void drawRectShape(QPainter *painter);
void drawEllipseShape(QPainter *painter);
void drawPolygonShape(QPainter *painter);
void drawPolylineShape(QPainter *painter);
void drawTextShape(QPainter *painter);
void drawStarShape(QPainter *painter);
void drawArrowShape(QPainter *painter);
void drawSelectionOutline(QPainter *painter);
void drawHoverOutline(QPainter *painter);
Shape *m_shape = nullptr;
SelectionController *m_selCtrl = nullptr;
DocumentController *m_docCtrl = nullptr;
QPointF m_dragStartPos;
QPointF m_dragStartScenePos;
bool m_dragging = false;
bool m_selectionGuard = false;
bool m_hovered = false;
};
#endif // SHAPEGRAPHICSITEM_H