|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013, 2014 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #pragma once |
|
20 #include "../main.h" |
|
21 |
|
22 class QPainter; |
|
23 class GLRenderer; |
|
24 class QMouseEvent; |
|
25 |
|
26 enum class EditModeType |
|
27 { |
|
28 Select, |
|
29 Draw, |
|
30 Circle, |
|
31 MagicWand, |
|
32 }; |
|
33 |
|
34 class AbstractEditMode |
|
35 { |
|
36 GLRenderer* _renderer; |
|
37 |
|
38 public: |
|
39 struct MouseEventData |
|
40 { |
|
41 QMouseEvent* ev; |
|
42 Qt::KeyboardModifiers keymods; |
|
43 bool mouseMoved; |
|
44 Qt::MouseButtons releasedButtons; |
|
45 }; |
|
46 |
|
47 AbstractEditMode (GLRenderer* renderer); |
|
48 virtual ~AbstractEditMode(); |
|
49 |
|
50 virtual bool allowFreeCamera() const = 0; |
|
51 virtual void render (QPainter&) const {}; |
|
52 GLRenderer* renderer() const; |
|
53 virtual EditModeType type() const = 0; |
|
54 virtual bool mousePressed (QMouseEvent*) { return false; } |
|
55 virtual bool mouseReleased (MouseEventData const&) { return false; } |
|
56 virtual bool mouseDoubleClicked (QMouseEvent*) { return false; } |
|
57 virtual bool mouseMoved (QMouseEvent*) { return false; } |
|
58 |
|
59 static AbstractEditMode* createByType (GLRenderer* renderer, EditModeType type); |
|
60 }; |
|
61 |
|
62 // |
|
63 // Base class for draw-like edit modes |
|
64 // |
|
65 class AbstractDrawMode : public AbstractEditMode |
|
66 { |
|
67 DEFINE_CLASS (AbstractDrawMode, AbstractEditMode) |
|
68 |
|
69 protected: |
|
70 QList<Vertex> _drawedVerts; |
|
71 Vertex _rectverts[4]; |
|
72 QBrush _polybrush; |
|
73 |
|
74 public: |
|
75 AbstractDrawMode (GLRenderer* renderer); |
|
76 |
|
77 virtual bool allowFreeCamera() const override |
|
78 { |
|
79 return false; |
|
80 } |
|
81 |
|
82 bool mouseReleased (const AbstractEditMode::MouseEventData& data) override; |
|
83 void addDrawnVertex (const Vertex& pos); |
|
84 void finishDraw (LDObjectList& objs); |
|
85 |
|
86 virtual bool preAddVertex (Vertex const&) |
|
87 { |
|
88 return false; |
|
89 } |
|
90 }; |
|
91 |
|
92 // |
|
93 // Base class for select-like edit modes |
|
94 // |
|
95 class AbstractSelectMode : public AbstractEditMode |
|
96 { |
|
97 DEFINE_CLASS (AbstractSelectMode, AbstractEditMode) |
|
98 |
|
99 public: |
|
100 AbstractSelectMode (GLRenderer* renderer); |
|
101 |
|
102 virtual bool allowFreeCamera() const override |
|
103 { |
|
104 return true; |
|
105 } |
|
106 }; |