Wed, 16 Jul 2014 15:00:41 +0300
- changed copyright lines to use my legal name instead of my nickname
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
1 | /* |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
844
11587d419d2f
- changed copyright lines to use my legal name instead of my nickname
Teemu Piippo <crimsondusk64@gmail.com>
parents:
840
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Teemu Piippo |
829
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
4 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
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:
828
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:
828
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:
828
diff
changeset
|
8 | * (at your option) any later version. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
9 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
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:
828
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
13 | * GNU General Public License for more details. |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
14 | * |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
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:
828
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:
828
diff
changeset
|
17 | */ |
bb903e89e23c
- now with license headers
Santeri Piippo <crimsondusk64@gmail.com>
parents:
828
diff
changeset
|
18 | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QMouseEvent> |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
20 | #include "selectMode.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include "../glRenderer.h" |
827 | 22 | #include "../addObjectDialog.h" |
23 | #include "../mainWindow.h" | |
24 | #include "../glRenderer.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 | SelectMode::SelectMode (GLRenderer* renderer) : |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
27 | Super (renderer), |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
28 | _rangepick (false) {} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | EditModeType SelectMode::type() const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | return EditModeType::Select; |
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 | |
827 | 35 | void SelectMode::render (QPainter& painter) const |
36 | { | |
37 | // If we're range-picking, draw a rectangle encompassing the selection area. | |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
38 | if (_rangepick) |
827 | 39 | { |
40 | int x0 = _rangeStart.x(), | |
41 | y0 = _rangeStart.y(), | |
42 | x1 = renderer()->mousePosition().x(), | |
43 | y1 = renderer()->mousePosition().y(); | |
44 | ||
45 | QRect rect (x0, y0, x1 - x0, y1 - y0); | |
46 | QColor fillColor = (_addpick ? "#40FF00" : "#00CCFF"); | |
47 | fillColor.setAlphaF (0.2f); | |
48 | painter.setPen (QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | |
49 | painter.setBrush (QBrush (fillColor)); | |
50 | painter.drawRect (rect); | |
51 | } | |
52 | } | |
53 | ||
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
54 | bool SelectMode::mouseReleased (MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
56 | if (Super::mouseReleased (data)) |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
57 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
58 | |
827 | 59 | if (data.releasedButtons & Qt::LeftButton) |
60 | { | |
61 | if (not data.mouseMoved) | |
62 | _rangepick = false; | |
63 | ||
64 | if (not _rangepick) | |
65 | _addpick = (data.keymods & Qt::ControlModifier); | |
66 | ||
840
d077dd19bf9a
- changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents:
830
diff
changeset
|
67 | if (not data.mouseMoved or _rangepick) |
827 | 68 | { |
69 | QRect area; | |
70 | int const mx = data.ev->x(); | |
71 | int const my = data.ev->y(); | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | |
827 | 73 | if (not _rangepick) |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
74 | { |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
75 | area = QRect (mx, my, 1, 1); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
76 | } |
827 | 77 | else |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
78 | { |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
79 | int const x = min (_rangeStart.x(), mx); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
80 | int const y = min (_rangeStart.y(), my); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
81 | int const width = abs (_rangeStart.x() - mx); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
82 | int const height = abs (_rangeStart.y() - my); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
83 | area = QRect (x, y, width, height); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
84 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | |
827 | 86 | renderer()->pick (area, _addpick); |
87 | } | |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
88 | |
827 | 89 | _rangepick = false; |
90 | return true; | |
91 | } | |
92 | ||
93 | return false; | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
96 | bool SelectMode::mousePressed (QMouseEvent* ev) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | { |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
98 | if (Super::mousePressed (ev)) |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
99 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
100 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
101 | if (ev->modifiers() & Qt::ControlModifier) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | _rangepick = true; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
104 | _rangeStart.setX (ev->x()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
105 | _rangeStart.setY (ev->y()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
106 | _addpick = (ev->modifiers() & Qt::AltModifier); |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
107 | return true; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
109 | |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
110 | return false; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
111 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
112 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
113 | bool SelectMode::mouseDoubleClicked (QMouseEvent* ev) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
114 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
115 | if (Super::mouseDoubleClicked (ev)) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
116 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
117 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
118 | if (ev->buttons() & Qt::LeftButton) |
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 | renderer()->document()->clearSelection(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
121 | LDObjectPtr obj = renderer()->pickOneObject (ev->x(), ev->y()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
122 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
123 | if (obj != null) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
124 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
125 | AddObjectDialog::staticDialog (obj->type(), obj); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
126 | g_win->endAction(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
127 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
128 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
129 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
130 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
131 | return false; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
132 | } |
827 | 133 | |
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
134 | bool SelectMode::mouseMoved (QMouseEvent*) |
827 | 135 | { |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
136 | return _rangepick; |
827 | 137 | } |