SettingView.qml 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. ScrollView
  10. {
  11. id: base;
  12. style: UM.Theme.styles.scrollview;
  13. flickableItem.flickableDirection: Flickable.VerticalFlick;
  14. property Action configureSettings;
  15. signal showTooltip(Item item, point location, string text);
  16. signal hideTooltip();
  17. ListView
  18. {
  19. id: contents
  20. spacing: UM.Theme.getSize("default_lining").height;
  21. cacheBuffer: 1000000; // Set a large cache to effectively just cache every list item.
  22. model: UM.SettingDefinitionsModel {
  23. id: definitionsModel;
  24. containerId: Cura.MachineManager.activeDefinitionId
  25. visibilityHandler: UM.SettingPreferenceVisibilityHandler { }
  26. exclude: ["machine_settings"]
  27. expanded: Printer.expandedCategories
  28. onExpandedChanged: Printer.setExpandedCategories(expanded)
  29. }
  30. delegate: Loader
  31. {
  32. id: delegate
  33. width: UM.Theme.getSize("sidebar").width;
  34. height: provider.properties.enabled == "True" ? UM.Theme.getSize("section").height : - contents.spacing
  35. Behavior on height { NumberAnimation { duration: 100 } }
  36. opacity: provider.properties.enabled == "True" ? 1 : 0
  37. Behavior on opacity { NumberAnimation { duration: 100 } }
  38. enabled:
  39. {
  40. if(!ExtruderManager.activeExtruderStackId && ExtruderManager.extruderCount > 0)
  41. {
  42. // disable all controls on the global tab, except categories
  43. return model.type == "category"
  44. }
  45. return provider.properties.enabled == "True"
  46. }
  47. property var definition: model
  48. property var settingDefinitionsModel: definitionsModel
  49. property var propertyProvider: provider
  50. property var globalPropertyProvider: inheritStackProvider
  51. //Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
  52. //In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
  53. //causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
  54. asynchronous: model.type != "enum" && model.type != "extruder"
  55. active: model.type != undefined
  56. source:
  57. {
  58. switch(model.type)
  59. {
  60. case "int":
  61. return "SettingTextField.qml"
  62. case "float":
  63. return "SettingTextField.qml"
  64. case "enum":
  65. return "SettingComboBox.qml"
  66. case "extruder":
  67. return "SettingExtruder.qml"
  68. case "bool":
  69. return "SettingCheckBox.qml"
  70. case "str":
  71. return "SettingTextField.qml"
  72. case "category":
  73. return "SettingCategory.qml"
  74. default:
  75. return "SettingUnknown.qml"
  76. }
  77. }
  78. // Binding to ensure that the right containerstack ID is set for the provider.
  79. // This ensures that if a setting has a limit_to_extruder id (for instance; Support speed points to the
  80. // extruder that actually prints the support, as that is the setting we need to use to calculate the value)
  81. Binding
  82. {
  83. target: provider
  84. property: "containerStackId"
  85. when: model.settable_per_extruder || (inheritStackProvider.properties.limit_to_extruder != null && inheritStackProvider.properties.limit_to_extruder >= 0);
  86. value:
  87. {
  88. if(!model.settable_per_extruder)
  89. {
  90. //Not settable per extruder, so we must pick global.
  91. return Cura.MachineManager.activeMachineId;
  92. }
  93. if(inheritStackProvider.properties.limit_to_extruder != null && inheritStackProvider.properties.limit_to_extruder >= 0)
  94. {
  95. //We have limit_to_extruder, so pick that stack.
  96. return ExtruderManager.extruderIds[String(inheritStackProvider.properties.limit_to_extruder)];
  97. }
  98. if(ExtruderManager.activeExtruderStackId)
  99. {
  100. //We're on an extruder tab. Pick the current extruder.
  101. return ExtruderManager.activeExtruderStackId;
  102. }
  103. //No extruder tab is selected. Pick the global stack. Shouldn't happen any more since we removed the global tab.
  104. return Cura.MachineManager.activeMachineId;
  105. }
  106. }
  107. // Specialty provider that only watches global_inherits (we cant filter on what property changed we get events
  108. // so we bypass that to make a dedicated provider).
  109. UM.SettingPropertyProvider
  110. {
  111. id: inheritStackProvider
  112. containerStackId: Cura.MachineManager.activeMachineId
  113. key: model.key
  114. watchedProperties: [ "limit_to_extruder" ]
  115. }
  116. UM.SettingPropertyProvider
  117. {
  118. id: provider
  119. containerStackId: Cura.MachineManager.activeMachineId
  120. key: model.key ? model.key : ""
  121. watchedProperties: [ "value", "enabled", "state", "validationState", "settable_per_extruder", "resolve" ]
  122. storeIndex: 0
  123. }
  124. Connections
  125. {
  126. target: item
  127. onContextMenuRequested:
  128. {
  129. contextMenu.key = model.key;
  130. contextMenu.provider = provider
  131. contextMenu.popup();
  132. }
  133. onShowTooltip: base.showTooltip(delegate, { x: 0, y: delegate.height / 2 }, text)
  134. onHideTooltip: base.hideTooltip()
  135. onShowAllHiddenInheritedSettings:
  136. {
  137. var children_with_override = Cura.SettingInheritanceManager.getChildrenKeysWithOverride(category_id)
  138. for(var i = 0; i < children_with_override.length; i++)
  139. {
  140. definitionsModel.setVisible(children_with_override[i], true)
  141. }
  142. Cura.SettingInheritanceManager.manualRemoveOverride(category_id)
  143. }
  144. }
  145. }
  146. UM.I18nCatalog { id: catalog; name: "uranium"; }
  147. add: Transition {
  148. SequentialAnimation {
  149. NumberAnimation { properties: "height"; from: 0; duration: 100 }
  150. NumberAnimation { properties: "opacity"; from: 0; duration: 100 }
  151. }
  152. }
  153. remove: Transition {
  154. SequentialAnimation {
  155. NumberAnimation { properties: "opacity"; to: 0; duration: 100 }
  156. NumberAnimation { properties: "height"; to: 0; duration: 100 }
  157. }
  158. }
  159. addDisplaced: Transition {
  160. NumberAnimation { properties: "x,y"; duration: 100 }
  161. }
  162. removeDisplaced: Transition {
  163. SequentialAnimation {
  164. PauseAnimation { duration: 100; }
  165. NumberAnimation { properties: "x,y"; duration: 100 }
  166. }
  167. }
  168. Menu
  169. {
  170. id: contextMenu
  171. property string key
  172. property var provider
  173. MenuItem
  174. {
  175. //: Settings context menu action
  176. text: catalog.i18nc("@action:menu", "Copy value to all extruders")
  177. visible: machineExtruderCount.properties.value > 1
  178. enabled: contextMenu.provider != undefined && contextMenu.provider.properties.settable_per_extruder != "False"
  179. onTriggered: Cura.MachineManager.copyValueToExtruders(contextMenu.key)
  180. }
  181. MenuSeparator
  182. {
  183. visible: machineExtruderCount.properties.value > 1
  184. }
  185. MenuItem
  186. {
  187. //: Settings context menu action
  188. text: catalog.i18nc("@action:menu", "Hide this setting");
  189. onTriggered: definitionsModel.hide(contextMenu.key);
  190. }
  191. MenuItem
  192. {
  193. //: Settings context menu action
  194. text: catalog.i18nc("@action:menu", "Configure setting visiblity...");
  195. onTriggered: Cura.Actions.configureSettingVisibility.trigger(contextMenu);
  196. }
  197. }
  198. UM.SettingPropertyProvider
  199. {
  200. id: machineExtruderCount
  201. containerStackId: Cura.MachineManager.activeMachineId
  202. key: "machine_extruder_count"
  203. watchedProperties: [ "value" ]
  204. storeIndex: 0
  205. }
  206. }
  207. }