Tue, 03 Mar 2015 17:42:21 +0200
- moved ui files to src/
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
1 | /* |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
927
409b82a4765e
- bump copyright year
Teemu Piippo <crimsondusk64@gmail.com>
parents:
897
diff
changeset
|
3 | * Copyright (C) 2013 - 2015 Teemu Piippo |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
4 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
8 | * (at your option) any later version. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
9 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
13 | * GNU General Public License for more details. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
14 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
17 | */ |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
18 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QPainter> |
827 | 20 | #include <QMouseEvent> |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
21 | #include "drawMode.h" |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
22 | #include "../ldObject.h" |
827 | 23 | #include "../glRenderer.h" |
897
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
24 | #include "../miscallenous.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | DrawMode::DrawMode (GLRenderer* renderer) : |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
27 | Super (renderer) {} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | EditModeType DrawMode::type() const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | return EditModeType::Draw; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | void DrawMode::render (QPainter& painter) const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | { |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
36 | QVector<Vertex> poly; |
827 | 37 | QFontMetrics metrics = QFontMetrics (QFont()); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
39 | for (Vertex const& vert : m_drawedVerts) |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
40 | poly << vert; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
42 | // Draw the cursor vertex as the last one in the list. |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
43 | if (poly.size() < 4) |
897
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
44 | poly << getCursorVertex(); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
866
4951b737f8cb
- now able to spawn partial circular primitives
Teemu Piippo <crimsondusk64@gmail.com>
parents:
861
diff
changeset
|
46 | renderPolygon (painter, poly, true, true); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | bool DrawMode::preAddVertex (Vertex const& pos) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | // If we picked an already-existing vertex, stop drawing |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
52 | for (Vertex& vert : m_drawedVerts) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | if (vert == pos) |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
827 | 56 | endDraw(); |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | return true; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | return false; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
64 | bool DrawMode::mouseReleased (MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | { |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
66 | if (Super::mouseReleased (data)) |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
67 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
68 | |
827 | 69 | if (data.releasedButtons & Qt::LeftButton) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | { |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
71 | // If we have 4 verts, stop drawing. |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
72 | if (m_drawedVerts.size() >= 4) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | { |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
74 | endDraw(); |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
75 | return true; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
897
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
78 | addDrawnVertex (getCursorVertex()); |
827 | 79 | return true; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
827 | 82 | return false; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | } |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
84 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
85 | void DrawMode::endDraw() |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
86 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
87 | // Clean the selection and create the object |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
88 | QList<Vertex>& verts = m_drawedVerts; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
89 | LDObjectList objs; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
90 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
91 | switch (verts.size()) |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
92 | { |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
93 | case 1: |
928
0fef7bb7b7a2
- removed the vertex object
Teemu Piippo <crimsondusk64@gmail.com>
parents:
927
diff
changeset
|
94 | return; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
95 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
96 | case 2: |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
97 | { |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
98 | // 2 verts - make a line |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
99 | LDLinePtr obj = LDSpawn<LDLine> (verts[0], verts[1]); |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
100 | obj->setColor (EdgeColor()); |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
101 | objs << obj; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
102 | break; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
103 | } |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
104 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
105 | case 3: |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
106 | case 4: |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
107 | { |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
108 | LDObjectPtr obj = (verts.size() == 3) ? |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
109 | static_cast<LDObjectPtr> (LDSpawn<LDTriangle>()) : |
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
110 | static_cast<LDObjectPtr> (LDSpawn<LDQuad>()); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
111 | |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
112 | obj->setColor (MainColor()); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
113 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
114 | for (int i = 0; i < verts.size(); ++i) |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
115 | obj->setVertex (i, verts[i]); |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
116 | |
841
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
117 | objs << obj; |
1243abd47381
- split the rectangle ability out of the draw mode into its own edit mode
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
118 | break; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
119 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
120 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
121 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
122 | finishDraw (objs); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
123 | } |
897
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
124 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
125 | template<typename _Type> |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
126 | _Type IntervalClamp (_Type a, _Type interval) |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
127 | { |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
128 | _Type remainder = a % interval; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
129 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
130 | if (remainder >= float (interval / 2)) |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
131 | a += interval; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
132 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
133 | a -= remainder; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
134 | return a; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
135 | } |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
136 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
137 | Vertex DrawMode::getCursorVertex() const |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
138 | { |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
139 | Vertex result = renderer()->position3D(); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
140 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
141 | if (renderer()->keyboardModifiers() & Qt::ControlModifier |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
142 | and not m_drawedVerts.isEmpty()) |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
143 | { |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
144 | Vertex const& v0 = m_drawedVerts.last(); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
145 | Vertex const& v1 = result; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
146 | Axis relX, relY; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
147 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
148 | renderer()->getRelativeAxes (relX, relY); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
149 | QLineF ln (v0[relX], v0[relY], v1[relX], v1[relY]); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
150 | ln.setAngle (IntervalClamp<int> (ln.angle(), 45)); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
151 | result.setCoordinate (relX, Grid::Snap (ln.x2(), Grid::Coordinate)); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
152 | result.setCoordinate (relY, Grid::Snap (ln.y2(), Grid::Coordinate)); |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
153 | } |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
154 | |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
155 | return result; |
ef9e4469975a
- pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
866
diff
changeset
|
156 | } |