Added the ability to cancel the position setting with right click.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Adsooi 2021-08-15 17:18:50 +02:00
parent 63d9f00e96
commit 9fd584f881
Signed by: Ad5001
GPG key ID: EF45F9C6AFE20160
2 changed files with 34 additions and 29 deletions

View file

@ -136,7 +136,7 @@ ListView {
onClicked: { onClicked: {
positionPicker.objType = objType positionPicker.objType = objType
positionPicker.objName = Objects.currentObjects[objType][index].name positionPicker.objName = obj.name
positionPicker.pickX = hasXProp positionPicker.pickX = hasXProp
positionPicker.pickY = hasYProp positionPicker.pickY = hasYProp
positionPicker.propertyX = 'x' positionPicker.propertyX = 'x'
@ -154,10 +154,12 @@ ListView {
anchors.rightMargin: 5 anchors.rightMargin: 5
anchors.topMargin: 5 anchors.topMargin: 5
icon.name: 'delete' icon.name: 'delete'
ToolTip.visible: hovered
ToolTip.text: 'Delete ' + Objects.types[objType].displayType() + '.'
onClicked: { onClicked: {
history.addToHistory(new HistoryLib.DeleteObject( history.addToHistory(new HistoryLib.DeleteObject(
Objects.currentObjects[objType][index].name, objType, Objects.currentObjects[objType][index].export() obj.name, objType, obj.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

@ -46,34 +46,37 @@ Item {
anchors.fill: parent anchors.fill: parent
hoverEnabled: parent.visible hoverEnabled: parent.visible
cursorShape: Qt.CrossCursor cursorShape: Qt.CrossCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
onClicked: { onClicked: {
if(parent.pickX) { if(mouse.button == Qt.LeftButton) { // Validate
var newValue = canvas.px2x(picker.mouseX).toFixed(parent.precision) if(parent.pickX) {
newValue = { var newValue = canvas.px2x(picker.mouseX).toFixed(parent.precision)
'Expression': () => new MathLib.Expression(newValue), newValue = {
'number': () => parseFloat(newValue) 'Expression': () => new MathLib.Expression(newValue),
}[Objects.types[objType].properties()[propertyX]]() 'number': () => parseFloat(newValue)
var obj = Objects.getObjectByName(objName, objType) }[Objects.types[objType].properties()[propertyX]]()
history.addToHistory(new HistoryLib.EditedProperty( var obj = Objects.getObjectByName(objName, objType)
objName, objType, propertyX, obj[propertyX], newValue history.addToHistory(new HistoryLib.EditedProperty(
)) objName, objType, propertyX, obj[propertyX], newValue
obj[propertyX] = newValue ))
obj.update() obj[propertyX] = newValue
objectLists.update() obj.update()
} objectLists.update()
if(parent.pickY) { }
var newValue = canvas.px2y(picker.mouseY).toFixed(parent.precision) if(parent.pickY) {
newValue = { var newValue = canvas.px2y(picker.mouseY).toFixed(parent.precision)
'Expression': () => new MathLib.Expression(newValue), newValue = {
'number': () => parseFloat(newValue) 'Expression': () => new MathLib.Expression(newValue),
}[Objects.types[objType].properties()[propertyY]]() 'number': () => parseFloat(newValue)
var obj = Objects.getObjectByName(objName, objType) }[Objects.types[objType].properties()[propertyY]]()
history.addToHistory(new HistoryLib.EditedProperty( var obj = Objects.getObjectByName(objName, objType)
objName, objType, propertyY, obj[propertyY], newValue history.addToHistory(new HistoryLib.EditedProperty(
)) objName, objType, propertyY, obj[propertyY], newValue
obj[propertyY] = newValue ))
obj.update() obj[propertyY] = newValue
objectLists.update() obj.update()
objectLists.update()
}
} }
pickerRoot.visible = false; pickerRoot.visible = false;
} }