]> Shamusworld >> Repos - architektonas/blob - src/drawingview.h
5906766d35b6bd459e0c2ccf9cdca55405a2f60a
[architektonas] / src / drawingview.h
1 #ifndef __DRAWINGVIEW_H__
2 #define __DRAWINGVIEW_H__
3
4 #include <QtWidgets>
5 #include <stdint.h>
6 #include "rect.h"
7 #include "structs.h"
8
9 enum { ToolMouseDown, ToolMouseMove, ToolMouseUp, ToolKeyDown, ToolKeyUp, ToolCleanup };
10
11 class Painter;
12
13 class DrawingView: public QWidget
14 {
15         Q_OBJECT
16
17         public:
18                 DrawingView(QWidget * parent = NULL);
19
20         public:
21                 void DrawBackground(Painter *);
22                 Point SnapPointToGrid(Point);
23                 Point SnapPointToAngle(Point);
24                 void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
25                 void HandleSelectionClick(VPVector &);
26                 VPVector GetSelection(void);
27                 VPVector GetHovered(bool exclude = false);
28                 void MoveSelectedToLayer(int);
29                 void ToolHandler(int, Point);
30                 void ToolDraw(Painter *);
31                 void LineHandler(int, Point);
32                 void CircleHandler(int, Point);
33                 void ArcHandler(int, Point);
34                 void RotateHandler(int, Point);
35                 void MirrorHandler(int, Point);
36                 void DimensionHandler(int, Point);
37                 void DeleteHandler(int, Point);
38                 void TriangulateHandler(int, Point);
39                 void TrimHandler(int, Point);
40                 void ParallelHandler(int, Point);
41                 Rect GetObjectExtents(Object *);
42                 void CheckObjectBounds(void);
43                 bool HitTestObjects(Point);
44                 bool HitTest(Object *, Point);
45                 bool HandleObjectClicked(void);
46                 void HandleObjectMovement(Point);
47                 void AddDimensionTo(void * obj);
48
49         public slots:
50                 void DeleteCurrentLayer(int);
51                 void HandleLayerToggle(void);
52                 void HandleLayerSwap(int, int);
53                 void HandleLayerSwap(int, int, VPVector &);
54                 void HandlePenStamp(QAction *);
55                 void HandlePenDropper(QAction *);
56
57         signals:
58                 void ObjectHovered(Object *);
59                 void ObjectSelected(Object *);
60                 void NeedZoomUpdate(void);
61
62         protected:
63                 void focusOutEvent(QFocusEvent * event);
64                 void focusInEvent(QFocusEvent * event);
65                 void paintEvent(QPaintEvent * event);
66                 void resizeEvent(QResizeEvent * event);
67                 void mousePressEvent(QMouseEvent * event);
68                 void mouseMoveEvent(QMouseEvent * event);
69                 void mouseReleaseEvent(QMouseEvent * event);
70                 void wheelEvent(QWheelEvent * event);
71                 void keyPressEvent(QKeyEvent * event);
72                 void keyReleaseEvent(QKeyEvent * event);
73
74         private:
75                 void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
76                 QPoint GetAdjustedMousePosition(QMouseEvent * event);
77                 QPoint GetAdjustedClientPosition(int x, int y);
78
79         public:
80                 bool useAntialiasing;
81                 uint32_t numHovered;
82                 bool shiftDown;
83                 bool ctrlDown;
84                 bool altDown;
85
86         private:
87                 QPixmap gridBackground;
88                 double scale;                                                   // Window scaling factor
89                 int32_t offsetX, offsetY;                               // Window offsets
90                 bool supressSelected;
91                 QCursor curMarker;
92                 QCursor curDropper;
93                 uint32_t currentSelect;
94         public:
95                 Container document;
96                 uint32_t gridPixels;                                    // Grid size in pixels
97                 double gridPixelsF;                                             // Grid size in pixels (float)
98                 bool collided;
99                 bool scrollDrag;
100                 Vector oldPoint;
101                 Vector oldScrollPoint;
102                 QString informativeText;
103
104         public:
105                 VPVector select;
106                 VPVector toolObjects;
107                 std::vector<Object> toolScratch;
108                 VPVector toolScratch2;
109                 VPVector oldHover;
110                 Point toolPoint[32];
111                 Object * toolObj[32];
112                 double toolParam[32];
113                 Point intersectionPoint;
114                 Point hoverPoint;
115                 bool hoverPointValid;
116                 bool hoveringIntersection;
117                 Object * dragged;
118                 bool draggingObject;
119                 bool angleSnap;
120                 bool dirty;
121                 bool scrollWheelSeen;
122 };
123
124 #endif  // __DRAWINGVIEW_H__