diff options
| author | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-06 22:04:07 +0200 |
|---|---|---|
| committer | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-06 22:04:07 +0200 |
| commit | ee265d4d86c5d371d23b0e5254de5c047fee1046 (patch) | |
| tree | 98410a54643e73d56f66b58570ae565daf294f6d | |
| parent | 98522593bd49c77ce969a9bf124f2a471d4f7ce1 (diff) | |
| download | symedit-ee265d4d86c5d371d23b0e5254de5c047fee1046.tar.gz symedit-ee265d4d86c5d371d23b0e5254de5c047fee1046.zip | |
Initial commit
| -rw-r--r-- | Editor.qml | 212 | ||||
| -rw-r--r-- | clear.png | bin | 0 -> 479 bytes | |||
| -rw-r--r-- | copy.png | bin | 0 -> 390 bytes | |||
| -rw-r--r-- | main.cpp | 16 | ||||
| -rw-r--r-- | main.qml | 234 | ||||
| -rw-r--r-- | qml.qrc | 8 |
6 files changed, 470 insertions, 0 deletions
diff --git a/Editor.qml b/Editor.qml new file mode 100644 index 0000000..c6a127f --- /dev/null +++ b/Editor.qml @@ -0,0 +1,212 @@ +import QtQuick 2.9 + +Rectangle +{ + property int margin: 20 + property int units: 100 + property int max: units / 2 + property int grid: 10 + + property bool horizontal: (height < width) + property real scalexy: (horizontal ? (height - margin * 2) / units : (width - margin * 2) / units) + + property int mousex: 0 + property int mousey: 0 + + property int startx: 0 + property int starty: 0 + property bool down: false + property int endx: 0 + property int endy: 0 + + anchors.fill: parent + + MouseArea + { + anchors.fill: parent + hoverEnabled: true + + onPositionChanged: + { + mousex = Math.round((mouse.x - canvas.x) / scalexy / snap) * snap - max + mousey = max - Math.round((mouse.y - canvas.y) / scalexy / snap) * snap + + if ( mouse.x < canvas.x ) + mousex = -max + else if ( mouse.x > canvas.x + canvas.width ) + mousex = max + if ( mouse.y < canvas.y ) + mousey = max + else if ( mouse.y >= canvas.y + canvas.height ) + mousey = -max + + if ( down ) + canvas.requestPaint() + } + + onPressed: + { + if ( tool == 12 ) // polyline + { + startx = endx + starty = endy + } + else + { + startx = mousex + starty = mousey + } + down = true + } + + onReleased: + { + endx = mousex + endy = mousey + down = false + } + } + + Canvas + { + id: canvas + + width: units * scalexy; height: units * scalexy + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + function paintgrid(context) + { + context.lineWidth = 0.2 + context.strokeStyle = "gray" + context.fillStyle = "white" + + context.fillRect(0, 0, units * scalexy, units * scalexy) + + var row, col; + for ( row = 0; row <= units; row += grid ) + { + context.beginPath().moveTo(0, row * scalexy) + context.lineTo(units * scalexy, row * scalexy) + context.closePath().stroke() + } + + for ( col = 0; col <= units; col += grid ) + { + context.beginPath().moveTo(col * scalexy, 0) + context.lineTo(col * scalexy, units * scalexy) + context.closePath().stroke() + } + + context.lineWidth = 1 + + context.beginPath().moveTo(0, max * scalexy) + context.lineTo(units * scalexy, max * scalexy) + context.closePath().stroke() + + context.beginPath().moveTo(max * scalexy, 0) + context.lineTo(max * scalexy, units * scalexy) + context.closePath().stroke() + + context.strokeRect(0, 0, units * scalexy, units * scalexy) + } + + onPaint: + { + var context = getContext("2d") + + paintgrid(context) + + context.strokeStyle = "black" + context.fillStyle = "black" +// context.lineWidth = 2 + + if ( down ) + { + var deltax = Math.abs(mousex - startx), deltay = Math.abs(mousey - starty) + if ( tool > 10 && tool < 20 ) // line + { + if ( tool == 11 ) // 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 + { + context.beginPath().moveTo((startx + max) * scalexy, (max - starty) * scalexy) + context.lineTo((mousex + max) * scalexy, (max - mousey) * scalexy) + context.closePath().stroke() + } + } + else if ( tool > 20 && tool < 30 ) // rectangle + { + if ( tool == 21 ) // center + { + //## + } + else if ( tool == 22 ) // corners + { + 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) + } + if ( fill ) + context.fill() + else + context.stroke() + } + else if ( tool > 30 && tool < 40 ) // circle + { + var centerx, centery, radius + if ( tool == 31 ) // center + { + radius = Math.sqrt(deltax * deltax + deltay * deltay) + centerx = startx + centery = starty + } + else if ( tool == 32 ) // horizontal + { + radius = deltax / 2 + centerx = startx + (mousex < startx ? -radius : radius) + centery = starty + } + else if ( tool == 33 ) // vertical + { + radius = deltay / 2 + centerx = startx + centery = starty + (mousey < starty ? -radius : radius) + } + else if ( tool == 34 ) // corners + { +/* + 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() +*/ + } + if ( radius ) + { + context.ellipse((centerx + max - radius) * scalexy, (max - centery - radius) * scalexy, + radius * 2 * scalexy, radius * 2 * scalexy) + if ( fill ) + context.fill() + else + context.stroke() + } + } + else if ( tool > 40 && tool < 50 ) // text + { + if ( tool == 31 ) // text + { + //## + } + } + } + } + } +} diff --git a/clear.png b/clear.png Binary files differnew file mode 100644 index 0000000..9edf96e --- /dev/null +++ b/clear.png diff --git a/copy.png b/copy.png Binary files differnew file mode 100644 index 0000000..df34b9f --- /dev/null +++ b/copy.png diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..5298d03 --- /dev/null +++ b/main.cpp @@ -0,0 +1,16 @@ +#include <QGuiApplication> +#include <QQmlApplicationEngine> + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); + if (engine.rootObjects().isEmpty()) + return -1; + + return app.exec(); +} diff --git a/main.qml b/main.qml new file mode 100644 index 0000000..09e0bb1 --- /dev/null +++ b/main.qml @@ -0,0 +1,234 @@ +import QtQuick 2.9 +import QtQuick.Controls 1.4 +import QtQuick.Layouts 1.0 + +ApplicationWindow +{ + property alias mousex: editor.mousex + property alias mousey: editor.mousey + property real snap: 5.0 + + property int tool: 0 + property bool fill: false + + id: window + visible: true + width: 640; height: 480 + title: qsTr("Symbol editor") //%% + + menuBar: MenuBar + { + Menu + { + title: "File" //%% + MenuItem + { + text: "Open" //%% + shortcut: "Ctrl+O" + onTriggered: + { + //## + } + } + MenuItem + { + text: "Save" //%% + shortcut: "Ctrl+S" + onTriggered: + { + //## + } + } + MenuSeparator { } + MenuItem + { + text: "Exit" //%% + shortcut: "F4" + onTriggered: { Qt.quit() } + } + } + Menu + { + title: "Tool" //%% + MenuItem + { + text: "Select" //%% + checkable : true + checked: (tool == 0) + onTriggered: { tool = 0 } + } + MenuSeparator { } + MenuItem + { + text: "Line" //%% + checkable : true + checked: (tool == 11) + onTriggered: { tool = 11 } + } + MenuItem + { + text: "Polyline" //%% + checkable : true + checked: (tool == 12) + onTriggered: { tool = 12 } + } + MenuSeparator { } + MenuItem + { + text: "Rectangle Center" //%% + checkable : true + checked: (tool == 21) + onTriggered: { tool = 21 } + } + MenuItem + { + text: "Rectangle Corners" //%% + checkable : true + checked: (tool == 22) + onTriggered: { tool = 22 } + } + MenuSeparator { } + MenuItem + { + text: "Circle Center" //%% + checkable : true + checked: (tool == 31) + onTriggered: { tool = 31 } + } + MenuItem + { + text: "Circle Horizontal" //%% + checkable : true + checked: (tool == 32) + onTriggered: { tool = 32 } + } + MenuItem + { + text: "Circle Vertical" //%% + checkable : true + checked: (tool == 33) + onTriggered: { tool = 33 } + } + MenuItem + { + text: "Circle Corners" //%% + checkable : true + checked: (tool == 34) + onTriggered: { tool = 34 } + } + MenuSeparator { } + MenuItem + { + text: "Text" //%% + checkable : true + checked: (tool == 41) + onTriggered: { tool = 41 } + } + } + Menu + { + title: "Help" //%% + MenuItem + { + text: "Help" //%% + shortcut: "F1" + onTriggered: + { + //## + } + } + MenuSeparator { } + MenuItem + { + text: "About" //%% + onTriggered: + { + //## + } + } + } + } + + toolBar: ToolBar + { + RowLayout + { + anchors.fill: parent + + ToolButton { iconSource: "clear.png" } + ToolButton { iconSource: "copy.png" } + Item { Layout.fillWidth: true } + CheckBox + { + id: fillcheck + checked: fill + text: "Fill" + onClicked: { fill = !fill } + } + Label { text: "Alignment" } //%% + ComboBox + { + id: alignlist + model: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] +/* + onCurrentIndexChanged: + { + if ( currentIndex == 0 ) { snap = 1 } + else if ( currentIndex == 1 ) { snap = 2 } + else if ( currentIndex == 2 ) { snap = 5 } + else if ( currentIndex == 3 ) { snap = 10 } + } + function setsnap() + { + if ( snap == 1 ) { currentIndex = 0 } + else if ( snap == 2 ) { currentIndex = 1 } + else if ( snap == 10 ) { currentIndex = 3 } + else { currentIndex = 2 } // default 5 + } +*/ + } + Label { text: "Snap" } //%% + ComboBox + { + id: snaplist + model: [ 1, 2, 5, 10 ] + onCurrentIndexChanged: + { + if ( currentIndex == 0 ) { snap = 1 } + else if ( currentIndex == 1 ) { snap = 2 } + else if ( currentIndex == 2 ) { snap = 5 } + else if ( currentIndex == 3 ) { snap = 10 } + } + function setsnap() + { + if ( snap == 1 ) { currentIndex = 0 } + else if ( snap == 2 ) { currentIndex = 1 } + else if ( snap == 10 ) { currentIndex = 3 } + else { currentIndex = 2 } // default 5 + } + } + } + } + + Editor + { + id: editor + } + + statusBar: StatusBar + { + RowLayout + { + anchors.fill: parent + Label { Layout.minimumWidth: 40; text: " X: " + mousex } + Label { Layout.minimumWidth: 40; text: " Y: " + mousey } + Item { Layout.fillWidth: true } + } + } + + Component.onCompleted: + { + snaplist.setsnap() + fill = true + } +} @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + <file>clear.png</file> + <file>copy.png</file> + <file>Editor.qml</file> + </qresource> +</RCC> |
