]> Shamusworld >> Repos - architektonas/blob - src/drawingview.h
Added automagically resizing grid. :-D
[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                 void SetGridSize(uint32_t);
23                 void SetGridSize(double);
24                 void UpdateGridBackground(void);
25                 void UpdateGridBackgroundF(void);
26                 Point SnapPointToGrid(Point);
27                 Point SnapPointToAngle(Point);
28                 void RenderObjects(Painter *, VPVector &, int, bool ignoreLayer = false);
29                 void AddHoveredToSelection(void);
30                 VPVector GetSelection(void);
31                 VPVector GetHovered(void);
32                 void ToolHandler(int, Point);
33                 void ToolDraw(Painter *);
34                 void LineHandler(int, Point);
35                 void CircleHandler(int, Point);
36                 void ArcHandler(int, Point);
37                 void RotateHandler(int, Point);
38                 void MirrorHandler(int, Point);
39                 void DimensionHandler(int, Point);
40                 void TriangulateHandler(int, Point);
41                 void TrimHandler(int, Point);
42                 void ParallelHandler(int, Point);
43                 Rect GetObjectExtents(Object *);
44                 void CheckObjectBounds(void);
45                 bool HitTestObjects(Point);
46                 bool HitTest(Object *, Point);
47                 bool HandleObjectClicked(void);
48                 void HandleObjectMovement(Point);
49                 void AddDimensionTo(void * obj);
50
51         public slots:
52                 void DeleteCurrentLayer(int);
53                 void HandleLayerToggle(void);
54                 void HandleLayerSwap(int, int);
55                 void HandlePenWidth(float);
56                 void HandlePenStyle(int);
57                 void HandlePenColor(uint32_t);
58                 void HandlePenStamp(void);
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 paintEvent(QPaintEvent * event);
68                 void resizeEvent(QResizeEvent * event);
69                 void mousePressEvent(QMouseEvent * event);
70                 void mouseMoveEvent(QMouseEvent * event);
71                 void mouseReleaseEvent(QMouseEvent * event);
72                 void wheelEvent(QWheelEvent * event);
73                 void keyPressEvent(QKeyEvent * event);
74                 void keyReleaseEvent(QKeyEvent * event);
75
76         private:
77                 void DrawSubGrid(Painter *, uint32_t, double, Vector, Vector);
78                 QPoint GetAdjustedMousePosition(QMouseEvent * event);
79                 QPoint GetAdjustedClientPosition(int x, int y);
80
81         public:
82                 bool useAntialiasing;
83                 uint32_t numHovered;
84                 bool shiftDown;
85                 bool ctrlDown;
86                 bool altDown;
87
88         private:
89                 QPixmap gridBackground;
90                 double scale;                                                   // Window scaling factor
91                 int32_t offsetX, offsetY;                               // Window offsets
92         public:
93                 Container document;
94                 uint32_t gridPixels;                                    // Grid size in pixels
95                 double gridPixelsF;                                             // Grid size in pixels (float)
96 //      private:
97         public:
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                 Point toolPoint[32];
110                 Object * toolObj[32];
111                 Point intersectionPoint;
112                 Point hoverPoint;
113                 bool hoverPointValid;
114                 bool hoveringIntersection;
115                 Object * dragged;
116                 bool draggingObject;
117                 bool angleSnap;
118                 bool dirty;
119                 bool scrollWheelSeen;
120 };
121
122 #endif  // __DRAWINGVIEW_H__
123