SettingTextField.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.2
  5. import UM 1.1 as UM
  6. SettingItem
  7. {
  8. id: base
  9. contents: Rectangle
  10. {
  11. id: control
  12. anchors.fill: parent
  13. border.width: UM.Theme.getSize("default_lining").width
  14. border.color: !enabled ? UM.Theme.getColor("setting_control_disabled_border") : hovered ? UM.Theme.getColor("setting_control_border_highlight") : UM.Theme.getColor("setting_control_border")
  15. color: {
  16. if (!enabled)
  17. {
  18. return UM.Theme.getColor("setting_control_disabled")
  19. }
  20. switch(propertyProvider.properties.validationState)
  21. {
  22. case "ValidatorState.Exception":
  23. return UM.Theme.getColor("setting_validation_error")
  24. case "ValidatorState.MinimumError":
  25. return UM.Theme.getColor("setting_validation_error")
  26. case "ValidatorState.MaximumError":
  27. return UM.Theme.getColor("setting_validation_error")
  28. case "ValidatorState.MinimumWarning":
  29. return UM.Theme.getColor("setting_validation_warning")
  30. case "ValidatorState.MaximumWarning":
  31. return UM.Theme.getColor("setting_validation_warning")
  32. case "ValidatorState.Valid":
  33. return UM.Theme.getColor("setting_validation_ok")
  34. default:
  35. return UM.Theme.getColor("setting_control")
  36. }
  37. }
  38. Rectangle
  39. {
  40. anchors.fill: parent;
  41. anchors.margins: UM.Theme.getSize("default_lining").width;
  42. color: UM.Theme.getColor("setting_control_highlight")
  43. opacity: !control.hovered ? 0 : propertyProvider.properties.validationState == "ValidatorState.Valid" ? 1.0 : 0.35;
  44. }
  45. Label
  46. {
  47. anchors.right: parent.right;
  48. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  49. anchors.verticalCenter: parent.verticalCenter;
  50. text: definition.unit;
  51. color: UM.Theme.getColor("setting_unit")
  52. font: UM.Theme.getFont("default")
  53. }
  54. MouseArea
  55. {
  56. id: mouseArea
  57. anchors.fill: parent;
  58. //hoverEnabled: true;
  59. cursorShape: Qt.IBeamCursor
  60. }
  61. TextInput
  62. {
  63. id: input
  64. anchors
  65. {
  66. left: parent.left
  67. leftMargin: UM.Theme.getSize("setting_unit_margin").width
  68. right: parent.right
  69. verticalCenter: parent.verticalCenter
  70. }
  71. Keys.onReleased:
  72. {
  73. propertyProvider.setPropertyValue("value", text)
  74. }
  75. onEditingFinished:
  76. {
  77. propertyProvider.setPropertyValue("value", text)
  78. }
  79. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  80. font: UM.Theme.getFont("default");
  81. selectByMouse: true;
  82. maximumLength: 10;
  83. validator: RegExpValidator { regExp: (definition.type == "int") ? /^-?[0-9]{0,10}/ : /^-?[0-9.,]{0,10}/ } // definition.type property from parent loader used to disallow fractional number entry
  84. Binding
  85. {
  86. target: input
  87. property: "text"
  88. value: {
  89. // Stacklevels
  90. // 0: user -> unsaved change
  91. // 1: quality changes -> saved change
  92. // 2: quality
  93. // 3: material -> user changed material in materialspage
  94. // 4: variant
  95. // 5: machine
  96. if ((propertyProvider.properties.resolve != "None") && (stackLevel != 0) && (stackLevel != 1)) {
  97. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  98. // we have to choose between the resolved value (default) and the global value
  99. // (if user has explicitly set this).
  100. return propertyProvider.properties.resolve;
  101. } else {
  102. return propertyProvider.properties.value;
  103. }
  104. }
  105. when: !input.activeFocus
  106. }
  107. }
  108. }
  109. }