src/editmodes/selectmode.cc

changeset 828
7dd8f19159f7
parent 827
82469b40567e
child 829
bb903e89e23c
equal deleted inserted replaced
827:82469b40567e 828:7dd8f19159f7
4 #include "../addObjectDialog.h" 4 #include "../addObjectDialog.h"
5 #include "../mainWindow.h" 5 #include "../mainWindow.h"
6 #include "../glRenderer.h" 6 #include "../glRenderer.h"
7 7
8 SelectMode::SelectMode (GLRenderer* renderer) : 8 SelectMode::SelectMode (GLRenderer* renderer) :
9 Super (renderer) {} 9 Super (renderer),
10 _rangepick (false) {}
10 11
11 EditModeType SelectMode::type() const 12 EditModeType SelectMode::type() const
12 { 13 {
13 return EditModeType::Select; 14 return EditModeType::Select;
14 } 15 }
15 16
16
17 void SelectMode::render (QPainter& painter) const 17 void SelectMode::render (QPainter& painter) const
18 { 18 {
19 // If we're range-picking, draw a rectangle encompassing the selection area. 19 // If we're range-picking, draw a rectangle encompassing the selection area.
20 if (_rangepick && not renderer()->mouseHasMoved()) 20 if (_rangepick)
21 { 21 {
22 int x0 = _rangeStart.x(), 22 int x0 = _rangeStart.x(),
23 y0 = _rangeStart.y(), 23 y0 = _rangeStart.y(),
24 x1 = renderer()->mousePosition().x(), 24 x1 = renderer()->mousePosition().x(),
25 y1 = renderer()->mousePosition().y(); 25 y1 = renderer()->mousePosition().y();
51 QRect area; 51 QRect area;
52 int const mx = data.ev->x(); 52 int const mx = data.ev->x();
53 int const my = data.ev->y(); 53 int const my = data.ev->y();
54 54
55 if (not _rangepick) 55 if (not _rangepick)
56 area = QRect (mx, my, mx + 1, my + 1); 56 {
57 area = QRect (mx, my, 1, 1);
58 }
57 else 59 else
58 area = QRect (_rangeStart.x(), _rangeStart.y(), mx, my); 60 {
61 int const x = min (_rangeStart.x(), mx);
62 int const y = min (_rangeStart.y(), my);
63 int const width = abs (_rangeStart.x() - mx);
64 int const height = abs (_rangeStart.y() - my);
65 area = QRect (x, y, width, height);
66 }
59 67
60 renderer()->pick (area, _addpick); 68 renderer()->pick (area, _addpick);
61 } 69 }
62 70
63 _rangepick = false; 71 _rangepick = false;
103 } 111 }
104 112
105 return false; 113 return false;
106 } 114 }
107 115
108 bool SelectMode::mouseMoved (QMouseEvent*) 116 bool SelectMode::mouseMoved (QMouseEvent* ev)
109 { 117 {
110 return not _rangepick; 118 return _rangepick;
111 } 119 }

mercurial