]> Shamusworld >> Repos - architektonas/blob - drawingview.h
e22634c00d936eda7afd7ad2a87752f611e8d5b0
[architektonas] / drawingview.h
1 #ifndef __DRAWINGVIEW_H__
2 #define __DRAWINGVIEW_H__
3
4 #include <QtWidgets>
5 #include <stdint.h>
6 #include "structs.h"
7
8 enum { ToolMouseDown, ToolMouseMove, ToolMouseUp, ToolKeyDown, ToolKeyUp, ToolCleanup };
9
10 class Painter;
11
12 class DrawingView: public QWidget
13 {
14         Q_OBJECT
15
16         public:
17                 DrawingView(QWidget * parent = NULL);
18
19         public:
20                 void SetGridSize(uint32_t);
21                 void UpdateGridBackground(void);
22                 Point SnapPointToGrid(Point);
23                 void RenderObjects(Painter *, std::vector<void *> &);
24                 void AddHoveredToSelection(void);
25                 void GetSelection(std::vector<void *> &);
26                 void GetHovered(std::vector<void *> &);
27                 void ToolHandler(int, Point);
28                 void ToolDraw(Painter *);
29                 void LineHandler(int, Point);
30                 void CircleHandler(int, Point);
31                 void ArcHandler(int, Point);
32                 void RotateHandler(int, Point);
33                 void CheckObjectBounds(void);
34                 bool HitTestObjects(Point);
35                 void HandleObjectMovement(Point);
36
37         public slots:
38                 void SetCurrentLayer(int);
39
40         protected:
41                 void paintEvent(QPaintEvent * event);
42                 void resizeEvent(QResizeEvent * event);
43                 void mousePressEvent(QMouseEvent * event);
44                 void mouseMoveEvent(QMouseEvent * event);
45                 void mouseReleaseEvent(QMouseEvent * event);
46                 void wheelEvent(QWheelEvent * event);
47                 void keyPressEvent(QKeyEvent * event);
48                 void keyReleaseEvent(QKeyEvent * event);
49
50         private:
51                 QPoint GetAdjustedMousePosition(QMouseEvent * event);
52                 QPoint GetAdjustedClientPosition(int x, int y);
53
54         public:
55                 bool useAntialiasing;
56                 uint32_t numSelected;
57                 uint32_t numHovered;
58                 bool shiftDown;
59                 bool ctrlDown;
60
61         private:
62                 QPixmap gridBackground;
63                 double scale;                                                   // Window scaling factor
64                 int32_t offsetX, offsetY;                               // Window offsets
65         public:
66                 Container document;
67                 uint32_t gridPixels;                                    // Grid size in pixels
68         private:
69                 bool collided;
70                 bool scrollDrag;
71                 Vector oldPoint;
72                 QString informativeText;
73
74         public:
75                 std::vector<void *> select;
76                 std::vector<void *> hover;
77                 std::vector<void *> toolObjects;
78                 std::vector<Object> toolScratch;
79                 Point toolPoint[32];
80
81 //      public:
82 //              static Container document;
83 };
84
85 #endif  // __DRAWINGVIEW_H__
86