CustomPrintSetup.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.0
  5. import UM 1.3 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. id: customPrintSetup
  10. property real padding: UM.Theme.getSize("default_margin").width
  11. property bool multipleExtruders: extrudersModel.count > 1
  12. property var extrudersModel: CuraApplication.getExtrudersModel()
  13. // Profile selector row
  14. GlobalProfileSelector
  15. {
  16. id: globalProfileRow
  17. anchors
  18. {
  19. top: parent.top
  20. topMargin: parent.padding
  21. left: parent.left
  22. leftMargin: parent.padding
  23. right: parent.right
  24. rightMargin: parent.padding
  25. }
  26. }
  27. UM.TabRow
  28. {
  29. id: tabBar
  30. visible: multipleExtruders // The tab row is only visible when there are more than 1 extruder
  31. anchors
  32. {
  33. top: globalProfileRow.bottom
  34. topMargin: UM.Theme.getSize("default_margin").height
  35. left: parent.left
  36. leftMargin: parent.padding
  37. right: parent.right
  38. rightMargin: parent.padding
  39. }
  40. Repeater
  41. {
  42. id: repeater
  43. model: extrudersModel
  44. delegate: UM.TabRowButton
  45. {
  46. contentItem: Item
  47. {
  48. Cura.ExtruderIcon
  49. {
  50. anchors.horizontalCenter: parent.horizontalCenter
  51. materialColor: model.color
  52. extruderEnabled: model.enabled
  53. }
  54. }
  55. onClicked:
  56. {
  57. Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
  58. }
  59. }
  60. }
  61. //When active extruder changes for some other reason, switch tabs.
  62. //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
  63. //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
  64. Connections
  65. {
  66. target: Cura.ExtruderManager
  67. onActiveExtruderChanged:
  68. {
  69. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  70. }
  71. }
  72. //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
  73. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
  74. //Therefore we need to change it back to what it was: The active extruder index.
  75. Connections
  76. {
  77. target: repeater.model
  78. onModelChanged:
  79. {
  80. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
  81. }
  82. }
  83. }
  84. Rectangle
  85. {
  86. anchors
  87. {
  88. top: tabBar.visible ? tabBar.bottom : globalProfileRow.bottom
  89. topMargin: -UM.Theme.getSize("default_lining").width
  90. left: parent.left
  91. leftMargin: parent.padding
  92. right: parent.right
  93. rightMargin: parent.padding
  94. bottom: parent.bottom
  95. }
  96. z: tabBar.z - 1
  97. // Don't show the border when only one extruder
  98. border.color: tabBar.visible ? UM.Theme.getColor("lining") : "transparent"
  99. border.width: UM.Theme.getSize("default_lining").width
  100. color: UM.Theme.getColor("main_background")
  101. Cura.SettingView
  102. {
  103. anchors
  104. {
  105. fill: parent
  106. topMargin: UM.Theme.getSize("default_margin").height
  107. leftMargin: UM.Theme.getSize("default_margin").width
  108. // Small space for the scrollbar
  109. rightMargin: UM.Theme.getSize("narrow_margin").width
  110. // Compensate for the negative margin in the parent
  111. bottomMargin: UM.Theme.getSize("default_lining").width
  112. }
  113. }
  114. }
  115. }