]> Shamusworld >> Repos - architektonas/blob - src/drawingview.h
136380c127960ae21fa626e04cc8a7beebf61e18
[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 AddHoveredToSelection(void);
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 HandlePenWidth(float);
55                 void HandlePenStyle(int);
56                 void HandlePenColor(uint32_t);
57                 void HandlePenStamp(QAction *);
58                 void HandlePenDropper(QAction *);
59
60         signals:
61                 void ObjectHovered(Object *);
62                 void ObjectSelected(Object *);
63                 void NeedZoomUpdate(void);
64
65         protected:
66                 void focusOutEvent(QFocusEvent * event);
67                 void focusInEvent(QFocusEvent * event);
68                 void paintEvent(QPaintEvent * event);
69                 void resizeEvent(QResizeEvent * event);
70                 void mousePressEvent(QMouseEvent * event);
71                 void mouseMoveEvent(QMouseEvent * event);
72                 void mouseReleaseEvent(QMouseEvent * event);
73                 void wheelEvent(QWheelEvent * event);
74                 void keyPressEvent(QKeyEvent * event);
75                 void keyReleaseEvent(QKeyEvent * event);
76
77         private:
78                 void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
79                 QPoint GetAdjustedMousePosition(QMouseEvent * event);
80                 QPoint GetAdjustedClientPosition(int x, int y);
81
82         public:
83                 bool useAntialiasing;
84                 uint32_t numHovered;
85                 bool shiftDown;
86                 bool ctrlDown;
87                 bool altDown;
88
89         private:
90                 QPixmap gridBackground;
91                 double scale;                                                   // Window scaling factor
92                 int32_t offsetX, offsetY;                               // Window offsets
93                 bool supressSelected;
94                 QCursor curMarker;
95                 QCursor curDropper;
96         public:
97                 Container document;
98                 uint32_t gridPixels;                                    // Grid size in pixels
99                 double gridPixelsF;                                             // Grid size in pixels (float)
100 //      private:
101         public:
102                 bool collided;
103                 bool scrollDrag;
104                 Vector oldPoint;
105                 Vector oldScrollPoint;
106                 QString informativeText;
107
108         public:
109                 VPVector select;
110                 VPVector toolObjects;
111                 std::vector<Object> toolScratch;
112                 VPVector toolScratch2;
113                 Point toolPoint[32];
114                 Object * toolObj[32];
115                 double toolParam[32];
116                 Point intersectionPoint;
117                 Point hoverPoint;
118                 bool hoverPointValid;
119                 bool hoveringIntersection;
120                 Object * dragged;
121                 bool draggingObject;
122                 bool angleSnap;
123                 bool dirty;
124                 bool scrollWheelSeen;
125 };
126
127 #endif  // __DRAWINGVIEW_H__