]> Shamusworld >> Repos - guemap/blob - src/mapview.h
Initial commit of GUEmap v3.
[guemap] / src / mapview.h
1 //
2 // GUEmap
3 // (C) 1997-2007 Christopher J. Madsen
4 // (C) 2019 James Hammons
5 //
6 // GUEmap is licensed under either version 2 of the GPL, or (at your option)
7 // any later version.  See LICENSE file for details.
8 //
9 // mapview.h: Interface of the MapView class
10 //
11
12 #ifndef __MAPVIEW_H__
13 #define __MAPVIEW_H__
14
15 #include <QtWidgets>
16 #include "globals.h"
17
18 class MapDoc;
19
20 enum GmOp
21 {
22         gmoNone, gmoAddEdge, gmoChangeEdge, gmoSelectBox,       gmoDeleting, gmoAddCorner,
23         gmoControlDown, gmoShiftDown,
24         gmoShiftDragUp, gmoShiftDragDown, gmoShiftDragLeft, gmoShiftDragRight,
25         gmoControlDrag,
26         gmoDrag = gmoShiftDragUp      // Drag operations must come last
27 };
28
29 enum EditPropUndo
30 {
31         epuRoomInfo, epuAddRoom, epuAddRoomEdge, epuMapInfo
32 };
33
34
35 class MapView: public QWidget
36 {
37         Q_OBJECT
38
39         public:
40                 QMenu * roomContextMenu;
41                 QMenu * mapContextMenu;
42
43                 QAction * deleteRoomAct;
44                 QAction * roomPropertiesAct;
45                 QAction * mapPropertiesAct;
46                 QAction * selectConnectedAct;
47                 QAction * addCornerAct;
48                 QAction * addRoomAct;
49                 QAction * addPageAct;
50                 QAction * addUnexploredAct;
51                 QAction * addLoopBackAct;
52                 QAction * addNoExitAct;
53                 QAction * addUpAct;
54                 QAction * addDownAct;
55                 QAction * addInAct;
56                 QAction * addOutAct;
57                 QAction * addOneWayAct;
58                 QAction * clearOneWayAct;
59                 QAction * addRestrictedAct;
60                 QAction * clearRestrictedAct;
61
62         public:
63                 GmOp    opInProgress;
64                 bool    bTmp;
65                 bool    b2Tmp;
66                 MapEdge edgeTmp;
67                 MapEdge e2Tmp;
68                 int     iTmp;
69                 QPoint  p1Tmp;
70                 QPoint  p2Tmp;
71                 QPoint  mouse;
72                 QRect   rTmp;
73                 int hoveredEdge;
74                 RoomCorner cornerClicked;
75                 int roomClicked;
76
77                 QPoint scrollDragStart;
78                 QPoint offsetScrollDragStart;
79                 unsigned int scrollDragTimer;
80                 bool scrollDrag;
81
82                 QFont font;
83                 bool showCorners;
84                 bool showGrid;
85                 bool showPages;
86
87                 int numSelected;
88                 int numSelectedPages;
89                 int selectedOne;
90                 ByteVec selected;
91                 ByteVec selectedPage;
92
93                 short printingPage;
94                 double zoom;
95                 MapDoc * doc;
96
97                 bool shiftDown, ctrlDown, altDown;
98                 bool mouseDown;
99
100                 // From scrollzoom.h
101                 QPoint offset;
102
103         public:
104                 MapView(QWidget * parent = NULL);
105                 virtual ~MapView();
106
107         public:
108                 void DrawArrowhead(QPainter *, QPointF, QPointF);
109                 void DrawNoExit(QPainter *, QPointF, QPointF);
110                 void clearSelection(bool update = true);
111                 void deleteSelection(bool removeCorner = true);
112                 void deselectPage(int n, bool update = true);
113                 void deselectPages(bool update = true);
114                 void deselectRoom(RoomNum n, bool update = true);
115                 void selectDone();
116                 void selectPage(int n, bool update = true);
117                 void selectRoom(RoomNum n, bool update = true);
118                 void selectOnlyRoom(RoomNum n);
119                 void makeRoomVisible(RoomNum n);
120                 void navigate(RoomCorner corner, bool toggleStubs = false);
121                 void setRoomNote(const char * comment);
122                 int FindHoveredEdge(void);
123
124         protected:
125                 void paintEvent(QPaintEvent *);
126                 void keyPressEvent(QKeyEvent *);
127                 void keyReleaseEvent(QKeyEvent *);
128                 void mouseDoubleClickEvent(QMouseEvent *);
129                 void mousePressEvent(QMouseEvent *);
130                 void mouseMoveEvent(QMouseEvent *);
131                 void mouseReleaseEvent(QMouseEvent *);
132 #if 0
133         // ClassWizard generated virtual function overrides
134         //{{AFX_VIRTUAL(CMapView)
135                 virtual void OnInitialUpdate();
136                 virtual void OnPrepareDC(QPainter * pDC, CPrintInfo * pInfo = NULL);
137                 protected:
138                 virtual bool OnPreparePrinting(CPrintInfo * pInfo);
139                 virtual bool PreCreateWindow(CREATESTRUCT & cs);
140                 virtual void OnActivateView(bool bActivate, CView * pActivateView, CView * pDeactiveView);
141                 virtual void OnBeginPrinting(QPainter * pDC, CPrintInfo * pInfo);
142                 virtual void OnEndPrinting(QPainter * pDC, CPrintInfo * pInfo);
143                 virtual void OnUpdate(CView * pSender, LPARAM lHint, CObject * pHint);
144 #endif
145         //}}AFX_VIRTUAL
146
147         private slots:
148                 void HandleAddCorner(void);
149                 void HandleAddUnexplored(void);
150                 void HandleAddLoopBack(void);
151                 void HandleAddNoExit(void);
152                 void SetEdgeDirection(EdgeType);
153                 void HandleAddUp(void);
154                 void HandleAddDown(void);
155                 void HandleAddIn(void);
156                 void HandleAddOut(void);
157                 void HandleAddRoom(void);
158                 void SetEdges(int, int, EdgeType);
159                 void ClearEdges(int, int, EdgeType);
160                 void HandleAddOneWay(void);
161                 void HandleClearOneWay(void);
162                 void HandleAddRestricted(void);
163                 void HandleClearRestricted(void);
164                 void HandleRoomProperties(void);
165                 void HandleMapProperties(void);
166                 void HandleDelete(void);
167
168         signals:
169                 void RoomClicked(MapDoc *, int);
170
171         protected:
172                 void addRoom(QPoint & point);
173                 void adjustOffset(QPoint & p) const;
174                 void computeSelectedRect(QRect & r) const;
175
176 //              void drawBackground(QPainter * dc);
177 //              void drawSelected(QPainter * dc);
178
179                 void editProperties(EditPropUndo undoType, bool wasModified = false, EdgeVec * edges = NULL);
180
181                 bool pasteClipboard(const string & text);
182
183                 void getNavText(char & initial, RoomCorner & dir1, char & separator, RoomCorner & dir2, bool mustBeMove = false);
184                 void setEdgeType(MapEdge & e);
185                 void setNavText(char c);
186
187                 void setScrollBars();
188                 void zoomTo(short newZoom);
189
190 #if 0
191         // Generated message map functions
192         protected:
193                 //{{AFX_MSG(CMapView)
194                 void OnEditProperties(unsigned int cmd);
195                 bool OnMouseWheel(unsigned int nFlags, short zDelta, CPoint pt);
196                 void OnChar(unsigned int nChar, unsigned int nRepCnt, unsigned int nFlags);
197 //              void OnEditAddCorner();
198                 void OnEditAddPage();
199 //              void OnEditAddRoom();
200 //              void OnEditClear();
201                 void OnEditCopy();
202                 void OnEditCut();
203                 void OnEditPaginate();
204                 void OnEditPaste();
205 //              void OnEditSelectAll();
206                 void OnEditSelectConnected();
207                 void OnKeyDown(unsigned int nChar, unsigned int nRepCnt, unsigned int nFlags);
208 //              void OnLButtonDblClk(unsigned int nFlags, CPoint point);
209 //              void OnLButtonDown(unsigned int nFlags, CPoint point);
210 //              void OnLButtonUp(unsigned int nFlags, CPoint point);
211 //              void OnMouseMove(unsigned int nFlags, CPoint point);
212 //              void OnRButtonDown(unsigned int nFlags, CPoint point);
213 //              void OnRButtonUp(unsigned int nFlags, CPoint point);
214                 void OnSize(unsigned int nType, int cx, int cy);
215                 void OnTimer(unsigned int nIDEvent);
216                 void OnUpdateEditAddCorner(CCmdUI * pCmdUI);
217                 void OnUpdateEditPaste(CCmdUI * pCmdUI);
218                 void OnUpdateSelectedUnlocked(CCmdUI * pCmdUI);
219                 void OnUpdateUnlocked(CCmdUI * pCmdUI);
220                 void OnUpdateViewGrid(CCmdUI * pCmdUI);
221                 void OnViewGrid();
222                 void OnWindowRefresh();
223                 int OnMouseActivate(CWnd *, unsigned int, unsigned int);
224                 void OnNavGo();
225                 void OnNavGoDir(unsigned int cmd);
226                 void OnUpdateViewZoom(CCmdUI * pCmdUI);
227                 void OnViewZoom(unsigned int cmd);
228                 //}}AFX_MSG
229 #endif
230 };
231
232 #endif  // __MAPVIEW_H__
233