Thu, 09 Feb 2017 00:32:24 +0200
Made a new renderer be created for each document, instead of reusing the same renderer for all documents.
|
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 |
| 1072 | 3 | * Copyright (C) 2013 - 2017 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 |
|
1006
a6b462051ae0
Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
8 | * (at your option) any later version. |
|
829
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" |
|
962
a4b463a7ee82
Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents:
952
diff
changeset
|
22 | #include "../mainwindow.h" |
| 827 | 23 | #include "../glRenderer.h" |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | |
|
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | SelectMode::SelectMode (GLRenderer* renderer) : |
|
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
26 | Super (renderer), |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
27 | m_rangepick (false) {} |
|
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 SelectMode::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::Select; |
|
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 | |
| 827 | 34 | void SelectMode::render (QPainter& painter) const |
| 35 | { | |
| 36 | // If we're range-picking, draw a rectangle encompassing the selection area. | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
37 | if (m_rangepick) |
| 827 | 38 | { |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
39 | int x0 = m_rangeStart.x(), |
|
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
40 | y0 = m_rangeStart.y(), |
| 827 | 41 | x1 = renderer()->mousePosition().x(), |
| 42 | y1 = renderer()->mousePosition().y(); | |
| 43 | ||
| 44 | QRect rect (x0, y0, x1 - x0, y1 - y0); | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
45 | QColor fillColor = (m_addpick ? "#40FF00" : "#00CCFF"); |
| 827 | 46 | fillColor.setAlphaF (0.2f); |
| 47 | painter.setPen (QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); | |
| 48 | painter.setBrush (QBrush (fillColor)); | |
| 49 | painter.drawRect (rect); | |
| 50 | } | |
| 51 | } | |
| 52 | ||
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
53 | bool SelectMode::mouseReleased (MouseEventData const& data) |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | { |
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
55 | if (Super::mouseReleased (data)) |
|
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
56 | return true; |
|
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
57 | |
| 827 | 58 | if (data.releasedButtons & Qt::LeftButton) |
| 59 | { | |
| 60 | if (not data.mouseMoved) | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
61 | m_rangepick = false; |
| 827 | 62 | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
63 | if (not m_rangepick) |
|
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
64 | m_addpick = (data.keymods & Qt::ControlModifier); |
| 827 | 65 | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
66 | if (not data.mouseMoved or m_rangepick) |
| 827 | 67 | { |
| 68 | QRect area; | |
| 69 | int const mx = data.ev->x(); | |
| 70 | int const my = data.ev->y(); | |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
72 | if (not m_rangepick) |
|
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
73 | { |
|
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
74 | area = QRect (mx, my, 1, 1); |
|
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
75 | } |
| 827 | 76 | else |
|
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
77 | { |
|
966
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
78 | int const x = qMin (m_rangeStart.x(), mx); |
|
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
79 | int const y = qMin (m_rangeStart.y(), my); |
|
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
80 | int const width = qAbs (m_rangeStart.x() - mx); |
|
a834e43a57da
Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
962
diff
changeset
|
81 | int const height = qAbs (m_rangeStart.y() - my); |
|
828
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
82 | area = QRect (x, y, width, height); |
|
7dd8f19159f7
- and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents:
827
diff
changeset
|
83 | } |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
85 | renderer()->pick (area, m_addpick); |
| 827 | 86 | } |
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
87 | |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
88 | m_rangepick = false; |
| 827 | 89 | return true; |
| 90 | } | |
| 91 | ||
| 92 | return false; | |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | } |
|
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
95 | bool SelectMode::mousePressed (QMouseEvent* ev) |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | { |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
97 | if (Super::mousePressed (ev)) |
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
98 | return true; |
|
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
99 | |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
100 | if (ev->modifiers() & Qt::ControlModifier) |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | { |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
102 | m_rangepick = true; |
|
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
103 | m_rangeStart.setX (ev->x()); |
|
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
104 | m_rangeStart.setY (ev->y()); |
|
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
105 | m_addpick = (ev->modifiers() & Qt::AltModifier); |
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
106 | return true; |
|
823
1a2f593f0c02
- saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | } |
|
824
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
108 | |
|
6add2126e7ff
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
823
diff
changeset
|
109 | return false; |
|
825
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 | bool SelectMode::mouseDoubleClicked (QMouseEvent* ev) |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
113 | { |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
114 | if (Super::mouseDoubleClicked (ev)) |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
115 | return true; |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
116 | |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
117 | if (ev->buttons() & Qt::LeftButton) |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
118 | { |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
119 | renderer()->document()->clearSelection(); |
| 944 | 120 | LDObject* obj = renderer()->pickOneObject (ev->x(), ev->y()); |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
121 | |
|
985
ed7b31b9f904
Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
984
diff
changeset
|
122 | if (obj) |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
123 | { |
|
1075
711c5fff384d
Removed the AddObjectDialog. Garbage code that absolutely needs to be reimplemented.
Teemu Piippo <teemu@hecknology.net>
parents:
1072
diff
changeset
|
124 | // TODO: |
|
977
dc3ceb65cda7
More refactor and removal of g_win uses
Teemu Piippo <crimsondusk64@gmail.com>
parents:
968
diff
changeset
|
125 | m_window->endAction(); |
|
825
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
126 | return true; |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
127 | } |
|
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 | return false; |
|
f7649c9bfd9a
- more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents:
824
diff
changeset
|
131 | } |
| 827 | 132 | |
|
830
a741a0b9df49
- updated filenames
Santeri Piippo <crimsondusk64@gmail.com>
parents:
829
diff
changeset
|
133 | bool SelectMode::mouseMoved (QMouseEvent*) |
| 827 | 134 | { |
|
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
844
diff
changeset
|
135 | return m_rangepick; |
| 827 | 136 | } |