123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- import QtQuick 2.10
- import QtQuick.Controls 2.3
- import UM 1.3 as UM
- import Cura 1.1 as Cura
- UM.TooltipArea
- {
- id: numericTextFieldWithUnit
- UM.I18nCatalog { id: catalog; name: "cura"; }
- height: childrenRect.height
- width: childrenRect.width
- property int controlWidth: UM.Theme.getSize("setting_control").width
- property int controlHeight: UM.Theme.getSize("setting_control").height
- text: tooltipText
- property alias containerStackId: propertyProvider.containerStackId
- property alias settingKey: propertyProvider.key
- property alias settingStoreIndex: propertyProvider.storeIndex
- property alias propertyProvider: propertyProvider
- property alias labelText: fieldLabel.text
- property alias labelFont: fieldLabel.font
- property alias labelWidth: fieldLabel.width
- 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 bool allowNegativeValue: false
-
- property var afterOnEditingFinishedFunction: dummy_func
- property var forceUpdateOnChangeFunction: dummy_func
- property var setValueFunction: null
-
- function dummy_func() {}
- UM.SettingPropertyProvider
- {
- id: propertyProvider
- watchedProperties: [ "value", "description" ]
- }
- Label
- {
- id: fieldLabel
- anchors.left: parent.left
- anchors.verticalCenter: textFieldWithUnit.verticalCenter
- visible: text != ""
- font: UM.Theme.getFont("medium")
- renderType: Text.NativeRendering
- }
- TextField
- {
- id: textFieldWithUnit
- anchors.left: fieldLabel.right
- anchors.leftMargin: UM.Theme.getSize("default_margin").width
- width: numericTextFieldWithUnit.controlWidth
- height: numericTextFieldWithUnit.controlHeight
-
- background: Rectangle
- {
- anchors.fill: parent
- anchors.margins: Math.round(UM.Theme.getSize("default_lining").width)
- radius: UM.Theme.getSize("setting_control_radius").width
- border.color:
- {
- if (!textFieldWithUnit.enabled)
- {
- return UM.Theme.getColor("setting_control_disabled_border")
- }
- switch (propertyProvider.properties.validationState)
- {
- case "ValidatorState.Exception":
- case "ValidatorState.MinimumError":
- case "ValidatorState.MaximumError":
- return UM.Theme.getColor("setting_validation_error")
- case "ValidatorState.MinimumWarning":
- case "ValidatorState.MaximumWarning":
- return UM.Theme.getColor("setting_validation_warning")
- }
-
- if (textFieldWithUnit.hovered || textFieldWithUnit.activeFocus)
- {
- return UM.Theme.getColor("setting_control_border_highlight")
- }
- return UM.Theme.getColor("setting_control_border")
- }
- color:
- {
- if (!textFieldWithUnit.enabled)
- {
- return UM.Theme.getColor("setting_control_disabled")
- }
- switch (propertyProvider.properties.validationState)
- {
- case "ValidatorState.Exception":
- case "ValidatorState.MinimumError":
- case "ValidatorState.MaximumError":
- return UM.Theme.getColor("setting_validation_error_background")
- case "ValidatorState.MinimumWarning":
- case "ValidatorState.MaximumWarning":
- return UM.Theme.getColor("setting_validation_warning_background")
- case "ValidatorState.Valid":
- return UM.Theme.getColor("setting_validation_ok")
- default:
- return UM.Theme.getColor("setting_control")
- }
- }
- }
- hoverEnabled: true
- selectByMouse: true
- font: UM.Theme.getFont("default")
- renderType: Text.NativeRendering
-
- onActiveFocusChanged:
- {
- if (activeFocus && (focusReason == Qt.TabFocusReason || focusReason == Qt.BacktabFocusReason))
- {
- selectAll()
- }
- }
- text:
- {
- const value = propertyProvider.properties.value
- return value ? value : ""
- }
- validator: RegExpValidator { regExp: allowNegativeValue ? /-?[0-9\.,]{0,6}/ : /[0-9\.,]{0,6}/ }
- onEditingFinished: editingFinishedFunction()
- property var editingFinishedFunction: defaultEditingFinishedFunction
- function defaultEditingFinishedFunction()
- {
- if (propertyProvider && text != propertyProvider.properties.value)
- {
-
-
-
-
-
-
-
-
-
-
-
- if (setValueFunction !== null)
- {
- setValueFunction(text)
- }
- else
- {
- propertyProvider.setPropertyValue("value", text)
- }
- forceUpdateOnChangeFunction()
- afterOnEditingFinishedFunction()
- }
- }
- Label
- {
- id: unitLabel
- anchors.right: parent.right
- anchors.rightMargin: Math.round(UM.Theme.getSize("setting_unit_margin").width)
- anchors.verticalCenter: parent.verticalCenter
- text: unitText
- textFormat: Text.PlainText
- verticalAlignment: Text.AlignVCenter
- renderType: Text.NativeRendering
- color: UM.Theme.getColor("setting_unit")
- font: UM.Theme.getFont("default")
- }
- }
- }
|