added buttons to rotate circular primitives

Tue, 19 Jun 2018 23:56:07 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 19 Jun 2018 23:56:07 +0300
changeset 1413
6b0ca41c158f
parent 1412
f5eb947a2e7f
child 1414
04db55860880

added buttons to rotate circular primitives

src/dialogs/circularprimitiveeditor.cpp file | annotate | diff | comparison | revisions
src/dialogs/circularprimitiveeditor.h file | annotate | diff | comparison | revisions
src/dialogs/circularprimitiveeditor.ui file | annotate | diff | comparison | revisions
--- a/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 23:18:58 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 23:56:07 2018 +0300
@@ -125,6 +125,8 @@
 		if (this->primitive)
 			this->primitive->setInverted(checked);
 	});
+	connect(ui.rotateCcw, &QPushButton::clicked, [&](){ rotate(-1); });
+	connect(ui.rotateCw, &QPushButton::clicked, [&](){ rotate(1); });
 	// Connect the reset button, "reset button" here meaning any button with the reset role.
 	connect(
 		ui.buttonBox,
@@ -193,3 +195,16 @@
 	if (primitive)
 		primitive->restore(originalState); // Restoring does not change 'originalState'
 }
+
+void CircularPrimitiveEditor::rotate(double factor)
+{
+	if (primitive)
+	{
+		double angle = factor * 360.0 / primitive->divisions();
+
+		QQuaternion rotation = QQuaternion::fromAxisAndAngle({0.0f, 1.0f, 0.0f}, angle);
+		QMatrix4x4 matrix = primitive->transformationMatrix();
+		matrix.rotate(rotation);
+		primitive->setTransformationMatrix(matrix);
+	}
+}
--- a/src/dialogs/circularprimitiveeditor.h	Tue Jun 19 23:18:58 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.h	Tue Jun 19 23:56:07 2018 +0300
@@ -31,6 +31,7 @@
 private:
 	Q_SLOT void updateWidgets();
 	Q_SLOT void reset();
+	void rotate(double factor);
 
 	class Ui_CircularPrimitiveEditor& ui;
 	LDCircularPrimitive* primitive;
--- a/src/dialogs/circularprimitiveeditor.ui	Tue Jun 19 23:18:58 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.ui	Tue Jun 19 23:56:07 2018 +0300
@@ -138,10 +138,28 @@
      <property name="title">
       <string>Transformation</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout">
+     <layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
       <item>
        <widget class="MatrixEditor" name="matrix" native="true"/>
       </item>
+      <item>
+       <layout class="QHBoxLayout" name="horizontalLayout">
+        <item>
+         <widget class="QPushButton" name="rotateCcw">
+          <property name="text">
+           <string>↺</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="rotateCw">
+          <property name="text">
+           <string>↻</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
      </layout>
     </widget>
    </item>

mercurial