SettingTextField.qml 5.3 KB

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