Sun, 12 Feb 2017 16:02:02 +0200
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
1 | /* |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 - 2017 Teemu Piippo |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
4 | * |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
9 | * |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
14 | * |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
17 | */ |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
18 | |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
19 | #include <QMouseEvent> |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
20 | #include "canvas.h" |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
21 | #include "documentmanager.h" |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
22 | #include "grid.h" |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
23 | #include "ldDocument.h" |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
24 | #include "mainwindow.h" |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
25 | #include "messageLog.h" |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
26 | #include "miscallenous.h" |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
27 | #include "primitives.h" |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
28 | |
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
29 | Canvas::Canvas(LDDocument* document, QWidget* parent) : |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
30 | GLRenderer {document, parent}, |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
31 | m_document {*document}, |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
32 | m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {} |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
33 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
34 | Canvas::~Canvas() |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
35 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
36 | delete m_currentEditMode; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
37 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
38 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
39 | void Canvas::overpaint(QPainter& painter) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
40 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
41 | GLRenderer::overpaint(painter); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
42 | QFontMetrics metrics {QFont {}}; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
43 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
44 | #ifndef RELEASE |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
45 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
46 | QString text = format("Rotation: %1\nPanning: (%2, %3), Zoom: %4", rotationMatrix(), panning(X), panning(Y), zoom()); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
47 | QRect textSize = metrics.boundingRect(0, 0, width(), height(), Qt::AlignCenter, text); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
48 | painter.setPen(textPen()); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
49 | painter.drawText((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(), |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
50 | textSize.height(), Qt::AlignCenter, text); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
51 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
52 | #endif |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
53 | |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
54 | if (camera() != Camera::Free) |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
55 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
56 | // Paint the coordinates onto the screen. |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
57 | QString text = format(tr("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
58 | QFontMetrics metrics {font()}; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
59 | QRect textSize = metrics.boundingRect (0, 0, width(), height(), Qt::AlignCenter, text); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
60 | painter.setPen(textPen()); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
61 | painter.drawText(width() - textSize.width(), height() - 16, textSize.width(), textSize.height(), Qt::AlignCenter, text); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
62 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
63 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
64 | // Draw edit mode HUD |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
65 | m_currentEditMode->render(painter); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
66 | |
1105
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
67 | // Render triangle count |
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
68 | { |
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
69 | QPoint renderPoint {4, height() - 4 - metrics.height() - metrics.descent()}; |
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
70 | painter.drawText(renderPoint, format("â–³ %1", m_document.triangleCount())); |
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
71 | } |
4f4d219e527d
Moved triangle count rendering to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1104
diff
changeset
|
72 | |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
73 | // Message log |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
74 | if (m_window->messageLog()) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
75 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
76 | int y = 0; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
77 | int margin = 2; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
78 | QColor penColor = textPen().color(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
79 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
80 | for (const MessageManager::Line& line : m_window->messageLog()->getLines()) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
81 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
82 | penColor.setAlphaF(line.alpha); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
83 | painter.setPen(penColor); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
84 | painter.drawText(QPoint {margin, y + margin + metrics.ascent()}, line.text); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
85 | y += metrics.height(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
86 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
87 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
88 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
89 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
90 | bool Canvas::freeCameraAllowed() const |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
91 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
92 | return m_currentEditMode->allowFreeCamera(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
93 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
94 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
95 | void Canvas::setEditMode(EditModeType a) |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
96 | { |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
97 | if (m_currentEditMode and m_currentEditMode->type() == a) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
98 | return; |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
99 | |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
100 | delete m_currentEditMode; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
101 | m_currentEditMode = AbstractEditMode::createByType(this, a); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
102 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
103 | // If we cannot use the free camera, use the top one instead. |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
104 | if (camera() == Camera::Free and not m_currentEditMode->allowFreeCamera()) |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
105 | setCamera(Camera::Top); |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
106 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
107 | m_window->updateEditModeActions(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
108 | update(); |
1103
ac7db4c076c3
Created a new GLRenderer derivative class "Canvas" and made MainWindow use it
Teemu Piippo <teemu@hecknology.net>
parents:
diff
changeset
|
109 | } |
1104
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
110 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
111 | EditModeType Canvas::currentEditModeType() const |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
112 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
113 | return m_currentEditMode->type(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
114 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
115 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
116 | LDDocument* Canvas::document() const |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
117 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
118 | return &m_document; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
119 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
120 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
121 | void Canvas::mouseDoubleClickEvent(QMouseEvent* event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
122 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
123 | if (m_currentEditMode->mouseDoubleClicked (event)) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
124 | event->accept(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
125 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
126 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
127 | void Canvas::dropEvent(QDropEvent* event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
128 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
129 | if (m_window and event->source() == m_window->getPrimitivesTree()) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
130 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
131 | PrimitiveTreeItem* item = static_cast<PrimitiveTreeItem*> (m_window->getPrimitivesTree()->currentItem()); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
132 | QString primitiveName = item->primitive()->name; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
133 | LDSubfileReference* reference = currentDocument()->emplaceAt<LDSubfileReference>(m_window->suggestInsertPoint()); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
134 | reference->setFileInfo (m_documents->getDocumentByName(primitiveName)); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
135 | currentDocument()->addToSelection(reference); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
136 | m_window->buildObjectList(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
137 | refresh(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
138 | event->acceptProposedAction(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
139 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
140 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
141 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
142 | void Canvas::keyReleaseEvent(QKeyEvent* event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
143 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
144 | m_currentEditMode->keyReleased(event); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
145 | GLRenderer::keyReleaseEvent(event); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
146 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
147 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
148 | void Canvas::mouseMoveEvent(QMouseEvent* event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
149 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
150 | // Calculate 3d position of the cursor |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
151 | m_position3D = convert2dTo3d(mousePosition(), true); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
152 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
153 | if (not m_currentEditMode->mouseMoved(event)) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
154 | GLRenderer::mouseMoveEvent(event); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
155 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
156 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
157 | void Canvas::mouseReleaseEvent(QMouseEvent *event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
158 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
159 | AbstractEditMode::MouseEventData data; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
160 | data.ev = event; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
161 | data.mouseMoved = mouseHasMoved(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
162 | data.keymods = keyboardModifiers(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
163 | data.releasedButtons = lastButtons() & ~event->buttons(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
164 | m_currentEditMode->mouseReleased(data); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
165 | GLRenderer::mouseReleaseEvent(event); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
166 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
167 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
168 | void Canvas::mousePressEvent(QMouseEvent *event) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
169 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
170 | if (m_currentEditMode->mousePressed(event)) |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
171 | event->accept(); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
172 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
173 | GLRenderer::mousePressEvent(event); |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
174 | } |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
175 | |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
176 | const Vertex& Canvas::position3D() const |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
177 | { |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
178 | return m_position3D; |
edddb9b0db9e
Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents:
1103
diff
changeset
|
179 | } |
1106
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
180 | |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
181 | void Canvas::drawPoint(QPainter& painter, QPointF pos, QColor color) const |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
182 | { |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
183 | int pointSize = 8; |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
184 | QPen pen = thinBorderPen; |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
185 | pen.setWidth(1); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
186 | painter.setPen(pen); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
187 | painter.setBrush(color); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
188 | painter.drawEllipse(pos.x() - pointSize / 2, pos.y() - pointSize / 2, pointSize, pointSize); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
189 | } |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
190 | |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
191 | void Canvas::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d) const |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
192 | { |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
193 | drawBlipCoordinates (painter, pos3d, convert3dTo2d (pos3d)); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
194 | } |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
195 | |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
196 | void Canvas::drawBlipCoordinates(QPainter& painter, const Vertex& pos3d, QPointF pos) const |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
197 | { |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
198 | painter.setPen (textPen()); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
199 | painter.drawText (pos.x(), pos.y() - 8, pos3d.toString (true)); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
200 | } |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
201 | |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
202 | QPen Canvas::linePen() const |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
203 | { |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
204 | QPen linepen = thinBorderPen; |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
205 | linepen.setWidth(2); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
206 | linepen.setColor(luma(backgroundColor()) < 40 ? Qt::white : Qt::black); |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
207 | return linepen; |
7541b0209057
Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents:
1105
diff
changeset
|
208 | } |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
209 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
210 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
211 | int Canvas::depthNegateFactor() const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
212 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
213 | return cameraInfo(camera()).negatedDepth ? -1 : 1; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
214 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
215 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
216 | // ============================================================================= |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
217 | // |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
218 | void Canvas::getRelativeAxes(Axis& relativeX, Axis& relativeY) const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
219 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
220 | const CameraInfo& camera = cameraInfo(this->camera()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
221 | relativeX = camera.localX; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
222 | relativeY = camera.localY; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
223 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
224 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
225 | // ============================================================================= |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
226 | // |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
227 | Axis Canvas::getRelativeZ() const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
228 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
229 | const CameraInfo& camera = cameraInfo(this->camera()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
230 | return static_cast<Axis>(3 - camera.localX - camera.localY); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
231 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
232 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
233 | // ============================================================================= |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
234 | // |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
235 | void Canvas::setDepthValue (double depth) |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
236 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
237 | if (camera() < Camera::Free) |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
238 | m_depthValues[static_cast<int>(camera())] = depth; |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
239 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
240 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
241 | // ============================================================================= |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
242 | // |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
243 | double Canvas::getDepthValue() const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
244 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
245 | if (camera() < Camera::Free) |
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
246 | return m_depthValues[static_cast<int>(camera())]; |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
247 | else |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
248 | return 0.0; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
249 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
250 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
251 | /* |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
252 | * This converts a 2D point on the screen to a 3D point in the model. If 'snap' is true, the 3D point will snap to the current grid. |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
253 | */ |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
254 | Vertex Canvas::convert2dTo3d(const QPoint& position2d, bool snap) const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
255 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
256 | if (camera() == Camera::Free) |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
257 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
258 | return {0, 0, 0}; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
259 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
260 | else |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
261 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
262 | Vertex position3d; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
263 | const CameraInfo& camera = cameraInfo(this->camera()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
264 | Axis axisX = camera.localX; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
265 | Axis axisY = camera.localY; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
266 | int signX = camera.negatedX ? -1 : 1; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
267 | int signY = camera.negatedY ? -1 : 1; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
268 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
269 | // Calculate cx and cy - these are the LDraw unit coords the cursor is at. |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
270 | double cx = (-virtualWidth() + ((2 * position2d.x() * virtualWidth()) / width()) - panning(X)); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
271 | double cy = (virtualHeight() - ((2 * position2d.y() * virtualHeight()) / height()) - panning(Y)); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
272 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
273 | if (snap) |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
274 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
275 | cx = grid()->snap(cx, Grid::Coordinate); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
276 | cy = grid()->snap(cy, Grid::Coordinate); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
277 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
278 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
279 | cx *= signX; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
280 | cy *= signY; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
281 | roundToDecimals(cx, 4); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
282 | roundToDecimals(cy, 4); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
283 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
284 | // Create the vertex from the coordinates |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
285 | position3d.setCoordinate(axisX, cx); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
286 | position3d.setCoordinate(axisY, cy); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
287 | position3d.setCoordinate(static_cast<Axis>(3 - axisX - axisY), getDepthValue()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
288 | return position3d; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
289 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
290 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
291 | |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
292 | /* |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
293 | * Inverse operation for the above - convert a 3D position to a 2D screen position. |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
294 | */ |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
295 | QPoint Canvas::convert3dTo2d(const Vertex& position3d) const |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
296 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1110
diff
changeset
|
297 | if (camera() == Camera::Free) |
1108
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
298 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
299 | return {0, 0}; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
300 | } |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
301 | else |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
302 | { |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
303 | const CameraInfo& camera = cameraInfo(this->camera()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
304 | Axis axisX = camera.localX; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
305 | Axis axisY = camera.localY; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
306 | int signX = camera.negatedX ? -1 : 1; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
307 | int signY = camera.negatedY ? -1 : 1; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
308 | int rx = (((position3d[axisX] * signX) + virtualWidth() + panning(X)) * width()) / (2 * virtualWidth()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
309 | int ry = (((position3d[axisY] * signY) - virtualHeight() + panning(Y)) * height()) / (2 * virtualHeight()); |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
310 | return {rx, -ry}; |
90d6f4b7782e
Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents:
1106
diff
changeset
|
311 | } |
1110
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
312 | } |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
313 | |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
314 | void Canvas::contextMenuEvent(QContextMenuEvent* event) |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
315 | { |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
316 | m_window->spawnContextMenu(event->globalPos()); |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
317 | } |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
318 | |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
319 | void Canvas::dragEnterEvent(QDragEnterEvent* event) |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
320 | { |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
321 | if (m_window and event->source() == m_window->getPrimitivesTree() and m_window->getPrimitivesTree()->currentItem()) |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
322 | event->acceptProposedAction(); |
ec3ee7da7806
Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents:
1108
diff
changeset
|
323 | } |