From 4afe0d4d634139e2226583939d518259f828c3cb Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Sun, 15 Aug 2021 01:18:13 +0200 Subject: [PATCH] Finishing position picker for objects having a position. --- .../ad5001/LogarithmPlotter/GreetScreen.qml | 2 +- .../LogarithmPlotter/LogarithmPlotter.qml | 1 + .../ObjectLists/ObjectLists.qml | 28 ++++++++++++- .../LogarithmPlotter/PickLocationOverlay.qml | 42 +++++++++++++++---- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/GreetScreen.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/GreetScreen.qml index 22cdb20..51d50ef 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/GreetScreen.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/GreetScreen.qml @@ -35,7 +35,7 @@ Popup { height: logo.height width: logo.width + 10 + welcomeText.width anchors.top: parent.top - anchors.topMargin: 50 + anchors.topMargin: (parent.width-width)/2 anchors.horizontalCenter: parent.horizontalCenter Image { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 1987350..9a7e6b2 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -155,6 +155,7 @@ ApplicationWindow { } PickLocationOverlay { + id: positionPicker anchors.fill: parent canvas: parent } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml index 0b48846..63db337 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/ObjectLists/ObjectLists.qml @@ -120,6 +120,32 @@ ListView { } } + Button { + id: pointerButton + width: parent.height - 10 + height: width + anchors.right: deleteButton.left + anchors.rightMargin: 5 + anchors.topMargin: 5 + icon.name: 'position' + property bool hasXProp: Objects.types[objType].properties().hasOwnProperty('x') + property bool hasYProp: Objects.types[objType].properties().hasOwnProperty('y') + visible: hasXProp || hasYProp + ToolTip.visible: hovered + ToolTip.text: 'Set ' + Objects.types[objType].displayType() + ' position.' + + onClicked: { + positionPicker.objType = objType + positionPicker.objName = Objects.currentObjects[objType][index].name + positionPicker.pickX = hasXProp + positionPicker.pickY = hasYProp + positionPicker.propertyX = 'x' + positionPicker.propertyY = 'y' + positionPicker.visible = true + + } + } + Button { id: deleteButton width: parent.height - 10 @@ -131,7 +157,7 @@ ListView { onClicked: { history.addToHistory(new HistoryLib.DeleteObject( - objEditor.obj.name, objEditor.objType, objEditor.obj.export() + Objects.currentObjects[objType][index].name, objType, Objects.currentObjects[objType][index].export() )) Objects.currentObjects[objType][index].delete() Objects.currentObjects[objType].splice(index, 1) diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml index c9122a1..1de03dc 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml @@ -33,6 +33,7 @@ Item { property bool pickX: true property string propertyX: 'x' property string propertyY: 'y' + property alias precision: precisionSlider.value Rectangle { color: sysPalette.window @@ -47,7 +48,7 @@ Item { cursorShape: Qt.CrossCursor onClicked: { if(parent.pickX) { - var newValue = canvas.px2x(picker.mouseX).toFixed(2) + var newValue = canvas.px2x(picker.mouseX).toFixed(parent.precision) newValue = { 'Expression': () => new MathLib.Expression(newValue), 'number': () => parseFloat(newValue) @@ -61,7 +62,7 @@ Item { objectLists.update() } if(parent.pickY) { - var newValue = canvas.px2y(picker.mouseY).toFixed(2) + var newValue = canvas.px2y(picker.mouseY).toFixed(parent.precision) newValue = { 'Expression': () => new MathLib.Expression(newValue), 'number': () => parseFloat(newValue) @@ -78,11 +79,33 @@ Item { } } + Row { + height: precisionSlider.height + Text { + text: " Pointer precision: " + color: 'black' + anchors.verticalCenter: parent.verticalCenter + } + + Slider { + id: precisionSlider + from: 0 + value: 2 + to: 10 + stepSize: 1 + ToolTip { + parent: precisionSlider.handle + visible: precisionSlider.pressed + text: precisionSlider.value.toFixed(0) + } + } + } + Rectangle { id: xCursor width: 1 height: parent.height - color: sysPalette.windowText + color: 'black' anchors.top: parent.top anchors.left: parent.left anchors.leftMargin: picker.mouseX @@ -93,25 +116,26 @@ Item { id: yCursor width: parent.width height: 1 - color: sysPalette.windowText + color: 'black' anchors.top: parent.top anchors.left: parent.left anchors.topMargin: picker.mouseY visible: parent.pickY } - Label { + Text { x: picker.mouseX - width - 5 y: picker.mouseY - height - 5 - property double mouseX: canvas.px2x(picker.mouseX).toFixed(2) - property double mouseY: canvas.px2y(picker.mouseY).toFixed(2) + property double mouseX: canvas.px2x(picker.mouseX).toFixed(parent.precision) + property double mouseY: canvas.px2y(picker.mouseY).toFixed(parent.precision) + color: 'black' text: { if(parent.pickX && parent.pickY) return `(${mouseX}, ${mouseY})` if(parent.pickX) - return mouseX + '' + return `X = ${mouseX}` if(parent.pickY) - return mouseY + '' + return `Y = ${mouseY}` } } }