diff options
| author | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-22 00:11:36 +0200 |
|---|---|---|
| committer | Mikko Syrjä <mikko@3d-system.fi> | 2019-02-22 00:11:36 +0200 |
| commit | cddb64f0238e9a8a0975732b925cbaae211a1b65 (patch) | |
| tree | 387b97d281342d32a36416d75e7972dc50b6bfe1 | |
| parent | cc5cce3e56ac38c2c59d80fd61a52c7ec5401175 (diff) | |
| download | symedit-cddb64f0238e9a8a0975732b925cbaae211a1b65.tar.gz symedit-cddb64f0238e9a8a0975732b925cbaae211a1b65.zip | |
Improved tooltips and added zooming.
| -rw-r--r-- | .editorconfig | 2 | ||||
| -rw-r--r-- | BarTool.qml | 31 | ||||
| -rw-r--r-- | Editor.qml | 86 | ||||
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | ToolTip.qml (renamed from ToolTip2.qml) | 20 | ||||
| -rw-r--r-- | ToolTip1.qml | 83 | ||||
| -rw-r--r-- | TooltipCreator.js | 2 | ||||
| -rw-r--r-- | image/copy_icon&48.png (renamed from image/clipboard_copy_icon&48.png) | bin | 3902 -> 3902 bytes | |||
| -rw-r--r-- | image/cursor_icon&48.png (renamed from image/cursor_arrow_icon&48.png) | bin | 3875 -> 3875 bytes | |||
| -rw-r--r-- | image/cut_icon&48.png (renamed from image/clipboard_cut_icon&48.png) | bin | 4656 -> 4656 bytes | |||
| -rw-r--r-- | image/open_icon&48.png (renamed from image/folder_open_icon&48.png) | bin | 3512 -> 3512 bytes | |||
| -rw-r--r-- | image/paste_icon&48.png (renamed from image/clipboard_past_icon&48.png) | bin | 3941 -> 3941 bytes | |||
| -rw-r--r-- | image/redo_icon&48.png | bin | 0 -> 3822 bytes | |||
| -rw-r--r-- | image/undo_icon&48.png | bin | 0 -> 3789 bytes | |||
| -rw-r--r-- | main.qml | 102 | ||||
| -rw-r--r-- | qml.qrc | 15 | ||||
| -rw-r--r-- | symbol.cpp | 6 | ||||
| -rw-r--r-- | symbol.h | 2 | ||||
| -rw-r--r-- | symedit.cpp | 7 | ||||
| -rw-r--r-- | symedit.h | 2 | ||||
| -rw-r--r-- | symedit.pro | 3 |
21 files changed, 199 insertions, 175 deletions
diff --git a/.editorconfig b/.editorconfig index 16d9e95..a8cac73 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true end_of_line = lf insert_final_newline = true -[*.{cpp,h,qml,md,pro}] +[*.{cpp,h,qml,js,md,pro}] charset = utf-8 indent_style = tab indent_size = 4 diff --git a/BarTool.qml b/BarTool.qml index 1898c3d..dadd70b 100644 --- a/BarTool.qml +++ b/BarTool.qml @@ -7,7 +7,6 @@ ToolButton { property string image property int tool: 0 - property var popup implicitHeight: 32 implicitWidth: 32 @@ -17,37 +16,11 @@ ToolButton source: image anchors { fill: parent; margins: 4 } } -/* - ToolTip1 - { - id: tooltip1 - width: 200 - target: parent - text: tooltip - } -*/ -/* - MouseArea - { - anchors.fill: parent - hoverEnabled: true - propagateComposedEvents: true - - onEntered: - { - popup = TooltipCreator.create(tooltip, this) - popup.show() - } - onExited: - { - if ( popup !== null ) - popup.hide() - } - } -*/ onHoveredChanged: { + if ( popup !== null ) + popup.hide() popup = TooltipCreator.create(tooltip, this) popup.show() } @@ -26,12 +26,11 @@ Rectangle property int units: 100 property int max: units / 2 property int grid: 10 - property int offset: 10 + property int offset: 5 property int total: units + offset * 2 - property int margin: 20 property bool horizontal: (height < width) - property real scalexy: (horizontal ? (height - margin * 2) / total : (width - margin * 2) / total) + property real scalexy: (horizontal ? height / total : width / total) * zoomscale property int startx: 0 property int starty: 0 @@ -83,20 +82,49 @@ Rectangle { endx = mousex endy = mousey - if ( tool === Editor.Tool.Line ) + if ( startx != endx && starty != endy ) { - manager.addPointItem(Editor.Operation.Line, Qt.point(startx, starty), Qt.point(endx, endy), false) - symbol = manager.getSymbol() - } - else if ( tool === Editor.Tool.RectCenter || tool === Editor.Tool.RectCorner ) - { - if ( tool === Editor.Tool.RectCenter ) + if ( tool === Editor.Tool.Line ) + { + manager.addPointItem(Editor.Operation.Line, Qt.point(startx, starty), Qt.point(endx, endy), false) + symbol = manager.getSymbol() + } + else if ( tool === Editor.Tool.RectCenter || tool === Editor.Tool.RectCorner ) { - startx -= (endx - startx) - starty -= (endy - starty) + if ( tool === Editor.Tool.RectCenter ) + { + startx -= (endx - startx) + starty -= (endy - starty) + } + manager.addPointItem(Editor.Operation.Rectangle, Qt.point(startx, starty), Qt.point(endx, endy), fillitem) + symbol = manager.getSymbol() + } + else if ( tool > 30 && tool < 40 ) // circle + { + var deltax = Math.abs(mousex - startx) + var deltay = Math.abs(mousey - starty) + var centerx, centery, radius + if ( tool === Editor.Tool.CircleCorner ) + { + radius = (deltax < deltay ? deltax : deltay) / 2 + centerx = (startx + endx) / 2 + centery = (starty + endy) / 2 + } + else if ( tool === Editor.Tool.CircleRadius ) + { + radius = Math.sqrt(deltax * deltax + deltay * deltay) / 2 + centerx = (startx + endx) / 2 + centery = (starty + endy) / 2 + } + else if ( tool === Editor.Tool.CircleCenter ) + { + radius = Math.sqrt(deltax * deltax + deltay * deltay) + centerx = startx + centery = starty + } + manager.addValueItem(Editor.Operation.Circle, Qt.point(centerx, centery), radius, fillitem) + symbol = manager.getSymbol() } - manager.addPointItem(Editor.Operation.Rectangle, Qt.point(startx, starty), Qt.point(endx, endy), fillitem) - symbol = manager.getSymbol() } } down = false @@ -145,17 +173,20 @@ Rectangle paintrect(context, Qt.point(-max - offset, max + offset), Qt.size(total, total), true) - var row, col; - for ( row = -max; row <= max; row += grid ) - paintline(context, Qt.point(-max, row), Qt.point(max, row)) - for ( col = -max; col <= max; col += grid ) - paintline(context, Qt.point(col, -max), Qt.point(col, max)) + if ( viewgrid ) + { + var row, col; + for ( row = -max; row <= max; row += grid ) + paintline(context, Qt.point(-max, row), Qt.point(max, row)) + for ( col = -max; col <= max; col += grid ) + paintline(context, Qt.point(col, -max), Qt.point(col, max)) - context.lineWidth = 1 - paintline(context, Qt.point(0, -max), Qt.point(0, max)) - paintline(context, Qt.point(-max, 0), Qt.point(max, 0)) + context.lineWidth = 1 + paintline(context, Qt.point(0, -max), Qt.point(0, max)) + paintline(context, Qt.point(-max, 0), Qt.point(max, 0)) - paintrect(context, Qt.point(-max, max), Qt.size(units, units), false) + paintrect(context, Qt.point(-max, max), Qt.size(units, units), false) + } } function paintsymbol(context) @@ -166,10 +197,7 @@ Rectangle var index, count = manager.getItemCount() for ( index = 0; index < count; index++ ) { - if ( index === active ) - context.strokeStyle = "red" - else - context.strokeStyle = "black" + context.strokeStyle = (index === active ? "red" : "black") var operation = manager.getItemOperation(index) var point, position = manager.getItemPosition(index) @@ -237,8 +265,8 @@ Rectangle if ( tool === Editor.Tool.CircleCorner ) { radius = (deltax < deltay ? deltax : deltay) / 2 - centerx = cornerx + radius - centery = cornery - radius + centerx = (startx + mousex) / 2 + centery = (starty + mousey) / 2 } else if ( tool === Editor.Tool.CircleRadius ) { @@ -10,3 +10,16 @@ krita: transparent line width: 6px brush: basic-1 + +Windows deployment: + +c:\Local\Qt\5.12.0\msvc2017_64\bin\windeployqt.exe + --release + --qmldir ../../symedit + --no-translations + --no-compiler-runtime + --no-webkit2 + --no-angle + --no-opengl-sw + . + diff --git a/ToolTip2.qml b/ToolTip.qml index 075925b..e8b09c2 100644 --- a/ToolTip2.qml +++ b/ToolTip.qml @@ -14,13 +14,13 @@ Rectangle function show() { - state = "showing" - if ( hideTimer.running ) - hideTimer.restart() + showTimer.start() } function hide() { + if ( showTimer.running ) + showTimer.stop() if ( hideTimer.running ) hideTimer.stop() state = "hidden" @@ -51,8 +51,20 @@ Rectangle Timer { + id: showTimer + interval: 1000 + onTriggered: + { + state = "showing" + if ( hideTimer.running ) + hideTimer.restart() + } + } + + Timer + { id: hideTimer - interval: 3000 + interval: 1000 onTriggered: hide() } diff --git a/ToolTip1.qml b/ToolTip1.qml deleted file mode 100644 index 868b4a4..0000000 --- a/ToolTip1.qml +++ /dev/null @@ -1,83 +0,0 @@ -import QtQuick 2.0 -import QtQuick.Controls 1.1 -import QtGraphicalEffects 1.0 - -Item -{ - id: toolTipRoot - width: toolTip.contentWidth - height: toolTipContainer.height - visible: false - clip: false - z: 30 - - property alias text: toolTip.text - property alias radius: content.radius - property alias backgroundColor: content.color - property alias textColor: toolTip.color - property alias font: toolTip.font - property var target: null - - function onMouseHover(x, y) - { - var obj = toolTipRoot.target.mapToItem(toolTipRoot.parent, x, y); - toolTipRoot.x = obj.x; - toolTipRoot.y = obj.y + 5; - } - - function onVisibleStatus(flag) - { - toolTipRoot.visible = flag; - } - - Component.onCompleted: - { - var itemParent = toolTipRoot.target; - - var newObject = Qt.createQmlObject('import QtQuick 2.0; MouseArea {signal mouserHover(int x, int y); signal showChanged(bool flag); anchors.fill:parent; hoverEnabled: true; onPositionChanged: {mouserHover(mouseX, mouseY)} onEntered: {showChanged(true)} onExited:{showChanged(false)} onClicked:{parent.focus = true}}', - itemParent, "mouseItem"); - newObject.mouserHover.connect(onMouseHover); - newObject.showChanged.connect(onVisibleStatus); - } - - Item - { - id: toolTipContainer - z: toolTipRoot.z + 1 - width: content.width + (2*toolTipShadow.radius) - height: content.height + (2*toolTipShadow.radius) - - Rectangle - { - id: content - anchors.centerIn: parent - width: toolTipRoot.width - height: toolTip.contentHeight + 10 - radius: 3 - - Text - { - id: toolTip - anchors {fill: parent; margins: 5} - wrapMode: Text.WrapAnywhere - } - } - } - - DropShadow - { - id: toolTipShadow - z: toolTipRoot.z + 1 - anchors.fill: source - cached: true - horizontalOffset: 4 - verticalOffset: 4 - radius: 8.0 - samples: 16 - color: "#80000000" - smooth: true - source: toolTipContainer - } - - Behavior on visible { NumberAnimation { duration: 200 }} -} diff --git a/TooltipCreator.js b/TooltipCreator.js index 58a0c3d..49a71e3 100644 --- a/TooltipCreator.js +++ b/TooltipCreator.js @@ -1,4 +1,4 @@ -var component = Qt.createComponent("ToolTip2.qml"); +var component = Qt.createComponent("ToolTip.qml"); function create(text, parent, properties) { diff --git a/image/clipboard_copy_icon&48.png b/image/copy_icon&48.png Binary files differindex f1387b8..f1387b8 100644 --- a/image/clipboard_copy_icon&48.png +++ b/image/copy_icon&48.png diff --git a/image/cursor_arrow_icon&48.png b/image/cursor_icon&48.png Binary files differindex 83fcad8..83fcad8 100644 --- a/image/cursor_arrow_icon&48.png +++ b/image/cursor_icon&48.png diff --git a/image/clipboard_cut_icon&48.png b/image/cut_icon&48.png Binary files differindex 82be5f4..82be5f4 100644 --- a/image/clipboard_cut_icon&48.png +++ b/image/cut_icon&48.png diff --git a/image/folder_open_icon&48.png b/image/open_icon&48.png Binary files differindex 7cdc921..7cdc921 100644 --- a/image/folder_open_icon&48.png +++ b/image/open_icon&48.png diff --git a/image/clipboard_past_icon&48.png b/image/paste_icon&48.png Binary files differindex 4d90cc0..4d90cc0 100644 --- a/image/clipboard_past_icon&48.png +++ b/image/paste_icon&48.png diff --git a/image/redo_icon&48.png b/image/redo_icon&48.png Binary files differnew file mode 100644 index 0000000..4486db1 --- /dev/null +++ b/image/redo_icon&48.png diff --git a/image/undo_icon&48.png b/image/undo_icon&48.png Binary files differnew file mode 100644 index 0000000..13bad19 --- /dev/null +++ b/image/undo_icon&48.png @@ -7,13 +7,18 @@ ApplicationWindow property int mousex: 0 property int mousey: 0 + property bool viewgrid: true + property real zoomscale: 1.0 + property real zoomstep: 1.3 + property bool fillitem: false - property int alignment: 1 property real linewidth: 1 + property int alignment: 1 property int snapgrid: 1 property int tool: 0 property string symbol + property var popup: null id: window visible: false @@ -32,6 +37,9 @@ ApplicationWindow Menu { title: qsTr("Edit") //%% + MenuItem { text: qsTr("Undo"); shortcut: "Ctrl+Z"; onTriggered: undo() } //%% + MenuItem { text: qsTr("Redo"); shortcut: "Ctrl+Y"; onTriggered: redo() } //%% + MenuSeparator { } MenuItem { text: qsTr("Cut"); shortcut: "Ctrl+X"; onTriggered: cut() } //%% MenuItem { text: qsTr("Copy"); shortcut: "Ctrl+C"; onTriggered: copy() } //%% MenuItem { text: qsTr("Paste"); shortcut: "Ctrl+V"; onTriggered: paste() } //%% @@ -43,6 +51,20 @@ ApplicationWindow } Menu { + title: qsTr("View") //%% + MenuItem { text: qsTr("Zoom In"); shortcut: "Ctrl++"; onTriggered: zoom(1) } //%% + MenuItem { text: qsTr("Zoom Out"); shortcut: "Ctrl+-"; onTriggered: zoom(-1) } //%% + MenuItem { text: qsTr("Zoom All"); shortcut: "Ctrl+0"; onTriggered: zoom(0) } //%% + MenuSeparator { } + MenuItem + { + text: qsTr("Grid"); shortcut: "Ctrl+G" //%% + checkable : true; checked: viewgrid + onTriggered: grid() + } + } + Menu + { title: qsTr("Tool") //%% MenuTool { text: qsTr("Select"); tool: Editor.Tool.Select } //%% MenuSeparator { } @@ -77,17 +99,20 @@ ApplicationWindow { height: 32 z: 10 - BarTool { image: "image/folder_open_icon&48.png"; tooltip: "Open File"; onClicked: open() } //%% - BarTool { image: "image/save_icon&48.png"; tooltip: "Save File"; onClicked: save() } //%% + BarTool { image: "image/open_icon&48.png"; tooltip: "Open File"; onClicked: open() } //%% + BarTool { image: "image/save_icon&48.png"; tooltip: "Save File"; onClicked: save() } //%% + BarSeparator { } + BarTool { image: "image/undo_icon&48.png"; tooltip: "Undo Edit"; onClicked: undo() } //%% + BarTool { image: "image/redo_icon&48.png"; tooltip: "Redo Edit"; onClicked: redo() } //%% + BarTool { image: "image/cut_icon&48.png"; tooltip: "Cut Symbol"; onClicked: cut() } //%% + BarTool { image: "image/copy_icon&48.png"; tooltip: "Copy Symbol"; onClicked: copy() } //%% + BarTool { image: "image/paste_icon&48.png"; tooltip: "Paste symbol"; onClicked: paste() } //%% BarSeparator { } - BarTool { image: "image/clipboard_cut_icon&48.png"; tooltip: "Cut Symbol"; onClicked: cut() } //%% - BarTool { image: "image/clipboard_copy_icon&48.png"; tooltip: "Copy Symbol"; onClicked: copy() } //%% - BarTool { image: "image/clipboard_past_icon&48.png"; tooltip: "Paste symbol"; onClicked: paste() } //%% - BarTool { image: "image/rotate_right.png"; tooltip: "Rotate right"; onClicked: rotate(1) } //%% - BarTool { image: "image/rotate_left.png"; tooltip: "Rotate left"; onClicked: rotate(-1) } //%% - BarTool { image: "image/delete.png"; tooltip: "Delete item"; onClicked: remove() } //%% + BarTool { image: "image/rotate_right.png"; tooltip: "Rotate right"; onClicked: rotate(1) } //%% + BarTool { image: "image/rotate_left.png"; tooltip: "Rotate left"; onClicked: rotate(-1) } //%% + BarTool { image: "image/delete.png"; tooltip: "Delete item"; onClicked: remove() } //%% BarSeparator { } - BarTool { image: "image/cursor_arrow_icon&48.png"; tooltip: "Select item"; tool: Editor.Tool.Select } //%% + BarTool { image: "image/cursor_icon&48.png"; tooltip: "Select item"; tool: Editor.Tool.Select } //%% BarSeparator { } BarTool { image: "image/polyline.png"; tooltip: "Straight Line"; tool: Editor.Tool.Line } //%% BarSeparator { } @@ -116,6 +141,7 @@ ApplicationWindow ComboBox { id: snaplist + implicitWidth: 60 model: [ 1, 2, 5, 10 ] onCurrentIndexChanged: { @@ -137,6 +163,7 @@ ApplicationWindow ComboBox { id: widthlist + implicitWidth: 60 model: [ 1, 2, 3, 4, 5 ] onCurrentIndexChanged: { linewidth = currentIndex + 1; editor.update() } function setWidth() { currentIndex = linewidth - 1 } @@ -146,10 +173,20 @@ ApplicationWindow ComboBox { id: alignlist + implicitWidth: 60 model: [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] onCurrentIndexChanged: { alignment = currentIndex + 1 } function setAlign() { currentIndex = alignment - 1 } } + BarSeparator { } + Label { text: qsTr("Text") } //%% + TextField + { + id: textfield + implicitWidth: 120 + + + } } } } @@ -212,6 +249,39 @@ ApplicationWindow } + function zoom(dir) + { + if ( dir === 0 ) // all + zoomscale = 1.0 + else if ( dir > 0 ) // in + { + if ( (zoomscale *= zoomstep) > 1.0 ) + zoomscale = 1.0 + } + else // out + { + if ( (zoomscale /= zoomstep) < 0.1 ) + zoomscale = 0.1 + } + editor.update() + } + + function grid() + { + viewgrid = !viewgrid + editor.update() + } + + function undo() + { + //## + } + + function redo() + { + //## + } + function cut() { manager.cutClipboard(); @@ -233,15 +303,9 @@ ApplicationWindow function rotate(dir) { - if ( dir > 0 ) // right - { - - - } - else // left - { - - } + manager.rotateSymbol(dir) + symbol = manager.getSymbol() + editor.update() } function remove() @@ -11,18 +11,19 @@ <file>image/circle_corner.png</file> <file>image/circle_radius.png</file> <file>image/circle_center.png</file> - <file>image/clipboard_copy_icon&48.png</file> - <file>image/clipboard_cut_icon&48.png</file> - <file>image/clipboard_past_icon&48.png</file> <file>image/rotate_left.png</file> <file>image/rotate_right.png</file> - <file>image/folder_open_icon&48.png</file> <file>image/save_icon&48.png</file> <file>image/text.png</file> <file>image/delete.png</file> - <file>image/cursor_arrow_icon&48.png</file> - <file>ToolTip1.qml</file> - <file>ToolTip2.qml</file> + <file>ToolTip.qml</file> <file>TooltipCreator.js</file> + <file>image/redo_icon&48.png</file> + <file>image/undo_icon&48.png</file> + <file>image/copy_icon&48.png</file> + <file>image/cursor_icon&48.png</file> + <file>image/cut_icon&48.png</file> + <file>image/paste_icon&48.png</file> + <file>image/open_icon&48.png</file> </qresource> </RCC> @@ -232,3 +232,9 @@ const SymEditSymbol::Item& SymEditSymbol::GetItem(int index) const return Items.at(static_cast<size_t>(index)); } +// +void SymEditSymbol::RotateSymbol(int dir) +{ + //## +} + @@ -43,6 +43,8 @@ public: int GetItemCount() const; const Item& GetItem(int index) const; + void RotateSymbol(int dir); + private: std::vector<Item> Items; //!< Symbol items. diff --git a/symedit.cpp b/symedit.cpp index e350a55..83fb7ea 100644 --- a/symedit.cpp +++ b/symedit.cpp @@ -58,7 +58,7 @@ SymEditManager::SymEditManager(QObject* parent) : QObject(parent) { Settings.Load(); - Symbol.Load("U00,00;R50;U-34,-34;D34,34;U-34,34;D34,-34;"); //## + Symbol.Load("U00,00;R50;U-35,-35;D35,35;U-35,35;D35,-35;"); //## } //! Set window initialized. @@ -295,4 +295,9 @@ void SymEditManager::pasteClipboard() Symbol.Load(clipboard->text()); } +// +void SymEditManager::rotateSymbol(int dir) +{ + Symbol.RotateSymbol(dir); +} @@ -82,6 +82,8 @@ public: Q_INVOKABLE void copyClipboard() const; Q_INVOKABLE void pasteClipboard(); + Q_INVOKABLE void rotateSymbol(int dir); + private: bool Initialized = false; //!< Initialization mutex. SymEditSymbol Symbol; //!< Current symbol. diff --git a/symedit.pro b/symedit.pro index 4fd41fc..e86d271 100644 --- a/symedit.pro +++ b/symedit.pro @@ -16,7 +16,8 @@ SOURCES += main.cpp \ symedit.cpp \ symbol.cpp -RESOURCES += qml.qrc +RESOURCES += \ + qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = |
