Sat, 05 Jul 2014 01:44:41 +0300
- and now it works fine too
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | #include <QMouseEvent> |
827 | 2 | #include "selectmode.h" |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | #include "../glRenderer.h" |
827 | 4 | #include "../addObjectDialog.h" |
5 | #include "../mainWindow.h" | |
6 | #include "../glRenderer.h" | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | SelectMode::SelectMode (GLRenderer* renderer) : |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
9 | Super (renderer), |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
10 | _rangepick (false) {} |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | EditModeType SelectMode::type() const |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | return EditModeType::Select; |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | } |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | |
827 | 17 | void SelectMode::render (QPainter& painter) const |
18 | { | |
19 | // 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
|
20 | if (_rangepick) |
827 | 21 | { |
22 | int x0 = _rangeStart.x(), | |
23 | y0 = _rangeStart.y(), | |
24 | x1 = renderer()->mousePosition().x(), | |
25 | y1 = renderer()->mousePosition().y(); | |
26 | ||
27 | QRect rect (x0, y0, x1 - x0, y1 - y0); | |
28 | QColor fillColor = (_addpick ? "#40FF00" : "#00CCFF"); | |
29 | fillColor.setAlphaF (0.2f); | |
30 | painter.setPen (QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | |
31 | painter.setBrush (QBrush (fillColor)); | |
32 | painter.drawRect (rect); | |
33 | } | |
34 | } | |
35 | ||
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
36 | bool SelectMode::mouseReleased (MouseEventData const& data) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
38 | if (Super::mouseReleased (data)) |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
39 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
40 | |
827 | 41 | if (data.releasedButtons & Qt::LeftButton) |
42 | { | |
43 | if (not data.mouseMoved) | |
44 | _rangepick = false; | |
45 | ||
46 | if (not _rangepick) | |
47 | _addpick = (data.keymods & Qt::ControlModifier); | |
48 | ||
49 | if (not data.mouseMoved || _rangepick) | |
50 | { | |
51 | QRect area; | |
52 | int const mx = data.ev->x(); | |
53 | int const my = data.ev->y(); | |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
827 | 55 | if (not _rangepick) |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
56 | { |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
57 | area = QRect (mx, my, 1, 1); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
58 | } |
827 | 59 | else |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
60 | { |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
61 | int const x = min (_rangeStart.x(), mx); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
62 | int const y = min (_rangeStart.y(), my); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
63 | int const width = abs (_rangeStart.x() - mx); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
64 | int const height = abs (_rangeStart.y() - my); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
65 | area = QRect (x, y, width, height); |
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
66 | } |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
827 | 68 | renderer()->pick (area, _addpick); |
69 | } | |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
70 | |
827 | 71 | _rangepick = false; |
72 | return true; | |
73 | } | |
74 | ||
75 | return false; | |
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 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
78 | bool SelectMode::mousePressed (QMouseEvent* ev) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | { |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
80 | if (Super::mousePressed (ev)) |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
81 | return true; |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
82 | |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
83 | if (ev->modifiers() & Qt::ControlModifier) |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | { |
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | _rangepick = true; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
86 | _rangeStart.setX (ev->x()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
87 | _rangeStart.setY (ev->y()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
88 | _addpick = (ev->modifiers() & Qt::AltModifier); |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
89 | return true; |
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | } |
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
91 | |
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
92 | return false; |
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
93 | } |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
94 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
95 | bool SelectMode::mouseDoubleClicked (QMouseEvent* ev) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
96 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
97 | if (Super::mouseDoubleClicked (ev)) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
98 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
99 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
100 | if (ev->buttons() & Qt::LeftButton) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
101 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
102 | renderer()->document()->clearSelection(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
103 | LDObjectPtr obj = renderer()->pickOneObject (ev->x(), ev->y()); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
104 | |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
105 | if (obj != null) |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
106 | { |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
107 | AddObjectDialog::staticDialog (obj->type(), obj); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
108 | g_win->endAction(); |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
109 | return true; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
110 | } |
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 | return false; |
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
114 | } |
827 | 115 | |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
116 | bool SelectMode::mouseMoved (QMouseEvent* ev) |
827 | 117 | { |
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
118 | return _rangepick; |
827 | 119 | } |