src/gl/partrenderer.cpp

changeset 232
8efa3a33172e
parent 231
a9bf6bab5ea2
child 234
87ee9824210b
--- a/src/gl/partrenderer.cpp	Wed Jun 15 19:47:02 2022 +0300
+++ b/src/gl/partrenderer.cpp	Mon Jun 20 02:04:51 2022 +0300
@@ -43,6 +43,7 @@
 	colorTable{colorTable}
 {
 	this->setMouseTracking(true);
+	this->setFocusPolicy(Qt::WheelFocus);
 	connect(model, &Model::rowsInserted, [&]{
 		this->needBuild = true;
 	});
@@ -294,38 +295,42 @@
 
 void PartRenderer::mouseMoveEvent(QMouseEvent* event)
 {
-	const bool left = event->buttons() & Qt::LeftButton;
-	const QPoint move = event->pos() - this->lastMousePosition;
-	this->totalMouseMove += move.manhattanLength();
-	if (left and not move.isNull())
-	{
-		// q_x is the rotation of the brick along the vertical y-axis, because turning the
-		// vertical axis causes horizontal (=x) rotation. Likewise q_y is the rotation of the
-		// brick along the horizontal x-axis, which causes vertical rotation.
-		const auto scalar = 0.006f;
-		const float move_x = static_cast<float>(move.x());
-		const float move_y = static_cast<float>(move.y());
-		const glm::quat q_x = glm::angleAxis(scalar * move_x, glm::vec3{0, -1, 0});
-		const glm::quat q_y = glm::angleAxis(scalar * move_y, glm::vec3{-1, 0, 0});
-		this->modelQuaternion = q_x * q_y * this->modelQuaternion;
-		this->updateModelMatrix();
+	if (not this->frozen) {
+		const bool left = event->buttons() & Qt::LeftButton;
+		const QPoint move = event->pos() - this->lastMousePosition;
+		this->totalMouseMove += move.manhattanLength();
+		if (left and not move.isNull())
+		{
+			// q_x is the rotation of the brick along the vertical y-axis, because turning the
+			// vertical axis causes horizontal (=x) rotation. Likewise q_y is the rotation of the
+			// brick along the horizontal x-axis, which causes vertical rotation.
+			const auto scalar = 0.006f;
+			const float move_x = static_cast<float>(move.x());
+			const float move_y = static_cast<float>(move.y());
+			const glm::quat q_x = glm::angleAxis(scalar * move_x, glm::vec3{0, -1, 0});
+			const glm::quat q_y = glm::angleAxis(scalar * move_y, glm::vec3{-1, 0, 0});
+			this->modelQuaternion = q_x * q_y * this->modelQuaternion;
+			this->updateModelMatrix();
+		}
+		this->lastMousePosition = event->pos();
+		for (RenderLayer* layer : this->activeRenderLayers) {
+			layer->mouseMoved(event);
+		}
+		this->update();
 	}
-	this->lastMousePosition = event->pos();
-	for (RenderLayer* layer : this->activeRenderLayers) {
-		layer->mouseMoved(event);
-	}
-	this->update();
 }
 
 void PartRenderer::mousePressEvent(QMouseEvent* event)
 {
-	this->totalMouseMove = 0;
-	this->lastMousePosition = event->pos();
+	if (not this->frozen) {
+		this->totalMouseMove = 0;
+		this->lastMousePosition = event->pos();
+	}
 }
 
 void PartRenderer::mouseReleaseEvent(QMouseEvent* event)
 {
-	if (this->totalMouseMove < (2.0 / sqrt(2)) * 5.0)
+	if (not frozen and this->totalMouseMove < (2.0 / sqrt(2)) * 5.0)
 	{
 		for (RenderLayer* layer : this->activeRenderLayers) {
 			layer->mouseClick(event);
@@ -334,13 +339,22 @@
 	}
 }
 
+void PartRenderer::keyReleaseEvent(QKeyEvent* event)
+{
+	if (event->key() == Qt::Key_Pause) {
+		this->frozen = not this->frozen;
+	}
+}
+
 void PartRenderer::wheelEvent(QWheelEvent* event)
 {
-	static constexpr double WHEEL_STEP = 1 / 1000.0;
-	const double move = (-event->angleDelta().y()) * WHEEL_STEP;
-	this->zoom = std::clamp(this->zoom + move, MIN_ZOOM, MAX_ZOOM);
-	this->updateViewMatrix();
-	this->update();
+	if (not this->frozen) {
+		static constexpr double WHEEL_STEP = 1 / 1000.0;
+		const double move = (-event->angleDelta().y()) * WHEEL_STEP;
+		this->zoom = std::clamp(this->zoom + move, MIN_ZOOM, MAX_ZOOM);
+		this->updateViewMatrix();
+		this->update();
+	}
 }
 
 void PartRenderer::addRenderLayer(RenderLayer* layer)

mercurial