-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanvasView.h
More file actions
86 lines (67 loc) · 2.44 KB
/
Copy pathCanvasView.h
File metadata and controls
86 lines (67 loc) · 2.44 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef CANVASVIEW_H
#define CANVASVIEW_H
#include <QGraphicsView>
#include <QPointF>
class QRubberBand;
class QGraphicsLineItem;
class DocumentController;
class SelectionController;
enum class CanvasTool {
Select,
Line,
Text,
};
class CanvasView : public QGraphicsView
{
Q_OBJECT
public:
explicit CanvasView(QGraphicsScene *scene, QWidget *parent = nullptr);
~CanvasView() override;
void setDocumentController(DocumentController *ctrl) { m_docCtrl = ctrl; }
void setSelectionController(SelectionController *ctrl) { m_selCtrl = ctrl; }
void setActiveTool(CanvasTool tool);
CanvasTool activeTool() const { return m_activeTool; }
void zoomIn();
void zoomOut();
void fitAll();
/// Fit workspace with a readable default zoom (60%–100%).
void fitWorkspaceDefault();
void setGridVisible(bool visible);
bool isGridVisible() const { return m_gridVisible; }
double zoomLevel() const { return m_zoomLevel; }
void cancelActiveOperation();
signals:
void mouseScenePosChanged(const QPointF &pos);
void zoomLevelChanged(double level);
protected:
void wheelEvent(QWheelEvent *event) override;
void drawBackground(QPainter *painter, const QRectF &rect) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
void notifyZoomChanged();
/// True when view pos hits a shape or its resize/rotate handle (must not start box-select).
bool hitInteractiveAt(const QPoint &viewPos) const;
void beginRubberBand(const QPoint &pos);
void updateRubberBand(const QPoint &pos);
void finishRubberBand(const QPoint &pos, Qt::KeyboardModifiers mods);
void beginLineDrag(const QPointF &scenePos);
void updateLinePreview(const QPointF &scenePos);
void finishLineDrag(const QPointF &scenePos);
void placeTextAt(const QPointF &scenePos);
double m_zoomLevel = 1.0;
bool m_gridVisible = true;
double m_gridSize = 20.0;
CanvasTool m_activeTool = CanvasTool::Select;
DocumentController *m_docCtrl = nullptr;
SelectionController *m_selCtrl = nullptr;
QRubberBand *m_rubberBand = nullptr;
QPoint m_rubberOrigin;
bool m_rubberActive = false;
bool m_lineDragging = false;
QPointF m_lineStartScene;
QGraphicsLineItem *m_linePreview = nullptr;
};
#endif // CANVASVIEW_H