SettingTextField.qml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. property var focusItem: input
  10. contents: Rectangle
  11. {
  12. id: control
  13. anchors.fill: parent
  14. border.width: UM.Theme.getSize("default_lining").width
  15. border.color:
  16. {
  17. if(!enabled)
  18. {
  19. return UM.Theme.getColor("setting_control_disabled_border")
  20. }
  21. switch(propertyProvider.properties.validationState)
  22. {
  23. case "ValidatorState.Exception":
  24. case "ValidatorState.MinimumError":
  25. case "ValidatorState.MaximumError":
  26. return UM.Theme.getColor("setting_validation_error");
  27. case "ValidatorState.MinimumWarning":
  28. case "ValidatorState.MaximumWarning":
  29. return UM.Theme.getColor("setting_validation_warning");
  30. }
  31. //Validation is OK.
  32. if(hovered || input.activeFocus)
  33. {
  34. return UM.Theme.getColor("setting_control_border_highlight")
  35. }
  36. return UM.Theme.getColor("setting_control_border")
  37. }
  38. color: {
  39. if(!enabled)
  40. {
  41. return UM.Theme.getColor("setting_control_disabled")
  42. }
  43. switch(propertyProvider.properties.validationState)
  44. {
  45. case "ValidatorState.Exception":
  46. case "ValidatorState.MinimumError":
  47. case "ValidatorState.MaximumError":
  48. return UM.Theme.getColor("setting_validation_error_background")
  49. case "ValidatorState.MinimumWarning":
  50. case "ValidatorState.MaximumWarning":
  51. return UM.Theme.getColor("setting_validation_warning_background")
  52. case "ValidatorState.Valid":
  53. return UM.Theme.getColor("setting_validation_ok")
  54. default:
  55. return UM.Theme.getColor("setting_control")
  56. }
  57. }
  58. Rectangle
  59. {
  60. anchors.fill: parent;
  61. anchors.margins: UM.Theme.getSize("default_lining").width;
  62. color: UM.Theme.getColor("setting_control_highlight")
  63. opacity: !control.hovered ? 0 : propertyProvider.properties.validationState == "ValidatorState.Valid" ? 1.0 : 0.35;
  64. }
  65. Label
  66. {
  67. anchors.right: parent.right;
  68. anchors.rightMargin: UM.Theme.getSize("setting_unit_margin").width
  69. anchors.verticalCenter: parent.verticalCenter;
  70. text: definition.unit;
  71. color: UM.Theme.getColor("setting_unit")
  72. font: UM.Theme.getFont("default")
  73. }
  74. MouseArea
  75. {
  76. id: mouseArea
  77. anchors.fill: parent;
  78. //hoverEnabled: true;
  79. cursorShape: Qt.IBeamCursor
  80. }
  81. TextInput
  82. {
  83. id: input
  84. anchors
  85. {
  86. left: parent.left
  87. leftMargin: UM.Theme.getSize("setting_unit_margin").width
  88. right: parent.right
  89. verticalCenter: parent.verticalCenter
  90. }
  91. Keys.onTabPressed:
  92. {
  93. base.setActiveFocusToNextSetting(true)
  94. }
  95. Keys.onBacktabPressed:
  96. {
  97. base.setActiveFocusToNextSetting(false)
  98. }
  99. Keys.onReleased:
  100. {
  101. propertyProvider.setPropertyValue("value", text)
  102. }
  103. onEditingFinished:
  104. {
  105. propertyProvider.setPropertyValue("value", text)
  106. }
  107. onActiveFocusChanged:
  108. {
  109. if(activeFocus)
  110. {
  111. base.focusReceived();
  112. }
  113. }
  114. color: !enabled ? UM.Theme.getColor("setting_control_disabled_text") : UM.Theme.getColor("setting_control_text")
  115. font: UM.Theme.getFont("default");
  116. selectByMouse: true;
  117. maximumLength: (definition.type == "[int]") ? 20 : (definition.type == "str") ? -1 : 10;
  118. validator: RegExpValidator { regExp: (definition.type == "[int]") ? /^\[?(\s*-?[0-9]{0,9}\s*,)*(\s*-?[0-9]{0,9})\s*\]?$/ : (definition.type == "int") ? /^-?[0-9]{0,10}$/ : (definition.type == "float") ? /^-?[0-9]{0,9}[.,]?[0-9]{0,10}$/ : /^.*$/ } // definition.type property from parent loader used to disallow fractional number entry
  119. Binding
  120. {
  121. target: input
  122. property: "text"
  123. value: {
  124. // Stacklevels
  125. // 0: user -> unsaved change
  126. // 1: quality changes -> saved change
  127. // 2: quality
  128. // 3: material -> user changed material in materialspage
  129. // 4: variant
  130. // 5: machine_changes
  131. // 6: machine
  132. if ((base.resolve != "None" && base.resolve) && (stackLevel != 0) && (stackLevel != 1)) {
  133. // We have a resolve function. Indicates that the setting is not settable per extruder and that
  134. // we have to choose between the resolved value (default) and the global value
  135. // (if user has explicitly set this).
  136. return base.resolve;
  137. } else {
  138. return propertyProvider.properties.value;
  139. }
  140. }
  141. when: !input.activeFocus
  142. }
  143. }
  144. }
  145. }