WIP: Add PrintHeadMinMaxTextField

This commit is contained in:
Lipu Fei 2019-03-18 12:01:52 +01:00
parent 0fb9ee6c9a
commit a2f845f90e
2 changed files with 91 additions and 2 deletions

View file

@ -3,7 +3,6 @@
import QtQuick 2.10 import QtQuick 2.10
import QtQuick.Controls 2.3 import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import UM 1.3 as UM import UM 1.3 as UM
import Cura 1.1 as Cura import Cura 1.1 as Cura
@ -30,11 +29,16 @@ UM.TooltipArea
property alias settingKey: propertyProvider.key property alias settingKey: propertyProvider.key
property alias settingStoreIndex: propertyProvider.storeIndex property alias settingStoreIndex: propertyProvider.storeIndex
property alias propertyProvider: propertyProvider
property alias labelText: fieldLabel.text property alias labelText: fieldLabel.text
property alias labelFont: fieldLabel.font property alias labelFont: fieldLabel.font
property alias labelWidth: fieldLabel.width property alias labelWidth: fieldLabel.width
property alias unitText: unitLabel.text property alias unitText: unitLabel.text
property alias valueText: textFieldWithUnit.text
property alias valueValidator: textFieldWithUnit.validator
property alias editingFinishedFunction: textFieldWithUnit.editingFinishedFunction
property string tooltipText: propertyProvider.properties.description property string tooltipText: propertyProvider.properties.description
// whether negative value is allowed. This affects the validation of the input field. // whether negative value is allowed. This affects the validation of the input field.
@ -151,7 +155,11 @@ UM.TooltipArea
} }
validator: RegExpValidator { regExp: allowNegativeValue ? /-?[0-9\.,]{0,6}/ : /[0-9\.,]{0,6}/ } validator: RegExpValidator { regExp: allowNegativeValue ? /-?[0-9\.,]{0,6}/ : /[0-9\.,]{0,6}/ }
onEditingFinished: onEditingFinished: editingFinishedFunction()
property var editingFinishedFunction: defaultEditingFinishedFunction
function defaultEditingFinishedFunction()
{ {
if (propertyProvider && text != propertyProvider.properties.value) if (propertyProvider && text != propertyProvider.properties.value)
{ {

View file

@ -0,0 +1,81 @@
// Copyright (c) 2019 Ultimaker B.V.
// Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.10
import QtQuick.Controls 2.3
import UM 1.3 as UM
import Cura 1.1 as Cura
//
// This is the widget for editing min and max X and Y for the print head.
// The print head is internally stored as a JSON array or array, representing a polygon of the print head.
// The polygon array is stored in the format illustrated below:
// [ [ -x_min, y_max ],
// [ -x_min, -y_min ],
// [ x_max, y_max ],
// [ x_max, -y_min ],
// ]
//
// In order to modify each field, the widget is configurable via "axisName" and "axisMinOrMax", where
// - axisName is "x" or "y"
// - axisMinOrMax is "min" or "max"
//
NumericTextFieldWithUnit
{
id: machineXMaxField
UM.I18nCatalog { id: catalog; name: "cura" }
containerStackId: Cura.MachineManager.activeMachineId
settingKey: "machine_head_with_fans_polygon"
settingStoreIndex: 1
property string axisName: "x"
property string axisMinOrMax: "min"
property var axisValue:
{
var polygon = JSON.parse(propertyProvider.properties.value)
var item = (axisName == "x") ? 0 : 1
var result = polygon[0][item]
var func = (axisMinOrMax == "min") ? Math.min : Math.max
for (var i = 1; i < polygon.length; i++)
{
result = func(result, polygon[i][item])
}
result = Math.abs(result)
return result
}
valueValidator: RegExpValidator { regExp: /[0-9\.,]{0,6}/ }
valueText: axisValue
editingFinishedFunction: function()
{
var polygon = JSON.parse(propertyProvider.properties.value)
var newValue = parseFloat(valueText.replace(',', '.'))
if (axisName == "x") // x min/x max
{
var start_i1 = (axisMinOrMax == "min") ? 0 : 2
var factor = (axisMinOrMax == "min") ? -1 : 1
polygon[start_i1][0] = newValue * factor
polygon[start_i1 + 1][0] = newValue * factor
}
else // y min/y max
{
var start_i1 = (axisMinOrMax == "min") ? 1 : 0
var factor = (axisMinOrMax == "min") ? -1 : 1
polygon[start_i1][1] = newValue * factor
polygon[start_i1 + 2][1] = newValue * factor
}
var polygon_string = JSON.stringify(polygon)
if (polygon_string != propertyProvider.properties.value)
{
propertyProvider.setPropertyValue("value", polygon_string)
forceUpdateOnChangeFunction()
}
}
// TODO: add forceUpdateOnChangeFunction:
}