PerObjectSettingsPanel.qml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 QtQuick.Controls.Styles 1.2
  6. import QtQuick.Window 2.2
  7. import UM 1.2 as UM
  8. import Cura 1.0 as Cura
  9. import ".."
  10. Item {
  11. id: base;
  12. UM.I18nCatalog { id: catalog; name: "cura"; }
  13. width: childrenRect.width;
  14. height: childrenRect.height;
  15. Column
  16. {
  17. id: items
  18. anchors.top: parent.top;
  19. anchors.left: parent.left;
  20. spacing: UM.Theme.getSize("default_margin").height;
  21. Repeater
  22. {
  23. id: contents
  24. height: childrenRect.height;
  25. model: UM.SettingDefinitionsModel
  26. {
  27. id: addedSettingsModel;
  28. containerId: Cura.MachineManager.activeDefinitionId
  29. visibilityHandler: Cura.PerObjectSettingVisibilityHandler
  30. {
  31. selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId")
  32. }
  33. }
  34. delegate: Row
  35. {
  36. Loader
  37. {
  38. id: settingLoader
  39. width: UM.Theme.getSize("setting").width;
  40. height: UM.Theme.getSize("section").height;
  41. property var definition: model
  42. property var settingDefinitionsModel: addedSettingsModel
  43. property var propertyProvider: provider
  44. //Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
  45. //In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
  46. //causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
  47. asynchronous: model.type != "enum" && model.type != "extruder"
  48. onLoaded: {
  49. settingLoader.item.showRevertButton = false
  50. settingLoader.item.showInheritButton = false
  51. settingLoader.item.doDepthIndentation = false
  52. }
  53. sourceComponent:
  54. {
  55. switch(model.type)
  56. {
  57. case "int":
  58. return settingTextField
  59. case "float":
  60. return settingTextField
  61. case "enum":
  62. return settingComboBox
  63. case "extruder":
  64. return settingExtruder
  65. case "bool":
  66. return settingCheckBox
  67. case "str":
  68. return settingTextField
  69. case "category":
  70. return settingCategory
  71. default:
  72. return settingUnknown
  73. }
  74. }
  75. }
  76. Button
  77. {
  78. width: UM.Theme.getSize("setting").height;
  79. height: UM.Theme.getSize("setting").height;
  80. onClicked: addedSettingsModel.setVisible(model.key, false);
  81. style: ButtonStyle
  82. {
  83. background: Rectangle
  84. {
  85. color: control.hovered ? control.parent.style.controlHighlightColor : control.parent.style.controlColor;
  86. UM.RecolorImage
  87. {
  88. anchors.verticalCenter: parent.verticalCenter
  89. anchors.horizontalCenter: parent.horizontalCenter
  90. width: parent.width/2
  91. height: parent.height/2
  92. sourceSize.width: width
  93. sourceSize.height: width
  94. color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button")
  95. source: UM.Theme.getIcon("cross1")
  96. }
  97. }
  98. }
  99. }
  100. UM.SettingPropertyProvider
  101. {
  102. id: provider
  103. containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
  104. key: model.key
  105. watchedProperties: [ "value", "enabled", "validationState" ]
  106. storeIndex: 0
  107. }
  108. }
  109. }
  110. Button
  111. {
  112. id: customise_settings_button;
  113. height: UM.Theme.getSize("setting").height;
  114. visible: parseInt(UM.Preferences.getValue("cura/active_mode")) == 1
  115. text: catalog.i18nc("@action:button", "Add Setting");
  116. style: ButtonStyle
  117. {
  118. background: Rectangle
  119. {
  120. width: control.width;
  121. height: control.height;
  122. border.width: UM.Theme.getSize("default_lining").width;
  123. border.color: control.pressed ? UM.Theme.getColor("action_button_active_border") :
  124. control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  125. color: control.pressed ? UM.Theme.getColor("action_button_active") :
  126. control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  127. }
  128. label: Label
  129. {
  130. text: control.text;
  131. color: UM.Theme.getColor("setting_control_text");
  132. anchors.centerIn: parent
  133. }
  134. }
  135. onClicked: settingPickDialog.visible = true;
  136. Connections
  137. {
  138. target: UM.Preferences;
  139. onPreferenceChanged:
  140. {
  141. customise_settings_button.visible = parseInt(UM.Preferences.getValue("cura/active_mode"))
  142. }
  143. }
  144. }
  145. }
  146. UM.Dialog {
  147. id: settingPickDialog
  148. title: catalog.i18nc("@title:window", "Pick a Setting to Customize")
  149. property string labelFilter: ""
  150. TextField {
  151. id: filter;
  152. anchors {
  153. top: parent.top;
  154. left: parent.left;
  155. right: parent.right;
  156. }
  157. placeholderText: catalog.i18nc("@label:textbox", "Filter...");
  158. onTextChanged:
  159. {
  160. if(text != "")
  161. {
  162. listview.model.filter = {"global_only": false, "label": "*" + text}
  163. }
  164. else
  165. {
  166. listview.model.filter = {"global_only": false}
  167. }
  168. }
  169. }
  170. ScrollView
  171. {
  172. id: scrollView
  173. anchors
  174. {
  175. top: filter.bottom;
  176. left: parent.left;
  177. right: parent.right;
  178. bottom: parent.bottom;
  179. }
  180. ListView
  181. {
  182. id:listview
  183. model: UM.SettingDefinitionsModel
  184. {
  185. id: definitionsModel;
  186. containerId: Cura.MachineManager.activeDefinitionId
  187. filter:
  188. {
  189. "global_only": false
  190. }
  191. visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
  192. }
  193. delegate:Loader
  194. {
  195. id: loader
  196. width: parent.width
  197. height: model.type != undefined ? UM.Theme.getSize("section").height : 0;
  198. property var definition: model
  199. property var settingDefinitionsModel: definitionsModel
  200. asynchronous: true
  201. source:
  202. {
  203. switch(model.type)
  204. {
  205. case "category":
  206. return "PerObjectCategory.qml"
  207. default:
  208. return "PerObjectItem.qml"
  209. }
  210. }
  211. }
  212. }
  213. }
  214. rightButtons: [
  215. Button {
  216. text: catalog.i18nc("@action:button", "Cancel");
  217. onClicked: {
  218. settingPickDialog.visible = false;
  219. }
  220. }
  221. ]
  222. }
  223. SystemPalette { id: palette; }
  224. Component
  225. {
  226. id: settingTextField;
  227. Cura.SettingTextField { }
  228. }
  229. Component
  230. {
  231. id: settingComboBox;
  232. Cura.SettingComboBox { }
  233. }
  234. Component
  235. {
  236. id: settingExtruder;
  237. Cura.SettingExtruder { }
  238. }
  239. Component
  240. {
  241. id: settingCheckBox;
  242. Cura.SettingCheckBox { }
  243. }
  244. Component
  245. {
  246. id: settingCategory;
  247. Cura.SettingCategory { }
  248. }
  249. Component
  250. {
  251. id: settingUnknown;
  252. Cura.SettingUnknown { }
  253. }
  254. }