PostProcessingPlugin.qml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. // Copyright (c) 2015 Jaime van Kessel, Ultimaker B.V.
  2. // The PostProcessingPlugin 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 QtQuick.Dialogs 1.1
  8. import QtQuick.Window 2.2
  9. import UM 1.2 as UM
  10. import Cura 1.0 as Cura
  11. UM.Dialog
  12. {
  13. id: dialog
  14. title: catalog.i18nc("@title:window", "Post Processing Plugin")
  15. width: 700 * screenScaleFactor;
  16. height: 500 * screenScaleFactor;
  17. minimumWidth: 400 * screenScaleFactor;
  18. minimumHeight: 250 * screenScaleFactor;
  19. Item
  20. {
  21. UM.I18nCatalog{id: catalog; name:"cura"}
  22. id: base
  23. property int columnWidth: Math.round((base.width / 2) - UM.Theme.getSize("default_margin").width)
  24. property int textMargin: Math.round(UM.Theme.getSize("default_margin").width / 2)
  25. property string activeScriptName
  26. SystemPalette{ id: palette }
  27. SystemPalette{ id: disabledPalette; colorGroup: SystemPalette.Disabled }
  28. anchors.fill: parent
  29. ExclusiveGroup
  30. {
  31. id: selectedScriptGroup
  32. }
  33. Item
  34. {
  35. id: activeScripts
  36. anchors.left: parent.left
  37. width: base.columnWidth
  38. height: parent.height
  39. Label
  40. {
  41. id: activeScriptsHeader
  42. text: catalog.i18nc("@label", "Post Processing Scripts")
  43. anchors.top: parent.top
  44. anchors.topMargin: base.textMargin
  45. anchors.left: parent.left
  46. anchors.leftMargin: base.textMargin
  47. anchors.right: parent.right
  48. anchors.rightMargin: base.textMargin
  49. font: UM.Theme.getFont("large")
  50. }
  51. ListView
  52. {
  53. id: activeScriptsList
  54. anchors.top: activeScriptsHeader.bottom
  55. anchors.topMargin: base.textMargin
  56. anchors.left: parent.left
  57. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  58. anchors.right: parent.right
  59. anchors.rightMargin: base.textMargin
  60. height: childrenRect.height
  61. model: manager.scriptList
  62. delegate: Item
  63. {
  64. width: parent.width
  65. height: activeScriptButton.height
  66. Button
  67. {
  68. id: activeScriptButton
  69. text: manager.getScriptLabelByKey(modelData.toString())
  70. exclusiveGroup: selectedScriptGroup
  71. checkable: true
  72. checked: {
  73. if (manager.selectedScriptIndex == index)
  74. {
  75. base.activeScriptName = manager.getScriptLabelByKey(modelData.toString())
  76. return true
  77. }
  78. else
  79. {
  80. return false
  81. }
  82. }
  83. onClicked:
  84. {
  85. forceActiveFocus()
  86. manager.setSelectedScriptIndex(index)
  87. base.activeScriptName = manager.getScriptLabelByKey(modelData.toString())
  88. }
  89. width: parent.width
  90. height: UM.Theme.getSize("setting").height
  91. style: ButtonStyle
  92. {
  93. background: Rectangle
  94. {
  95. color: activeScriptButton.checked ? palette.highlight : "transparent"
  96. width: parent.width
  97. height: parent.height
  98. }
  99. label: Label
  100. {
  101. wrapMode: Text.Wrap
  102. text: control.text
  103. color: activeScriptButton.checked ? palette.highlightedText : palette.text
  104. }
  105. }
  106. }
  107. Button
  108. {
  109. id: removeButton
  110. text: "x"
  111. width: 20 * screenScaleFactor
  112. height: 20 * screenScaleFactor
  113. anchors.right:parent.right
  114. anchors.rightMargin: base.textMargin
  115. anchors.verticalCenter: parent.verticalCenter
  116. onClicked: manager.removeScriptByIndex(index)
  117. style: ButtonStyle
  118. {
  119. label: Item
  120. {
  121. UM.RecolorImage
  122. {
  123. anchors.verticalCenter: parent.verticalCenter
  124. anchors.horizontalCenter: parent.horizontalCenter
  125. width: Math.round(control.width / 2.7)
  126. height: Math.round(control.height / 2.7)
  127. sourceSize.width: width
  128. sourceSize.height: width
  129. color: palette.text
  130. source: UM.Theme.getIcon("cross1")
  131. }
  132. }
  133. }
  134. }
  135. Button
  136. {
  137. id: downButton
  138. text: ""
  139. anchors.right: removeButton.left
  140. anchors.verticalCenter: parent.verticalCenter
  141. enabled: index != manager.scriptList.length - 1
  142. width: 20 * screenScaleFactor
  143. height: 20 * screenScaleFactor
  144. onClicked:
  145. {
  146. if (manager.selectedScriptIndex == index)
  147. {
  148. manager.setSelectedScriptIndex(index + 1)
  149. }
  150. return manager.moveScript(index, index + 1)
  151. }
  152. style: ButtonStyle
  153. {
  154. label: Item
  155. {
  156. UM.RecolorImage
  157. {
  158. anchors.verticalCenter: parent.verticalCenter
  159. anchors.horizontalCenter: parent.horizontalCenter
  160. width: Math.round(control.width / 2.5)
  161. height: Math.round(control.height / 2.5)
  162. sourceSize.width: width
  163. sourceSize.height: width
  164. color: control.enabled ? palette.text : disabledPalette.text
  165. source: UM.Theme.getIcon("arrow_bottom")
  166. }
  167. }
  168. }
  169. }
  170. Button
  171. {
  172. id: upButton
  173. text: ""
  174. enabled: index != 0
  175. width: 20 * screenScaleFactor
  176. height: 20 * screenScaleFactor
  177. anchors.right: downButton.left
  178. anchors.verticalCenter: parent.verticalCenter
  179. onClicked:
  180. {
  181. if (manager.selectedScriptIndex == index)
  182. {
  183. manager.setSelectedScriptIndex(index - 1)
  184. }
  185. return manager.moveScript(index, index - 1)
  186. }
  187. style: ButtonStyle
  188. {
  189. label: Item
  190. {
  191. UM.RecolorImage
  192. {
  193. anchors.verticalCenter: parent.verticalCenter
  194. anchors.horizontalCenter: parent.horizontalCenter
  195. width: Math.round(control.width / 2.5)
  196. height: Math.round(control.height / 2.5)
  197. sourceSize.width: width
  198. sourceSize.height: width
  199. color: control.enabled ? palette.text : disabledPalette.text
  200. source: UM.Theme.getIcon("arrow_top")
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. Button
  208. {
  209. id: addButton
  210. text: catalog.i18nc("@action", "Add a script")
  211. anchors.left: parent.left
  212. anchors.leftMargin: base.textMargin
  213. anchors.top: activeScriptsList.bottom
  214. anchors.topMargin: base.textMargin
  215. menu: scriptsMenu
  216. style: ButtonStyle
  217. {
  218. label: Label
  219. {
  220. text: control.text
  221. }
  222. }
  223. }
  224. Menu
  225. {
  226. id: scriptsMenu
  227. Instantiator
  228. {
  229. model: manager.loadedScriptList
  230. MenuItem
  231. {
  232. text: manager.getScriptLabelByKey(modelData.toString())
  233. onTriggered: manager.addScriptToList(modelData.toString())
  234. }
  235. onObjectAdded: scriptsMenu.insertItem(index, object);
  236. onObjectRemoved: scriptsMenu.removeItem(object);
  237. }
  238. }
  239. }
  240. Rectangle
  241. {
  242. color: UM.Theme.getColor("sidebar")
  243. anchors.left: activeScripts.right
  244. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  245. anchors.right: parent.right
  246. height: parent.height
  247. id: settingsPanel
  248. Label
  249. {
  250. id: scriptSpecsHeader
  251. text: manager.selectedScriptIndex == -1 ? catalog.i18nc("@label", "Settings") : base.activeScriptName
  252. anchors.top: parent.top
  253. anchors.topMargin: base.textMargin
  254. anchors.left: parent.left
  255. anchors.leftMargin: base.textMargin
  256. anchors.right: parent.right
  257. anchors.rightMargin: base.textMargin
  258. height: 20 * screenScaleFactor
  259. font: UM.Theme.getFont("large")
  260. color: UM.Theme.getColor("text")
  261. }
  262. ScrollView
  263. {
  264. id: scrollView
  265. anchors.top: scriptSpecsHeader.bottom
  266. anchors.topMargin: settingsPanel.textMargin
  267. anchors.left: parent.left
  268. anchors.right: parent.right
  269. anchors.bottom: parent.bottom
  270. visible: manager.selectedScriptDefinitionId != ""
  271. style: UM.Theme.styles.scrollview;
  272. ListView
  273. {
  274. id: listview
  275. spacing: UM.Theme.getSize("default_lining").height
  276. model: UM.SettingDefinitionsModel
  277. {
  278. id: definitionsModel;
  279. containerId: manager.selectedScriptDefinitionId
  280. showAll: true
  281. }
  282. delegate:Loader
  283. {
  284. id: settingLoader
  285. width: parent.width
  286. height:
  287. {
  288. if(provider.properties.enabled == "True")
  289. {
  290. if(model.type != undefined)
  291. {
  292. return UM.Theme.getSize("section").height;
  293. }
  294. else
  295. {
  296. return 0;
  297. }
  298. }
  299. else
  300. {
  301. return 0;
  302. }
  303. }
  304. Behavior on height { NumberAnimation { duration: 100 } }
  305. opacity: provider.properties.enabled == "True" ? 1 : 0
  306. Behavior on opacity { NumberAnimation { duration: 100 } }
  307. enabled: opacity > 0
  308. property var definition: model
  309. property var settingDefinitionsModel: definitionsModel
  310. property var propertyProvider: provider
  311. property var globalPropertyProvider: inheritStackProvider
  312. //Qt5.4.2 and earlier has a bug where this causes a crash: https://bugreports.qt.io/browse/QTBUG-35989
  313. //In addition, while it works for 5.5 and higher, the ordering of the actual combo box drop down changes,
  314. //causing nasty issues when selecting different options. So disable asynchronous loading of enum type completely.
  315. asynchronous: model.type != "enum" && model.type != "extruder"
  316. onLoaded: {
  317. settingLoader.item.showRevertButton = false
  318. settingLoader.item.showInheritButton = false
  319. settingLoader.item.showLinkedSettingIcon = false
  320. settingLoader.item.doDepthIndentation = true
  321. settingLoader.item.doQualityUserSettingEmphasis = false
  322. }
  323. sourceComponent:
  324. {
  325. switch(model.type)
  326. {
  327. case "int":
  328. return settingTextField
  329. case "float":
  330. return settingTextField
  331. case "enum":
  332. return settingComboBox
  333. case "extruder":
  334. return settingExtruder
  335. case "bool":
  336. return settingCheckBox
  337. case "str":
  338. return settingTextField
  339. case "category":
  340. return settingCategory
  341. default:
  342. return settingUnknown
  343. }
  344. }
  345. UM.SettingPropertyProvider
  346. {
  347. id: provider
  348. containerStackId: manager.selectedScriptStackId
  349. key: model.key ? model.key : "None"
  350. watchedProperties: [ "value", "enabled", "state", "validationState" ]
  351. storeIndex: 0
  352. }
  353. // Specialty provider that only watches global_inherits (we cant filter on what property changed we get events
  354. // so we bypass that to make a dedicated provider).
  355. UM.SettingPropertyProvider
  356. {
  357. id: inheritStackProvider
  358. containerStackId: Cura.MachineManager.activeMachineId
  359. key: model.key ? model.key : "None"
  360. watchedProperties: [ "limit_to_extruder" ]
  361. }
  362. Connections
  363. {
  364. target: item
  365. onShowTooltip:
  366. {
  367. tooltip.text = text;
  368. var position = settingLoader.mapToItem(settingsPanel, settingsPanel.x, 0);
  369. tooltip.show(position);
  370. tooltip.target.x = position.x + 1
  371. }
  372. onHideTooltip:
  373. {
  374. tooltip.hide();
  375. }
  376. }
  377. }
  378. }
  379. }
  380. }
  381. Cura.SidebarTooltip
  382. {
  383. id: tooltip
  384. }
  385. Component
  386. {
  387. id: settingTextField;
  388. Cura.SettingTextField { }
  389. }
  390. Component
  391. {
  392. id: settingComboBox;
  393. Cura.SettingComboBox { }
  394. }
  395. Component
  396. {
  397. id: settingExtruder;
  398. Cura.SettingExtruder { }
  399. }
  400. Component
  401. {
  402. id: settingCheckBox;
  403. Cura.SettingCheckBox { }
  404. }
  405. Component
  406. {
  407. id: settingCategory;
  408. Cura.SettingCategory { }
  409. }
  410. Component
  411. {
  412. id: settingUnknown;
  413. Cura.SettingUnknown { }
  414. }
  415. }
  416. rightButtons: Button
  417. {
  418. text: catalog.i18nc("@action:button", "Close")
  419. iconName: "dialog-close"
  420. onClicked: dialog.accept()
  421. }
  422. Button {
  423. objectName: "postProcessingSaveAreaButton"
  424. visible: activeScriptsList.count > 0
  425. height: UM.Theme.getSize("save_button_save_to_button").height
  426. width: height
  427. tooltip: catalog.i18nc("@info:tooltip", "Change active post-processing scripts")
  428. onClicked: dialog.show()
  429. style: ButtonStyle {
  430. background: Rectangle {
  431. id: deviceSelectionIcon
  432. border.width: UM.Theme.getSize("default_lining").width
  433. border.color: !control.enabled ? UM.Theme.getColor("action_button_disabled_border") :
  434. control.pressed ? UM.Theme.getColor("action_button_active_border") :
  435. control.hovered ? UM.Theme.getColor("action_button_hovered_border") : UM.Theme.getColor("action_button_border")
  436. color: !control.enabled ? UM.Theme.getColor("action_button_disabled") :
  437. control.pressed ? UM.Theme.getColor("action_button_active") :
  438. control.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  439. Behavior on color { ColorAnimation { duration: 50; } }
  440. anchors.left: parent.left
  441. anchors.leftMargin: Math.round(UM.Theme.getSize("save_button_text_margin").width / 2);
  442. width: parent.height
  443. height: parent.height
  444. UM.RecolorImage {
  445. anchors.verticalCenter: parent.verticalCenter
  446. anchors.horizontalCenter: parent.horizontalCenter
  447. width: Math.round(parent.width / 2)
  448. height: Math.round(parent.height / 2)
  449. sourceSize.width: width
  450. sourceSize.height: height
  451. color: !control.enabled ? UM.Theme.getColor("action_button_disabled_text") :
  452. control.pressed ? UM.Theme.getColor("action_button_active_text") :
  453. control.hovered ? UM.Theme.getColor("action_button_hovered_text") : UM.Theme.getColor("action_button_text");
  454. source: "postprocessing.svg"
  455. }
  456. }
  457. label: Label{ }
  458. }
  459. }
  460. }