aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikko Syrjä <mikko@3d-system.fi>2019-02-06 23:25:24 +0200
committerMikko Syrjä <mikko@3d-system.fi>2019-02-06 23:25:24 +0200
commitf56d81d87cd5f44995ddef65e1d017b33587a798 (patch)
tree39d41502a749d888b51f018dde3a8c9c4b4a2980
parentee265d4d86c5d371d23b0e5254de5c047fee1046 (diff)
downloadsymedit-f56d81d87cd5f44995ddef65e1d017b33587a798.tar.gz
symedit-f56d81d87cd5f44995ddef65e1d017b33587a798.zip
Added tool enumerations.
-rw-r--r--Editor.qml56
-rw-r--r--main.qml56
-rw-r--r--symedit.pro3
3 files changed, 71 insertions, 44 deletions
diff --git a/Editor.qml b/Editor.qml
index c6a127f..0c14ef6 100644
--- a/Editor.qml
+++ b/Editor.qml
@@ -2,6 +2,22 @@ import QtQuick 2.9
Rectangle
{
+ enum Tool
+ {
+ Select = 1,
+ Line = 11,
+ Polyline = 12,
+ RectangleCenter = 21,
+ RectangleCorner = 22,
+ CircleCenter = 31,
+ CircleHorizontal = 32,
+ CircleVertical = 33,
+ CircleCorner = 34,
+ ArcSemicircle = 41,
+ ArcQuarter = 42,
+ Text = 51
+ }
+
property int margin: 20
property int units: 100
property int max: units / 2
@@ -46,7 +62,7 @@ Rectangle
onPressed:
{
- if ( tool == 12 ) // polyline
+ if ( tool === Editor.Tool.Polyline )
{
startx = endx
starty = endy
@@ -123,16 +139,19 @@ Rectangle
if ( down )
{
- var deltax = Math.abs(mousex - startx), deltay = Math.abs(mousey - starty)
+ var cornerx = (mousex < startx ? mousex : startx)
+ var cornery = (mousey > starty ? mousey : starty)
+ var deltax = Math.abs(mousex - startx)
+ var deltay = Math.abs(mousey - starty)
if ( tool > 10 && tool < 20 ) // line
{
- if ( tool == 11 ) // line
+ if ( tool === Editor.Tool.Line )
{
context.beginPath().moveTo((startx + max) * scalexy, (max - starty) * scalexy)
context.lineTo((mousex + max) * scalexy, (max - mousey) * scalexy)
context.closePath().stroke()
}
- else if ( tool == 12 ) // polyline
+ else if ( tool === Editor.Tool.Polyline )
{
context.beginPath().moveTo((startx + max) * scalexy, (max - starty) * scalexy)
context.lineTo((mousex + max) * scalexy, (max - mousey) * scalexy)
@@ -141,17 +160,14 @@ Rectangle
}
else if ( tool > 20 && tool < 30 ) // rectangle
{
- if ( tool == 21 ) // center
+ if ( tool === Editor.Tool.RectangleCenter )
{
//##
}
- else if ( tool == 22 ) // corners
+ else if ( tool === Editor.Tool.RectangleCorner )
{
- var cornerx = (mousex < startx ? mousex : startx)
- var cornery = (mousey < starty ? mousey : starty)
- var delta = (deltax < deltay ? deltax : deltay)
context.rect((cornerx + max) * scalexy, (max - cornery) * scalexy,
- delta * scalexy, delta * scalexy)
+ deltax * scalexy, deltay * scalexy)
}
if ( fill )
context.fill()
@@ -161,33 +177,29 @@ Rectangle
else if ( tool > 30 && tool < 40 ) // circle
{
var centerx, centery, radius
- if ( tool == 31 ) // center
+ if ( tool === Editor.Tool.CircleCenter )
{
radius = Math.sqrt(deltax * deltax + deltay * deltay)
centerx = startx
centery = starty
}
- else if ( tool == 32 ) // horizontal
+ else if ( tool === Editor.Tool.CircleHorizontal )
{
radius = deltax / 2
centerx = startx + (mousex < startx ? -radius : radius)
centery = starty
}
- else if ( tool == 33 ) // vertical
+ else if ( tool === Editor.Tool.CircleVertical )
{
radius = deltay / 2
centerx = startx
centery = starty + (mousey < starty ? -radius : radius)
}
- else if ( tool == 34 ) // corners
+ else if ( tool === Editor.Tool.CircleCorner )
{
-/*
- var cornerx = (mousex < startx ? mousex : startx)
- var cornery = (mousey < starty ? mousey : starty)
- var delta = (deltax < deltay ? deltax : deltay)
- context.ellipse((cornerx + max) * scalexy, (max - cornery) * scalexy,
- delta * scalexy, delta * scalexy).stroke()
-*/
+ radius = (deltax < deltay ? deltax : deltay) / 2
+ centerx = cornerx + radius
+ centery = cornery - radius
}
if ( radius )
{
@@ -201,7 +213,7 @@ Rectangle
}
else if ( tool > 40 && tool < 50 ) // text
{
- if ( tool == 31 ) // text
+ if ( tool === Editor.Tool.Texts )
{
//##
}
diff --git a/main.qml b/main.qml
index 09e0bb1..36f0d5f 100644
--- a/main.qml
+++ b/main.qml
@@ -54,75 +54,90 @@ ApplicationWindow
{
text: "Select" //%%
checkable : true
- checked: (tool == 0)
- onTriggered: { tool = 0 }
+ checked: (tool === Editor.Tool.Select)
+ onTriggered: { tool = Editor.Tool.Select }
}
MenuSeparator { }
MenuItem
{
text: "Line" //%%
checkable : true
- checked: (tool == 11)
- onTriggered: { tool = 11 }
+ checked: (tool === Editor.Tool.Line)
+ onTriggered: { tool = Editor.Tool.Line }
}
MenuItem
{
text: "Polyline" //%%
checkable : true
- checked: (tool == 12)
- onTriggered: { tool = 12 }
+ checked: (tool === Editor.Tool.Polyline)
+ onTriggered: { tool = Editor.Tool.Polyline }
}
MenuSeparator { }
MenuItem
{
text: "Rectangle Center" //%%
checkable : true
- checked: (tool == 21)
- onTriggered: { tool = 21 }
+ checked: (tool === Editor.Tool.RectangleCenter)
+ onTriggered: { tool = Editor.Tool.RectangleCenter }
}
MenuItem
{
text: "Rectangle Corners" //%%
checkable : true
- checked: (tool == 22)
- onTriggered: { tool = 22 }
+ checked: (tool === Editor.Tool.RectangleCorner)
+ onTriggered: { tool = Editor.Tool.RectangleCorner }
}
MenuSeparator { }
MenuItem
{
text: "Circle Center" //%%
checkable : true
- checked: (tool == 31)
- onTriggered: { tool = 31 }
+ checked: (tool === Editor.Tool.CircleCenter)
+ onTriggered: { tool = Editor.Tool.CircleCenter }
}
MenuItem
{
text: "Circle Horizontal" //%%
checkable : true
- checked: (tool == 32)
- onTriggered: { tool = 32 }
+ checked: (tool === Editor.Tool.CircleHorizontal)
+ onTriggered: { tool = Editor.Tool.CircleHorizontal }
}
MenuItem
{
text: "Circle Vertical" //%%
checkable : true
- checked: (tool == 33)
- onTriggered: { tool = 33 }
+ checked: (tool === Editor.Tool.CircleVertical)
+ onTriggered: { tool = Editor.Tool.CircleVertical }
}
MenuItem
{
text: "Circle Corners" //%%
checkable : true
- checked: (tool == 34)
- onTriggered: { tool = 34 }
+ checked: (tool === Editor.Tool.CircleCorner)
+ onTriggered: { tool = Editor.Tool.CircleCorner }
+ }
+ MenuSeparator { }
+ MenuItem
+ {
+ text: "Semicircle" //%%
+ checkable : true
+ checked: (tool === Editor.Tool.ArcSemicircle)
+ onTriggered: { tool = Editor.Tool.ArcSemicircle }
+ }
+ MenuItem
+ {
+ text: "Quarter circle" //%%
+ checkable : true
+ checked: (tool === Editor.Tool.ArcQuarter)
+ onTriggered: { tool = Editor.Tool.ArcQuarter }
}
MenuSeparator { }
MenuItem
{
text: "Text" //%%
checkable : true
- checked: (tool == 41)
- onTriggered: { tool = 41 }
+ checked: (tool === Editor.Tool.Text)
+ onTriggered: { tool = Editor.Tool.Text }
}
}
Menu
@@ -230,5 +245,6 @@ ApplicationWindow
{
snaplist.setsnap()
fill = true
+ tool = Editor.Tool.Select
}
}
diff --git a/symedit.pro b/symedit.pro
index a517b75..b5bab04 100644
--- a/symedit.pro
+++ b/symedit.pro
@@ -12,8 +12,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
-SOURCES += \
- main.cpp
+SOURCES += main.cpp
RESOURCES += qml.qrc