src/editmodes/selectmode.cc

Sat, 05 Jul 2014 01:44:41 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 05 Jul 2014 01:44:41 +0300
changeset 828
7dd8f19159f7
parent 827
82469b40567e
child 829
bb903e89e23c
permissions
-rw-r--r--

- 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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
4 #include "../addObjectDialog.h"
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
5 #include "../mainWindow.h"
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
17 void SelectMode::render (QPainter& painter) const
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
18 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
21 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
22 int x0 = _rangeStart.x(),
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
23 y0 = _rangeStart.y(),
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
24 x1 = renderer()->mousePosition().x(),
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
25 y1 = renderer()->mousePosition().y();
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
26
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
27 QRect rect (x0, y0, x1 - x0, y1 - y0);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
28 QColor fillColor = (_addpick ? "#40FF00" : "#00CCFF");
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
29 fillColor.setAlphaF (0.2f);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
30 painter.setPen (QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
31 painter.setBrush (QBrush (fillColor));
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
32 painter.drawRect (rect);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
33 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
34 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
41 if (data.releasedButtons & Qt::LeftButton)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
42 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
43 if (not data.mouseMoved)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
44 _rangepick = false;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
45
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
46 if (not _rangepick)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
47 _addpick = (data.keymods & Qt::ControlModifier);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
48
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
49 if (not data.mouseMoved || _rangepick)
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
50 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
51 QRect area;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
52 int const mx = data.ev->x();
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
68 renderer()->pick (area, _addpick);
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
69 }
824
6add2126e7ff - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 823
diff changeset
70
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
71 _rangepick = false;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
72 return true;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
73 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
74
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
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
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
117 {
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
118 return _rangepick;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
119 }

mercurial