PerObjectSettingsPanel.qml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // Copyright (c) 2016 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. Column
  22. {
  23. // This is to ensure that the panel is first increasing in size up to 200 and then shows a scrollbar.
  24. // It kinda looks ugly otherwise (big panel, no content on it)
  25. property int maximumHeight: 200 * Screen.devicePixelRatio
  26. height: Math.min(contents.count * (UM.Theme.getSize("section").height + UM.Theme.getSize("default_lining").height), maximumHeight)
  27. ScrollView
  28. {
  29. height: parent.height
  30. width: UM.Theme.getSize("setting").width + UM.Theme.getSize("setting").height
  31. style: UM.Theme.styles.scrollview
  32. ListView
  33. {
  34. id: contents
  35. spacing: UM.Theme.getSize("default_lining").height
  36. model: UM.SettingDefinitionsModel
  37. {
  38. id: addedSettingsModel;
  39. containerId: Cura.MachineManager.activeDefinitionId
  40. expanded: [ "*" ]
  41. visibilityHandler: Cura.PerObjectSettingVisibilityHandler
  42. {
  43. selectedObjectId: UM.ActiveTool.properties.getValue("SelectedObjectId")
  44. }
  45. }
  46. delegate: Row
  47. {
  48. Loader
  49. {
  50. id: settingLoader
  51. width: UM.Theme.getSize("setting").width
  52. height: UM.Theme.getSize("section").height
  53. property var definition: model
  54. property var settingDefinitionsModel: addedSettingsModel
  55. property var propertyProvider: provider
  56. //Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
  57. //In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
  58. //causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
  59. asynchronous: model.type != "enum" && model.type != "extruder"
  60. onLoaded: {
  61. settingLoader.item.showRevertButton = false
  62. settingLoader.item.showInheritButton = false
  63. settingLoader.item.showLinkedSettingIcon = false
  64. settingLoader.item.doDepthIndentation = false
  65. settingLoader.item.doQualityUserSettingEmphasis = false
  66. }
  67. sourceComponent:
  68. {
  69. switch(model.type)
  70. {
  71. case "int":
  72. return settingTextField
  73. case "[int]":
  74. return settingTextField
  75. case "float":
  76. return settingTextField
  77. case "enum":
  78. return settingComboBox
  79. case "extruder":
  80. return settingExtruder
  81. case "optional_extruder":
  82. return settingOptionalExtruder
  83. case "bool":
  84. return settingCheckBox
  85. case "str":
  86. return settingTextField
  87. case "category":
  88. return settingCategory
  89. default:
  90. return settingUnknown
  91. }
  92. }
  93. }
  94. Button
  95. {
  96. width: (UM.Theme.getSize("setting").height / 2) | 0
  97. height: UM.Theme.getSize("setting").height
  98. onClicked: addedSettingsModel.setVisible(model.key, false)
  99. style: ButtonStyle
  100. {
  101. background: Item
  102. {
  103. UM.RecolorImage
  104. {
  105. anchors.verticalCenter: parent.verticalCenter
  106. width: parent.width
  107. height: parent.height / 2
  108. sourceSize.width: width
  109. sourceSize.height: width
  110. color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button")
  111. source: UM.Theme.getIcon("minus")
  112. }
  113. }
  114. }
  115. }
  116. UM.SettingPropertyProvider
  117. {
  118. id: provider
  119. containerStackId: UM.ActiveTool.properties.getValue("ContainerID")
  120. key: model.key
  121. watchedProperties: [ "value", "enabled", "validationState" ]
  122. storeIndex: 0
  123. removeUnusedValue: false
  124. }
  125. }
  126. }
  127. }
  128. }
  129. Button
  130. {
  131. id: customise_settings_button;
  132. height: UM.Theme.getSize("setting").height;
  133. visible: parseInt(UM.Preferences.getValue("cura/active_mode")) == 1
  134. text: catalog.i18nc("@action:button", "Select settings");
  135. style: ButtonStyle
  136. {
  137. background: Rectangle
  138. {
  139. width: control.width;
  140. height: control.height;
  141. border.width: UM.Theme.getSize("default_lining").width;
  142. border.color: control.pressed ? UM.Theme.getColor("action_button_active_border") :
  143. control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  144. color: control.pressed ? UM.Theme.getColor("action_button_active") :
  145. control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  146. }
  147. label: Label
  148. {
  149. text: control.text;
  150. color: UM.Theme.getColor("setting_control_text");
  151. anchors.centerIn: parent
  152. }
  153. }
  154. onClicked: settingPickDialog.visible = true;
  155. Connections
  156. {
  157. target: UM.Preferences;
  158. onPreferenceChanged:
  159. {
  160. customise_settings_button.visible = parseInt(UM.Preferences.getValue("cura/active_mode"))
  161. }
  162. }
  163. }
  164. }
  165. UM.Dialog {
  166. id: settingPickDialog
  167. title: catalog.i18nc("@title:window", "Select Settings to Customize for this model")
  168. width: Screen.devicePixelRatio * 360;
  169. property string labelFilter: ""
  170. onVisibilityChanged:
  171. {
  172. // force updating the model to sync it with addedSettingsModel
  173. if(visible)
  174. {
  175. listview.model.forceUpdate()
  176. }
  177. }
  178. TextField {
  179. id: filter
  180. anchors {
  181. top: parent.top
  182. left: parent.left
  183. right: toggleShowAll.left
  184. rightMargin: UM.Theme.getSize("default_margin").width
  185. }
  186. placeholderText: catalog.i18nc("@label:textbox", "Filter...");
  187. onTextChanged:
  188. {
  189. if(text != "")
  190. {
  191. listview.model.filter = {"settable_per_mesh": true, "i18n_label": "*" + text}
  192. }
  193. else
  194. {
  195. listview.model.filter = {"settable_per_mesh": true}
  196. }
  197. }
  198. }
  199. CheckBox
  200. {
  201. id: toggleShowAll
  202. anchors {
  203. top: parent.top
  204. right: parent.right
  205. }
  206. text: catalog.i18nc("@label:checkbox", "Show all")
  207. checked: listview.model.showAll
  208. onClicked:
  209. {
  210. listview.model.showAll = checked;
  211. }
  212. }
  213. ScrollView
  214. {
  215. id: scrollView
  216. anchors
  217. {
  218. top: filter.bottom;
  219. left: parent.left;
  220. right: parent.right;
  221. bottom: parent.bottom;
  222. }
  223. ListView
  224. {
  225. id:listview
  226. model: UM.SettingDefinitionsModel
  227. {
  228. id: definitionsModel;
  229. containerId: Cura.MachineManager.activeDefinitionId
  230. filter:
  231. {
  232. "settable_per_mesh": true
  233. }
  234. visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
  235. expanded: [ "*" ]
  236. exclude: [ "machine_settings", "command_line_settings" ]
  237. }
  238. delegate:Loader
  239. {
  240. id: loader
  241. width: parent.width
  242. height: model.type != undefined ? UM.Theme.getSize("section").height : 0;
  243. property var definition: model
  244. property var settingDefinitionsModel: definitionsModel
  245. asynchronous: true
  246. source:
  247. {
  248. switch(model.type)
  249. {
  250. case "category":
  251. return "PerObjectCategory.qml"
  252. default:
  253. return "PerObjectItem.qml"
  254. }
  255. }
  256. }
  257. }
  258. }
  259. rightButtons: [
  260. Button {
  261. text: catalog.i18nc("@action:button", "Close");
  262. onClicked: {
  263. settingPickDialog.visible = false;
  264. }
  265. }
  266. ]
  267. }
  268. UM.SettingPropertyProvider
  269. {
  270. id: machineExtruderCount
  271. containerStackId: Cura.MachineManager.activeMachineId
  272. key: "machine_extruder_count"
  273. watchedProperties: [ "value" ]
  274. storeIndex: 0
  275. }
  276. SystemPalette { id: palette; }
  277. Component
  278. {
  279. id: settingTextField;
  280. Cura.SettingTextField { }
  281. }
  282. Component
  283. {
  284. id: settingComboBox;
  285. Cura.SettingComboBox { }
  286. }
  287. Component
  288. {
  289. id: settingExtruder;
  290. Cura.SettingExtruder { }
  291. }
  292. Component
  293. {
  294. id: settingOptionalExtruder
  295. Cura.SettingOptionalExtruder { }
  296. }
  297. Component
  298. {
  299. id: settingCheckBox;
  300. Cura.SettingCheckBox { }
  301. }
  302. Component
  303. {
  304. id: settingCategory;
  305. Cura.SettingCategory { }
  306. }
  307. Component
  308. {
  309. id: settingUnknown;
  310. Cura.SettingUnknown { }
  311. }
  312. }