Finishing position picker for objects having a position.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adsooi 2021-08-15 01:18:13 +02:00
parent 391cf61e36
commit 4afe0d4d63
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
4 changed files with 62 additions and 11 deletions

View file

@ -35,7 +35,7 @@ Popup {
height: logo.height height: logo.height
width: logo.width + 10 + welcomeText.width width: logo.width + 10 + welcomeText.width
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 50 anchors.topMargin: (parent.width-width)/2
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
Image { Image {

View file

@ -155,6 +155,7 @@ ApplicationWindow {
} }
PickLocationOverlay { PickLocationOverlay {
id: positionPicker
anchors.fill: parent anchors.fill: parent
canvas: parent canvas: parent
} }

View file

@ -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 { Button {
id: deleteButton id: deleteButton
width: parent.height - 10 width: parent.height - 10
@ -131,7 +157,7 @@ ListView {
onClicked: { onClicked: {
history.addToHistory(new HistoryLib.DeleteObject( 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][index].delete()
Objects.currentObjects[objType].splice(index, 1) Objects.currentObjects[objType].splice(index, 1)

View file

@ -33,6 +33,7 @@ Item {
property bool pickX: true property bool pickX: true
property string propertyX: 'x' property string propertyX: 'x'
property string propertyY: 'y' property string propertyY: 'y'
property alias precision: precisionSlider.value
Rectangle { Rectangle {
color: sysPalette.window color: sysPalette.window
@ -47,7 +48,7 @@ Item {
cursorShape: Qt.CrossCursor cursorShape: Qt.CrossCursor
onClicked: { onClicked: {
if(parent.pickX) { if(parent.pickX) {
var newValue = canvas.px2x(picker.mouseX).toFixed(2) var newValue = canvas.px2x(picker.mouseX).toFixed(parent.precision)
newValue = { newValue = {
'Expression': () => new MathLib.Expression(newValue), 'Expression': () => new MathLib.Expression(newValue),
'number': () => parseFloat(newValue) 'number': () => parseFloat(newValue)
@ -61,7 +62,7 @@ Item {
objectLists.update() objectLists.update()
} }
if(parent.pickY) { if(parent.pickY) {
var newValue = canvas.px2y(picker.mouseY).toFixed(2) var newValue = canvas.px2y(picker.mouseY).toFixed(parent.precision)
newValue = { newValue = {
'Expression': () => new MathLib.Expression(newValue), 'Expression': () => new MathLib.Expression(newValue),
'number': () => parseFloat(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 { Rectangle {
id: xCursor id: xCursor
width: 1 width: 1
height: parent.height height: parent.height
color: sysPalette.windowText color: 'black'
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: picker.mouseX anchors.leftMargin: picker.mouseX
@ -93,25 +116,26 @@ Item {
id: yCursor id: yCursor
width: parent.width width: parent.width
height: 1 height: 1
color: sysPalette.windowText color: 'black'
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.topMargin: picker.mouseY anchors.topMargin: picker.mouseY
visible: parent.pickY visible: parent.pickY
} }
Label { Text {
x: picker.mouseX - width - 5 x: picker.mouseX - width - 5
y: picker.mouseY - height - 5 y: picker.mouseY - height - 5
property double mouseX: canvas.px2x(picker.mouseX).toFixed(2) property double mouseX: canvas.px2x(picker.mouseX).toFixed(parent.precision)
property double mouseY: canvas.px2y(picker.mouseY).toFixed(2) property double mouseY: canvas.px2y(picker.mouseY).toFixed(parent.precision)
color: 'black'
text: { text: {
if(parent.pickX && parent.pickY) if(parent.pickX && parent.pickY)
return `(${mouseX}, ${mouseY})` return `(${mouseX}, ${mouseY})`
if(parent.pickX) if(parent.pickX)
return mouseX + '' return `X = ${mouseX}`
if(parent.pickY) if(parent.pickY)
return mouseY + '' return `Y = ${mouseY}`
} }
} }
} }