1 #include <QMouseEvent> |
1 #include <QMouseEvent> |
2 #include <QPainter> |
2 #include <QPainter> |
3 #include "modeleditor.h" |
|
4 #include "document.h" |
3 #include "document.h" |
5 #include "canvas.h" |
4 #include "canvas.h" |
6 |
5 |
7 Canvas::Canvas( |
6 Canvas::Canvas( |
8 Model* model, |
7 Model* model, |
9 Document *document, |
8 EditorTabWidget *document, |
10 DocumentManager* documents, |
9 DocumentManager* documents, |
11 const ldraw::ColorTable& colorTable, |
10 const ldraw::ColorTable& colorTable, |
12 QWidget* parent) : |
11 QWidget* parent) : |
13 PartRenderer{model, documents, colorTable, parent}, |
12 PartRenderer{model, documents, colorTable, parent}, |
14 document{document} |
13 document{document} |
19 /** |
18 /** |
20 * @brief Handles a change of selection |
19 * @brief Handles a change of selection |
21 * @param selectedIds IDs of objects to select |
20 * @param selectedIds IDs of objects to select |
22 * @param deselectedIds IDs of objects to deselect. |
21 * @param deselectedIds IDs of objects to deselect. |
23 */ |
22 */ |
24 void Canvas::handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds) |
23 void Canvas::handleSelectionChange(const QSet<ModelId> &selectedIds, const QSet<ModelId> &deselectedIds) |
25 { |
24 { |
26 Q_ASSERT(not selectedIds.contains(ldraw::NULL_ID)); |
25 Q_ASSERT(not selectedIds.contains({0})); |
27 this->selection.subtract(deselectedIds); |
26 this->selection.subtract(deselectedIds); |
28 this->selection.unite(selectedIds); |
27 this->selection.unite(selectedIds); |
29 gl::setModelShaderSelectedObjects(&this->shaders, this->selection); |
28 gl::setModelShaderSelectedObjects(&this->shaders, this->selection); |
30 this->update(); |
29 this->update(); |
31 } |
30 } |
32 |
31 |
33 /** |
32 /** |
34 * @brief Updates vertex rendering |
33 * @brief Updates vertex rendering |
35 * @param document Document to get vertices from |
34 * @param document Document to get vertices from |
36 */ |
35 */ |
37 void Canvas::rebuildVertices(Document* document) |
36 void Canvas::rebuildVertices(EditorTabWidget* document) |
38 { |
37 { |
39 if (this->vertexProgram.has_value()) |
38 if (this->vertexProgram.has_value()) |
40 { |
39 { |
41 this->vertexProgram->build(document); |
40 this->vertexProgram->build(document); |
42 this->update(); |
41 this->update(); |
43 } |
42 } |
44 } |
43 } |
45 |
44 |
46 void Canvas::mouseMoveEvent(QMouseEvent* event) |
45 void Canvas::mouseMoveEvent(QMouseEvent* event) |
47 { |
46 { |
48 const ldraw::id_t id = this->pick(event->pos()); |
47 const ModelId id = this->pick(event->pos()); |
49 this->highlighted = id; |
48 this->highlighted = id; |
50 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); |
49 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength(); |
51 this->worldPosition = this->screenToModelCoordinates(event->pos(), this->gridPlane); |
50 this->worldPosition = this->screenToModelCoordinates(event->pos(), this->gridPlane); |
52 if (this->worldPosition.has_value()) |
51 if (this->worldPosition.has_value()) |
53 { |
52 { |