SimulationViewMenuComponent.qml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.4
  4. import QtQuick.Controls 1.2
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Controls.Styles 1.1
  7. import QtGraphicalEffects 1.0
  8. import UM 1.0 as UM
  9. import Cura 1.0 as Cura
  10. Cura.ExpandableComponent
  11. {
  12. id: base
  13. dragPreferencesNamePrefix: "view/colorscheme"
  14. contentHeaderTitle: catalog.i18nc("@label", "Color scheme")
  15. Connections
  16. {
  17. target: UM.Preferences
  18. onPreferenceChanged:
  19. {
  20. if (preference !== "view/only_show_top_layers" && preference !== "view/top_layer_count" && ! preference.match("layerview/"))
  21. {
  22. return;
  23. }
  24. layerTypeCombobox.currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type")
  25. layerTypeCombobox.updateLegends(layerTypeCombobox.currentIndex)
  26. viewSettings.extruder_opacities = UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  27. viewSettings.show_travel_moves = UM.Preferences.getValue("layerview/show_travel_moves")
  28. viewSettings.show_helpers = UM.Preferences.getValue("layerview/show_helpers")
  29. viewSettings.show_skin = UM.Preferences.getValue("layerview/show_skin")
  30. viewSettings.show_infill = UM.Preferences.getValue("layerview/show_infill")
  31. viewSettings.only_show_top_layers = UM.Preferences.getValue("view/only_show_top_layers")
  32. viewSettings.top_layer_count = UM.Preferences.getValue("view/top_layer_count")
  33. }
  34. }
  35. headerItem: Item
  36. {
  37. Label
  38. {
  39. id: colorSchemeLabel
  40. text: catalog.i18nc("@label", "Color scheme")
  41. verticalAlignment: Text.AlignVCenter
  42. height: parent.height
  43. elide: Text.ElideRight
  44. font: UM.Theme.getFont("medium")
  45. color: UM.Theme.getColor("text_medium")
  46. renderType: Text.NativeRendering
  47. }
  48. Label
  49. {
  50. text: layerTypeCombobox.currentText
  51. verticalAlignment: Text.AlignVCenter
  52. anchors
  53. {
  54. left: colorSchemeLabel.right
  55. leftMargin: UM.Theme.getSize("default_margin").width
  56. right: parent.right
  57. }
  58. height: parent.height
  59. elide: Text.ElideRight
  60. font: UM.Theme.getFont("medium")
  61. color: UM.Theme.getColor("text")
  62. renderType: Text.NativeRendering
  63. }
  64. }
  65. contentItem: Column
  66. {
  67. id: viewSettings
  68. property var extruder_opacities: UM.Preferences.getValue("layerview/extruder_opacities").split("|")
  69. property bool show_travel_moves: UM.Preferences.getValue("layerview/show_travel_moves")
  70. property bool show_helpers: UM.Preferences.getValue("layerview/show_helpers")
  71. property bool show_skin: UM.Preferences.getValue("layerview/show_skin")
  72. property bool show_infill: UM.Preferences.getValue("layerview/show_infill")
  73. property bool show_starts: UM.Preferences.getValue("layerview/show_starts")
  74. // If we are in compatibility mode, we only show the "line type"
  75. property bool show_legend: UM.SimulationView.compatibilityMode ? true : UM.Preferences.getValue("layerview/layer_view_type") == 1
  76. property bool show_gradient: UM.SimulationView.compatibilityMode ? false : UM.Preferences.getValue("layerview/layer_view_type") == 2 || UM.Preferences.getValue("layerview/layer_view_type") == 3
  77. property bool show_feedrate_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 2
  78. property bool show_thickness_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 3
  79. property bool show_line_width_gradient: show_gradient && UM.Preferences.getValue("layerview/layer_view_type") == 4
  80. property bool only_show_top_layers: UM.Preferences.getValue("view/only_show_top_layers")
  81. property int top_layer_count: UM.Preferences.getValue("view/top_layer_count")
  82. width: UM.Theme.getSize("layerview_menu_size").width - 2 * UM.Theme.getSize("default_margin").width
  83. height: implicitHeight
  84. spacing: UM.Theme.getSize("layerview_row_spacing").height
  85. ListModel // matches SimulationView.py
  86. {
  87. id: layerViewTypes
  88. }
  89. Component.onCompleted:
  90. {
  91. layerViewTypes.append({
  92. text: catalog.i18nc("@label:listbox", "Material Color"),
  93. type_id: 0
  94. })
  95. layerViewTypes.append({
  96. text: catalog.i18nc("@label:listbox", "Line Type"),
  97. type_id: 1
  98. })
  99. layerViewTypes.append({
  100. text: catalog.i18nc("@label:listbox", "Speed"),
  101. type_id: 2
  102. })
  103. layerViewTypes.append({
  104. text: catalog.i18nc("@label:listbox", "Layer Thickness"),
  105. type_id: 3 // these ids match the switching in the shader
  106. })
  107. layerViewTypes.append({
  108. text: catalog.i18nc("@label:listbox", "Line Width"),
  109. type_id: 4
  110. })
  111. }
  112. ComboBox
  113. {
  114. id: layerTypeCombobox
  115. width: parent.width
  116. model: layerViewTypes
  117. visible: !UM.SimulationView.compatibilityMode
  118. style: UM.Theme.styles.combobox
  119. onActivated:
  120. {
  121. UM.Preferences.setValue("layerview/layer_view_type", index);
  122. }
  123. Component.onCompleted:
  124. {
  125. currentIndex = UM.SimulationView.compatibilityMode ? 1 : UM.Preferences.getValue("layerview/layer_view_type");
  126. updateLegends(currentIndex);
  127. }
  128. function updateLegends(type_id)
  129. {
  130. // Update the visibility of the legends.
  131. viewSettings.show_legend = UM.SimulationView.compatibilityMode || (type_id == 1);
  132. viewSettings.show_gradient = !UM.SimulationView.compatibilityMode && (type_id == 2 || type_id == 3 || type_id == 4);
  133. viewSettings.show_feedrate_gradient = viewSettings.show_gradient && (type_id == 2);
  134. viewSettings.show_thickness_gradient = viewSettings.show_gradient && (type_id == 3);
  135. viewSettings.show_line_width_gradient = viewSettings.show_gradient && (type_id == 4);
  136. }
  137. }
  138. Label
  139. {
  140. id: compatibilityModeLabel
  141. text: catalog.i18nc("@label", "Compatibility Mode")
  142. font: UM.Theme.getFont("default")
  143. color: UM.Theme.getColor("text")
  144. visible: UM.SimulationView.compatibilityMode
  145. height: UM.Theme.getSize("layerview_row").height
  146. width: parent.width
  147. renderType: Text.NativeRendering
  148. }
  149. Item // Spacer
  150. {
  151. height: UM.Theme.getSize("narrow_margin").width
  152. width: width
  153. }
  154. Repeater
  155. {
  156. model: CuraApplication.getExtrudersModel()
  157. CheckBox
  158. {
  159. id: extrudersModelCheckBox
  160. checked: viewSettings.extruder_opacities[index] > 0.5 || viewSettings.extruder_opacities[index] == undefined || viewSettings.extruder_opacities[index] == ""
  161. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  162. width: parent.width
  163. visible: !UM.SimulationView.compatibilityMode
  164. onClicked:
  165. {
  166. viewSettings.extruder_opacities[index] = checked ? 1.0 : 0.0
  167. UM.Preferences.setValue("layerview/extruder_opacities", viewSettings.extruder_opacities.join("|"));
  168. }
  169. style: UM.Theme.styles.checkbox
  170. UM.RecolorImage
  171. {
  172. id: swatch
  173. anchors.verticalCenter: parent.verticalCenter
  174. anchors.right: extrudersModelCheckBox.right
  175. width: UM.Theme.getSize("layerview_legend_size").width
  176. height: UM.Theme.getSize("layerview_legend_size").height
  177. source: UM.Theme.getIcon("extruder_button")
  178. color: model.color
  179. }
  180. Label
  181. {
  182. text: model.name
  183. elide: Text.ElideRight
  184. color: UM.Theme.getColor("setting_control_text")
  185. font: UM.Theme.getFont("default")
  186. anchors
  187. {
  188. verticalCenter: parent.verticalCenter
  189. left: extrudersModelCheckBox.left
  190. right: extrudersModelCheckBox.right
  191. leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  192. rightMargin: UM.Theme.getSize("default_margin").width * 2
  193. }
  194. renderType: Text.NativeRendering
  195. }
  196. }
  197. }
  198. Repeater
  199. {
  200. model: ListModel
  201. {
  202. id: typesLegendModel
  203. Component.onCompleted:
  204. {
  205. typesLegendModel.append({
  206. label: catalog.i18nc("@label", "Travels"),
  207. initialValue: viewSettings.show_travel_moves,
  208. preference: "layerview/show_travel_moves",
  209. colorId: "layerview_move_combing"
  210. });
  211. typesLegendModel.append({
  212. label: catalog.i18nc("@label", "Helpers"),
  213. initialValue: viewSettings.show_helpers,
  214. preference: "layerview/show_helpers",
  215. colorId: "layerview_support"
  216. });
  217. typesLegendModel.append({
  218. label: catalog.i18nc("@label", "Shell"),
  219. initialValue: viewSettings.show_skin,
  220. preference: "layerview/show_skin",
  221. colorId: "layerview_inset_0"
  222. });
  223. typesLegendModel.append({
  224. label: catalog.i18nc("@label", "Infill"),
  225. initialValue: viewSettings.show_infill,
  226. preference: "layerview/show_infill",
  227. colorId: "layerview_infill"
  228. });
  229. if (! UM.SimulationView.compatibilityMode)
  230. {
  231. typesLegendModel.append({
  232. label: catalog.i18nc("@label", "Starts"),
  233. initialValue: viewSettings.show_starts,
  234. preference: "layerview/show_starts",
  235. colorId: "layerview_starts"
  236. });
  237. }
  238. }
  239. }
  240. CheckBox
  241. {
  242. id: legendModelCheckBox
  243. checked: model.initialValue
  244. onClicked: UM.Preferences.setValue(model.preference, checked)
  245. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  246. width: parent.width
  247. style: UM.Theme.styles.checkbox
  248. Rectangle
  249. {
  250. anchors.verticalCenter: parent.verticalCenter
  251. anchors.right: legendModelCheckBox.right
  252. width: UM.Theme.getSize("layerview_legend_size").width
  253. height: UM.Theme.getSize("layerview_legend_size").height
  254. color: UM.Theme.getColor(model.colorId)
  255. border.width: UM.Theme.getSize("default_lining").width
  256. border.color: UM.Theme.getColor("lining")
  257. visible: viewSettings.show_legend
  258. }
  259. Label
  260. {
  261. text: label
  262. font: UM.Theme.getFont("default")
  263. elide: Text.ElideRight
  264. renderType: Text.NativeRendering
  265. color: UM.Theme.getColor("setting_control_text")
  266. anchors.verticalCenter: parent.verticalCenter
  267. anchors.left: legendModelCheckBox.left
  268. anchors.right: legendModelCheckBox.right
  269. anchors.leftMargin: UM.Theme.getSize("checkbox").width + Math.round(UM.Theme.getSize("default_margin").width / 2)
  270. anchors.rightMargin: UM.Theme.getSize("default_margin").width * 2
  271. }
  272. }
  273. }
  274. CheckBox
  275. {
  276. checked: viewSettings.only_show_top_layers
  277. onClicked: UM.Preferences.setValue("view/only_show_top_layers", checked ? 1.0 : 0.0)
  278. text: catalog.i18nc("@label", "Only Show Top Layers")
  279. visible: UM.SimulationView.compatibilityMode
  280. style: UM.Theme.styles.checkbox
  281. width: parent.width
  282. }
  283. CheckBox
  284. {
  285. checked: viewSettings.top_layer_count == 5
  286. onClicked: UM.Preferences.setValue("view/top_layer_count", checked ? 5 : 1)
  287. text: catalog.i18nc("@label", "Show 5 Detailed Layers On Top")
  288. width: parent.width
  289. visible: UM.SimulationView.compatibilityMode
  290. style: UM.Theme.styles.checkbox
  291. }
  292. Repeater
  293. {
  294. model: ListModel
  295. {
  296. id: typesLegendModelNoCheck
  297. Component.onCompleted:
  298. {
  299. typesLegendModelNoCheck.append({
  300. label: catalog.i18nc("@label", "Top / Bottom"),
  301. colorId: "layerview_skin",
  302. });
  303. typesLegendModelNoCheck.append({
  304. label: catalog.i18nc("@label", "Inner Wall"),
  305. colorId: "layerview_inset_x",
  306. });
  307. }
  308. }
  309. Label
  310. {
  311. text: label
  312. visible: viewSettings.show_legend
  313. id: typesLegendModelLabel
  314. height: UM.Theme.getSize("layerview_row").height + UM.Theme.getSize("default_lining").height
  315. width: parent.width
  316. color: UM.Theme.getColor("setting_control_text")
  317. font: UM.Theme.getFont("default")
  318. renderType: Text.NativeRendering
  319. Rectangle
  320. {
  321. anchors.verticalCenter: parent.verticalCenter
  322. anchors.right: typesLegendModelLabel.right
  323. width: UM.Theme.getSize("layerview_legend_size").width
  324. height: UM.Theme.getSize("layerview_legend_size").height
  325. color: UM.Theme.getColor(model.colorId)
  326. border.width: UM.Theme.getSize("default_lining").width
  327. border.color: UM.Theme.getColor("lining")
  328. }
  329. }
  330. }
  331. // Text for the minimum, maximum and units for the feedrates and layer thickness
  332. Item
  333. {
  334. id: gradientLegend
  335. visible: viewSettings.show_gradient
  336. width: parent.width
  337. height: UM.Theme.getSize("layerview_row").height
  338. Label //Minimum value.
  339. {
  340. text:
  341. {
  342. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  343. {
  344. // Feedrate selected
  345. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  346. {
  347. return parseFloat(UM.SimulationView.getMinFeedrate()).toFixed(2)
  348. }
  349. // Layer thickness selected
  350. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  351. {
  352. return parseFloat(UM.SimulationView.getMinThickness()).toFixed(2)
  353. }
  354. //Line width selected
  355. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  356. {
  357. return parseFloat(UM.SimulationView.getMinLineWidth()).toFixed(2);
  358. }
  359. }
  360. return catalog.i18nc("@label","min")
  361. }
  362. anchors.left: parent.left
  363. color: UM.Theme.getColor("setting_control_text")
  364. font: UM.Theme.getFont("default")
  365. renderType: Text.NativeRendering
  366. }
  367. Label //Unit in the middle.
  368. {
  369. text:
  370. {
  371. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  372. {
  373. // Feedrate selected
  374. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  375. {
  376. return "mm/s"
  377. }
  378. // Layer thickness selected
  379. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  380. {
  381. return "mm"
  382. }
  383. //Line width selected
  384. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  385. {
  386. return "mm"
  387. }
  388. }
  389. return ""
  390. }
  391. anchors.horizontalCenter: parent.horizontalCenter
  392. color: UM.Theme.getColor("setting_control_text")
  393. font: UM.Theme.getFont("default")
  394. }
  395. Label //Maximum value.
  396. {
  397. text: {
  398. if (UM.SimulationView.layerActivity && CuraApplication.platformActivity)
  399. {
  400. // Feedrate selected
  401. if (UM.Preferences.getValue("layerview/layer_view_type") == 2)
  402. {
  403. return parseFloat(UM.SimulationView.getMaxFeedrate()).toFixed(2)
  404. }
  405. // Layer thickness selected
  406. if (UM.Preferences.getValue("layerview/layer_view_type") == 3)
  407. {
  408. return parseFloat(UM.SimulationView.getMaxThickness()).toFixed(2)
  409. }
  410. //Line width selected
  411. if(UM.Preferences.getValue("layerview/layer_view_type") == 4)
  412. {
  413. return parseFloat(UM.SimulationView.getMaxLineWidth()).toFixed(2);
  414. }
  415. }
  416. return catalog.i18nc("@label","max")
  417. }
  418. anchors.right: parent.right
  419. color: UM.Theme.getColor("setting_control_text")
  420. font: UM.Theme.getFont("default")
  421. }
  422. }
  423. // Gradient colors for feedrate
  424. Rectangle
  425. {
  426. id: feedrateGradient
  427. visible: viewSettings.show_feedrate_gradient || viewSettings.show_line_width_gradient
  428. anchors.left: parent.left
  429. anchors.right: parent.right
  430. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  431. border.width: UM.Theme.getSize("default_lining").width
  432. border.color: UM.Theme.getColor("lining")
  433. LinearGradient
  434. {
  435. anchors
  436. {
  437. left: parent.left
  438. leftMargin: UM.Theme.getSize("default_lining").width
  439. right: parent.right
  440. rightMargin: UM.Theme.getSize("default_lining").width
  441. top: parent.top
  442. topMargin: UM.Theme.getSize("default_lining").width
  443. bottom: parent.bottom
  444. bottomMargin: UM.Theme.getSize("default_lining").width
  445. }
  446. start: Qt.point(0, 0)
  447. end: Qt.point(parent.width, 0)
  448. gradient: Gradient
  449. {
  450. GradientStop
  451. {
  452. position: 0.000
  453. color: Qt.rgba(0, 0, 1, 1)
  454. }
  455. GradientStop
  456. {
  457. position: 0.25
  458. color: Qt.rgba(0.25, 1, 0, 1)
  459. }
  460. GradientStop
  461. {
  462. position: 0.375
  463. color: Qt.rgba(0.375, 0.5, 0, 1)
  464. }
  465. GradientStop
  466. {
  467. position: 1.0
  468. color: Qt.rgba(1, 0.5, 0, 1)
  469. }
  470. }
  471. }
  472. }
  473. // Gradient colors for layer thickness (similar to parula colormap)
  474. Rectangle
  475. {
  476. id: thicknessGradient
  477. visible: viewSettings.show_thickness_gradient
  478. anchors.left: parent.left
  479. anchors.right: parent.right
  480. height: Math.round(UM.Theme.getSize("layerview_row").height * 1.5)
  481. border.width: UM.Theme.getSize("default_lining").width
  482. border.color: UM.Theme.getColor("lining")
  483. LinearGradient
  484. {
  485. anchors
  486. {
  487. left: parent.left
  488. leftMargin: UM.Theme.getSize("default_lining").width
  489. right: parent.right
  490. rightMargin: UM.Theme.getSize("default_lining").width
  491. top: parent.top
  492. topMargin: UM.Theme.getSize("default_lining").width
  493. bottom: parent.bottom
  494. bottomMargin: UM.Theme.getSize("default_lining").width
  495. }
  496. start: Qt.point(0, 0)
  497. end: Qt.point(parent.width, 0)
  498. gradient: Gradient
  499. {
  500. GradientStop
  501. {
  502. position: 0.000
  503. color: Qt.rgba(0, 0, 0.5, 1)
  504. }
  505. GradientStop
  506. {
  507. position: 0.25
  508. color: Qt.rgba(0, 0.375, 0.75, 1)
  509. }
  510. GradientStop
  511. {
  512. position: 0.5
  513. color: Qt.rgba(0, 0.75, 0.5, 1)
  514. }
  515. GradientStop
  516. {
  517. position: 0.75
  518. color: Qt.rgba(1, 0.75, 0.25, 1)
  519. }
  520. GradientStop
  521. {
  522. position: 1.0
  523. color: Qt.rgba(1, 1, 0, 1)
  524. }
  525. }
  526. }
  527. }
  528. }
  529. FontMetrics
  530. {
  531. id: fontMetrics
  532. font: UM.Theme.getFont("default")
  533. }
  534. }