added preview layer code and fixed build warnings

Mon, 19 Jul 2021 23:41:52 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 19 Jul 2021 23:41:52 +0300
changeset 105
6ca6e8c647d4
parent 104
cd4df75924b7
child 106
128efb9d148b

added preview layer code and fixed build warnings

CMakeLists.txt file | annotate | diff | comparison | revisions
src/geometry.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/parser.cpp file | annotate | diff | comparison | revisions
src/tools/drawtool.h file | annotate | diff | comparison | revisions
src/ui/canvas.cpp file | annotate | diff | comparison | revisions
src/ui/canvas.h file | annotate | diff | comparison | revisions
src/widgets/vec3editor.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Mon Jul 19 19:28:16 2021 +0300
+++ b/CMakeLists.txt	Mon Jul 19 23:41:52 2021 +0300
@@ -10,7 +10,7 @@
 find_package(Qt5Core REQUIRED)
 find_package(Qt5OpenGL REQUIRED)
 find_package(Qt5Network REQUIRED)
-find_package(Qt5LinguistTools REQUIRED)
+#find_package(Qt5LinguistTools REQUIRED)
 find_package(GLM REQUIRED)
 set(CMAKE_AUTOMOC ON)
 set(CMAKE_AUTOUIC ON)
--- a/src/geometry.h	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/geometry.h	Mon Jul 19 23:41:52 2021 +0300
@@ -97,4 +97,9 @@
 		glm::mat4 unscaled;
 	};
 	ScalingExtract extractScaling(const glm::mat4& matrix);
+
+	struct NPolygon
+	{
+		std::vector<glm::vec3> points;
+	};
 }
--- a/src/mainwindow.cpp	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/mainwindow.cpp	Mon Jul 19 23:41:52 2021 +0300
@@ -409,7 +409,7 @@
 
 void MainWindow::canvasMousePressed(QMouseEvent *event)
 {
-
+	Q_UNUSED(event)
 }
 
 void MainWindow::canvasMouseReleased(const Canvas::MouseClickInfo& info)
@@ -420,6 +420,17 @@
 	}
 }
 
-void MainWindow::canvasMouseDoubleClicked(QMouseEvent* event){}
-void MainWindow::canvasMouseMoved(QMouseEvent*){}
-void MainWindow::canvasKeyReleased(QKeyEvent*){}
+void MainWindow::canvasMouseDoubleClicked(QMouseEvent* event)
+{
+	Q_UNUSED(event)
+}
+
+void MainWindow::canvasMouseMoved(QMouseEvent* event)
+{
+	Q_UNUSED(event)
+}
+
+void MainWindow::canvasKeyReleased(QKeyEvent* event)
+{
+	Q_UNUSED(event)
+}
--- a/src/parser.cpp	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/parser.cpp	Mon Jul 19 23:41:52 2021 +0300
@@ -82,7 +82,7 @@
 	{
 		QStringList tokens = line
 			.mid(strlen("0 !LDRAW_ORG "))
-			.split(" ", QString::SkipEmptyParts);
+			.split(" ", Qt::SkipEmptyParts);
 		if (not tokens.isEmpty())
 		{
 			QString partTypeString = tokens[0];
--- a/src/tools/drawtool.h	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/tools/drawtool.h	Mon Jul 19 23:41:52 2021 +0300
@@ -8,7 +8,7 @@
 public:
 	Q_INVOKABLE DrawTool(QObject* parent = nullptr);
 
-	QString name() const;
-	QString toolTip() const;
+	QString name() const override;
+	QString toolTip() const override;
 	bool mouseClick(const Canvas::MouseClickInfo& info) override;
 };
--- a/src/ui/canvas.cpp	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/ui/canvas.cpp	Mon Jul 19 23:41:52 2021 +0300
@@ -233,6 +233,20 @@
 					renderText(axis.text, *intersection);
 				}
 			}
+			for (const PreviewLayer& previewLayer : this->previewLayers)
+			{
+				painter.setBrush({previewLayer.color});
+				for (const geom::NPolygon& polygon3d : previewLayer.polygons)
+				{
+					QVector<QPointF> points2d;
+					points2d.reserve(polygon3d.points.size());
+					for (const glm::vec3& point : polygon3d.points)
+					{
+						points2d.push_back(this->modelToScreenCoordinates(point));
+					}
+					painter.drawPolygon({points2d});
+				}
+			}
 		}
 	}
 }
@@ -272,3 +286,13 @@
 	const float dot = glm::dot(glm::normalize(this->gridPlane.normal), glm::normalize(cameraDirection));
 	return std::abs(dot) < threshold;
 }
+
+const Canvas::PreviewLayer& Canvas::getPreviewLayer(PreviewLayerName name) const
+{
+	return previewLayers[static_cast<unsigned int>(name)];
+}
+
+Canvas::PreviewLayer& Canvas::modifyPreviewLayer(PreviewLayerName name)
+{
+	return previewLayers[static_cast<unsigned int>(name)];
+}
--- a/src/ui/canvas.h	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/ui/canvas.h	Mon Jul 19 23:41:52 2021 +0300
@@ -8,11 +8,24 @@
 	Q_OBJECT
 public:
 	struct MouseClickInfo;
+	enum PreviewLayerName : std::int8_t
+	{
+		DrawToolPreview
+	};
+	struct PreviewLayer
+	{
+		QSet<geom::NPolygon> polygons;
+		QColor color{64, 255, 128};
+	};
+	static constexpr int NUM_PREVIEW_LAYERS = 1;
+
 	Canvas(
 		Model* model,
 		DocumentManager* documents,
 		const ldraw::ColorTable& colorTable,
 		QWidget* parent = nullptr);
+	const PreviewLayer& getPreviewLayer(PreviewLayerName name) const;
+	PreviewLayer& modifyPreviewLayer(PreviewLayerName name);
 public slots:
 	void handleSelectionChange(const QSet<ldraw::id_t>& selectedIds, const QSet<ldraw::id_t>& deselectedIds);
 protected:
@@ -36,6 +49,7 @@
 	geom::Plane gridPlane;
 	int totalMouseMove = 0;
 	QSet<ldraw::id_t> selection;
+	PreviewLayer previewLayers[NUM_PREVIEW_LAYERS];
 };
 
 struct Canvas::MouseClickInfo
--- a/src/widgets/vec3editor.h	Mon Jul 19 19:28:16 2021 +0300
+++ b/src/widgets/vec3editor.h	Mon Jul 19 23:41:52 2021 +0300
@@ -15,7 +15,7 @@
 	{
 		NoMultiplyButton = 0x1
 	};
-	explicit Vec3Editor(const glm::vec3& value, QWidget* parent = nullptr, QFlags<Flag> flags = 0);
+	explicit Vec3Editor(const glm::vec3& value, QWidget* parent = nullptr, QFlags<Flag> flags = {});
 	~Vec3Editor();
 	glm::vec3 value() const;
 	void setValue(const glm::vec3& value);

mercurial