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
width: logo.width + 10 + welcomeText.width
anchors.top: parent.top
anchors.topMargin: 50
anchors.topMargin: (parent.width-width)/2
anchors.horizontalCenter: parent.horizontalCenter
Image {

View file

@ -155,6 +155,7 @@ ApplicationWindow {
}
PickLocationOverlay {
id: positionPicker
anchors.fill: 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 {
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)

View file

@ -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}`
}
}
}