aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-02-23 20:39:30 +0200
committerMikko Syrjä <mikko@3d-system.fi>2019-02-23 20:39:30 +0200
commit498b1b9a56b399225d3a70742fdcb01245aa91c4 (patch)
tree2fd8596e3e049b46aad818cbe029a48c9df3e7e0
parent07599f27937b8af9a3d3a46f17e34b51d6eada2c (diff)
downloadsymedit-498b1b9a56b399225d3a70742fdcb01245aa91c4.tar.gz
symedit-498b1b9a56b399225d3a70742fdcb01245aa91c4.zip
Implement rotations.
-rw-r--r--main.qml34
-rw-r--r--symbol.cpp17
2 files changed, 32 insertions, 19 deletions
diff --git a/main.qml b/main.qml
index f3d2961..14e87f8 100644
--- a/main.qml
+++ b/main.qml
@@ -130,39 +130,37 @@ ApplicationWindow
RowLayout
{
height: 32
- Item { Layout.fillWidth: true }
- Label { text: qsTr("Fill") } //%%
- ComboBox
- {
- id: filllist
- implicitWidth: 60
- model: [ 0, 1, 2 ]
- onCurrentIndexChanged: { fillitem = currentIndex; editor.update() }
- function setFill() { currentIndex = fillitem }
- }
- BarSeparator { }
Label { text: qsTr("Snap") } //%%
ComboBox
{
id: snaplist
implicitWidth: 60
- model: [ 1, 2, 5, 10 ]
+ model: [ 1, 5, 10 ]
onCurrentIndexChanged:
{
if ( currentIndex == 0 ) { snapgrid = 1 }
- else if ( currentIndex == 1 ) { snapgrid = 2 }
- else if ( currentIndex == 2 ) { snapgrid = 5 }
- else if ( currentIndex == 3 ) { snapgrid = 10 }
+ else if ( currentIndex == 1 ) { snapgrid = 5 }
+ else if ( currentIndex == 2 ) { snapgrid = 10 }
}
function setSnap()
{
if ( snapgrid == 1 ) { currentIndex = 0 }
- else if ( snapgrid == 2 ) { currentIndex = 1 }
- else if ( snapgrid == 10 ) { currentIndex = 3 }
- else { currentIndex = 2 } // default 5
+ else if ( snapgrid == 10 ) { currentIndex = 2 }
+ else { currentIndex = 1 } // default 5
}
}
BarSeparator { }
+ Item { Layout.fillWidth: true }
+ Label { text: qsTr("Fill") } //%%
+ ComboBox
+ {
+ id: filllist
+ implicitWidth: 60
+ model: [ 0, 1, 2 ]
+ onCurrentIndexChanged: { fillitem = currentIndex; editor.update() }
+ function setFill() { currentIndex = fillitem }
+ }
+ BarSeparator { }
Label { text: qsTr("Line width") } //%%
ComboBox
{
diff --git a/symbol.cpp b/symbol.cpp
index 11d9791..f95ba71 100644
--- a/symbol.cpp
+++ b/symbol.cpp
@@ -238,5 +238,20 @@ const SymEditSymbol::Item& SymEditSymbol::GetItem(int index) const
*/
void SymEditSymbol::RotateSymbol(int dir)
{
- //##
+ auto rotate = [](QPoint& point, int dir)
+ {
+ double length = sqrt(point.x() * point.x() + point.y() * point.y());
+ double angle = atan2(point.y(), point.x());
+ angle += (dir > 0 ? -M_PI / 2.0 : M_PI / 2.0);
+ double x = cos(angle) * length, y = sin(angle) * length;
+ point.setX(static_cast<int>(x + (x > 0.0 ? 0.5 : -0.5)));
+ point.setY(static_cast<int>(y + (y > 0.0 ? 0.5 : -0.5)));
+ };
+
+ for ( auto& item : Items )
+ {
+ rotate(item.Point, dir);
+ if ( item.Operation != 'R' )
+ rotate(item.Value, dir);
+ }
}