CustomPrintSetup.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 QtQuick.Controls 1.1 as OldControls
  6. import UM 1.3 as UM
  7. import Cura 1.0 as Cura
  8. Item
  9. {
  10. id: customPrintSetup
  11. property real padding: UM.Theme.getSize("default_margin").width
  12. property bool multipleExtruders: extrudersModel.count > 1
  13. property var extrudersModel: CuraApplication.getExtrudersModel()
  14. // Profile selector row
  15. GlobalProfileSelector
  16. {
  17. id: globalProfileRow
  18. anchors
  19. {
  20. top: parent.top
  21. left: parent.left
  22. right: parent.right
  23. margins: parent.padding
  24. }
  25. }
  26. Item
  27. {
  28. id: intent
  29. height: childrenRect.height
  30. anchors
  31. {
  32. top: globalProfileRow.bottom
  33. topMargin: UM.Theme.getSize("default_margin").height
  34. left: parent.left
  35. leftMargin: parent.padding
  36. right: parent.right
  37. rightMargin: parent.padding
  38. }
  39. Label
  40. {
  41. id: intentLabel
  42. anchors
  43. {
  44. top: parent.top
  45. bottom: parent.bottom
  46. left: parent.left
  47. right: intentSelection.left
  48. }
  49. text: catalog.i18nc("@label", "Intent")
  50. font: UM.Theme.getFont("medium")
  51. color: UM.Theme.getColor("text")
  52. verticalAlignment: Text.AlignVCenter
  53. }
  54. OldControls.ToolButton
  55. {
  56. id: intentSelection
  57. text: Cura.MachineManager.activeStack != null ? Cura.MachineManager.activeStack.intent.name : ""
  58. tooltip: text
  59. height: UM.Theme.getSize("print_setup_big_item").height
  60. width: UM.Theme.getSize("print_setup_big_item").width
  61. anchors.right: parent.right
  62. style: UM.Theme.styles.print_setup_header_button
  63. activeFocusOnPress: true
  64. menu: Cura.IntentMenu { extruderIndex: Cura.ExtruderManager.activeExtruderIndex }
  65. }
  66. }
  67. UM.TabRow
  68. {
  69. id: tabBar
  70. visible: multipleExtruders // The tab row is only visible when there are more than 1 extruder
  71. anchors
  72. {
  73. top: intent.bottom
  74. topMargin: UM.Theme.getSize("default_margin").height
  75. left: parent.left
  76. leftMargin: parent.padding
  77. right: parent.right
  78. rightMargin: parent.padding
  79. }
  80. Repeater
  81. {
  82. id: repeater
  83. model: extrudersModel
  84. delegate: UM.TabRowButton
  85. {
  86. contentItem: Item
  87. {
  88. Cura.ExtruderIcon
  89. {
  90. anchors.horizontalCenter: parent.horizontalCenter
  91. materialColor: model.color
  92. extruderEnabled: model.enabled
  93. }
  94. }
  95. onClicked:
  96. {
  97. Cura.ExtruderManager.setActiveExtruderIndex(tabBar.currentIndex)
  98. }
  99. }
  100. }
  101. //When active extruder changes for some other reason, switch tabs.
  102. //Don't directly link currentIndex to Cura.ExtruderManager.activeExtruderIndex!
  103. //This causes a segfault in Qt 5.11. Something with VisualItemModel removing index -1. We have to use setCurrentIndex instead.
  104. Connections
  105. {
  106. target: Cura.ExtruderManager
  107. onActiveExtruderChanged:
  108. {
  109. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex);
  110. }
  111. }
  112. //When the model of the extruders is rebuilt, the list of extruders is briefly emptied and rebuilt.
  113. //This causes the currentIndex of the tab to be in an invalid position which resets it to 0.
  114. //Therefore we need to change it back to what it was: The active extruder index.
  115. Connections
  116. {
  117. target: repeater.model
  118. onModelChanged:
  119. {
  120. tabBar.setCurrentIndex(Cura.ExtruderManager.activeExtruderIndex)
  121. }
  122. }
  123. }
  124. Rectangle
  125. {
  126. anchors
  127. {
  128. top: tabBar.visible ? tabBar.bottom : globalProfileRow.bottom
  129. topMargin: -UM.Theme.getSize("default_lining").width
  130. left: parent.left
  131. leftMargin: parent.padding
  132. right: parent.right
  133. rightMargin: parent.padding
  134. bottom: parent.bottom
  135. }
  136. z: tabBar.z - 1
  137. // Don't show the border when only one extruder
  138. border.color: tabBar.visible ? UM.Theme.getColor("lining") : "transparent"
  139. border.width: UM.Theme.getSize("default_lining").width
  140. color: UM.Theme.getColor("main_background")
  141. Cura.SettingView
  142. {
  143. anchors
  144. {
  145. fill: parent
  146. topMargin: UM.Theme.getSize("default_margin").height
  147. leftMargin: UM.Theme.getSize("default_margin").width
  148. // Small space for the scrollbar
  149. rightMargin: UM.Theme.getSize("narrow_margin").width
  150. // Compensate for the negative margin in the parent
  151. bottomMargin: UM.Theme.getSize("default_lining").width
  152. }
  153. }
  154. }
  155. }