Sat, 08 Feb 2020 00:08:57 +0200
avoid having the null id in the selection
47 | 1 | #include <QMouseEvent> |
2 | #include "canvas.h" | |
3 | ||
4 | Canvas::Canvas( | |
5 | Model* model, | |
6 | DocumentManager* documents, | |
7 | const ldraw::ColorTable& colorTable, | |
8 | QWidget* parent) : | |
9 | PartRenderer{model, documents, colorTable, parent} | |
10 | { | |
11 | this->setMouseTracking(true); | |
12 | } | |
13 | ||
51 | 14 | void Canvas::handleSelectionChange(const QSet<ldraw::Id>& selectedIds, const QSet<ldraw::Id>& deselectedIds) |
15 | { | |
52
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
16 | Q_ASSERT(not selectedIds.contains(ldraw::NULL_ID)); |
51 | 17 | this->selection.subtract(deselectedIds); |
18 | this->selection.unite(selectedIds); | |
19 | this->compiler->setSelectedObjects(this->selection); | |
20 | this->update(); | |
21 | } | |
22 | ||
47 | 23 | void Canvas::mouseMoveEvent(QMouseEvent* event) |
24 | { | |
25 | const ldraw::Id id = this->pick(event->pos()); | |
26 | this->newStatusText("Selected: %1"_q.arg(id.value)); | |
51 | 27 | this->highlighted = id; |
28 | this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); | |
29 | this->lastMousePosition = event->pos(); | |
47 | 30 | PartRenderer::mouseMoveEvent(event); |
31 | } | |
51 | 32 | |
33 | void Canvas::mousePressEvent(QMouseEvent* event) | |
34 | { | |
35 | this->totalMouseMove = 0; | |
36 | this->lastMousePosition = event->pos(); | |
37 | PartRenderer::mousePressEvent(event); | |
38 | } | |
39 | ||
40 | void Canvas::mouseReleaseEvent(QMouseEvent* event) | |
41 | { | |
42 | if (this->totalMouseMove < (2.0 / sqrt(2)) * 5.0) | |
43 | { | |
52
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
44 | if (this->highlighted == ldraw::NULL_ID) |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
45 | { |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
46 | this->selection = {}; |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
47 | } |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
48 | else |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
49 | { |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
50 | this->selection = {this->highlighted}; |
eee644f88e93
avoid having the null id in the selection
Teemu Piippo <teemu@hecknology.net>
parents:
51
diff
changeset
|
51 | } |
51 | 52 | this->compiler->setSelectedObjects(this->selection); |
53 | emit selectionChanged(this->selection); | |
54 | this->update(); | |
55 | } | |
56 | PartRenderer::mouseReleaseEvent(event); | |
57 | } |