src/ui/canvas.cpp

changeset 57
5c0005f63319
parent 56
fad4a5dd8dee
child 58
b7841cd31fb7
equal deleted inserted replaced
56:fad4a5dd8dee 57:5c0005f63319
1 #include <QMouseEvent> 1 #include <QMouseEvent>
2 #include <QPainter>
2 #include "canvas.h" 3 #include "canvas.h"
3 4
4 Canvas::Canvas( 5 Canvas::Canvas(
5 Model* model, 6 Model* model,
6 DocumentManager* documents, 7 DocumentManager* documents,
20 this->update(); 21 this->update();
21 } 22 }
22 23
23 void Canvas::mouseMoveEvent(QMouseEvent* event) 24 void Canvas::mouseMoveEvent(QMouseEvent* event)
24 { 25 {
25 #if 0 26 const ldraw::Id id = this->pick(event->pos());
26 std::optional<glm::vec3> p = this->cameraToGrid(event->pos()); 27 this->highlighted = id;
27 if (p.has_value()) 28 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength();
29 this->lastMousePosition = event->pos();
30 this->worldPosition = this->screenToModelCoordinates(this->lastMousePosition);
31 if (this->worldPosition.has_value())
28 { 32 {
29 this->newStatusText("Position: (%1, %2, %3)"_q.arg(p->x).arg(p->y).arg(p->z)); 33 this->worldPosition = glm::round(*this->worldPosition);
34 }
35 if (this->worldPosition.has_value())
36 {
37 this->newStatusText("Position: (%1, %2, %3)"_q
38 .arg(this->worldPosition->x)
39 .arg(this->worldPosition->y)
40 .arg(this->worldPosition->z));
30 } 41 }
31 else 42 else
32 { 43 {
33 this->newStatusText("Position: <none>"_q); 44 this->newStatusText("Position: <none>"_q);
34 } 45 }
35 #else
36 const QPointF originAtCamera = this->modelToScreenCoordinates({1, 1, 1});
37 this->newStatusText("{1,1,1} is at (%1, %2), cursor at (%3, %4)"_q.arg(originAtCamera.x()).arg(originAtCamera.y()).arg(event->pos().x()).arg(event->pos().y()));
38 #endif
39 const ldraw::Id id = this->pick(event->pos());
40 this->highlighted = id;
41 this->totalMouseMove += (event->pos() - this->lastMousePosition).manhattanLength();
42 this->lastMousePosition = event->pos();
43 PartRenderer::mouseMoveEvent(event); 46 PartRenderer::mouseMoveEvent(event);
44 } 47 }
45 48
46 void Canvas::mousePressEvent(QMouseEvent* event) 49 void Canvas::mousePressEvent(QMouseEvent* event)
47 { 50 {
66 emit selectionChanged(this->selection); 69 emit selectionChanged(this->selection);
67 this->update(); 70 this->update();
68 } 71 }
69 PartRenderer::mouseReleaseEvent(event); 72 PartRenderer::mouseReleaseEvent(event);
70 } 73 }
74
75 void Canvas::paintGL()
76 {
77 PartRenderer::paintGL();
78 if (this->worldPosition.has_value())
79 {
80 QPainter painter{this};
81 painter.setRenderHint(QPainter::Antialiasing);
82 painter.setPen(Qt::black);
83 painter.setBrush(Qt::green);
84 painter.drawEllipse(this->modelToScreenCoordinates(*this->worldPosition), 10, 10);
85 }
86 }

mercurial