PrepareMenu.qml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright (c) 2021 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.9
  4. import QtQuick.Layouts 1.1
  5. import QtQuick.Controls 2.3
  6. import UM 1.3 as UM
  7. import Cura 1.1 as Cura
  8. Item
  9. {
  10. id: prepareMenu
  11. property var fileProviderModel: CuraApplication.getFileProviderModel()
  12. UM.I18nCatalog
  13. {
  14. id: catalog
  15. name: "cura"
  16. }
  17. anchors
  18. {
  19. left: parent.left
  20. right: parent.right
  21. leftMargin: UM.Theme.getSize("wide_margin").width * 2
  22. rightMargin: UM.Theme.getSize("wide_margin").width * 2
  23. }
  24. // Item to ensure that all of the buttons are nicely centered.
  25. Item
  26. {
  27. anchors.fill: parent
  28. RowLayout
  29. {
  30. id: itemRow
  31. anchors.left: parent.left
  32. anchors.right: parent.right
  33. anchors.leftMargin: UM.Theme.getSize("default_margin").width + openFileButton.width + openFileMenu.width
  34. property int machineSelectorWidth: Math.round((width - printSetupSelectorItem.width) / 3)
  35. height: parent.height
  36. // This is a trick to make sure that the borders of the two adjacent buttons' borders overlap. Otherwise
  37. // there will be double border (one from each button)
  38. spacing: -UM.Theme.getSize("default_lining").width
  39. Cura.MachineSelector
  40. {
  41. id: machineSelection
  42. headerCornerSide: Cura.RoundedRectangle.Direction.Left
  43. Layout.preferredWidth: parent.machineSelectorWidth
  44. Layout.fillWidth: true
  45. Layout.fillHeight: true
  46. }
  47. Cura.ConfigurationMenu
  48. {
  49. id: printerSetup
  50. Layout.fillHeight: true
  51. Layout.fillWidth: true
  52. Layout.preferredWidth: parent.machineSelectorWidth * 2
  53. }
  54. Item
  55. {
  56. id: printSetupSelectorItem
  57. // This is a work around to prevent the printSetupSelector from having to be re-loaded every time
  58. // a stage switch is done.
  59. children: [printSetupSelector]
  60. height: childrenRect.height
  61. width: childrenRect.width
  62. }
  63. }
  64. //Pop-up shown when there are multiple items to select from.
  65. Cura.ExpandablePopup
  66. {
  67. id: openFileMenu
  68. visible: prepareMenu.fileProviderModel.count > 1
  69. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  70. headerCornerSide: Cura.RoundedRectangle.Direction.All
  71. headerPadding: Math.round((parent.height - UM.Theme.getSize("button_icon").height) / 2)
  72. contentPadding: UM.Theme.getSize("default_lining").width
  73. enabled: visible
  74. height: parent.height
  75. width: visible ? (headerPadding * 3 + UM.Theme.getSize("button_icon").height + iconSize) : 0
  76. headerItem: UM.RecolorImage
  77. {
  78. id: menuIcon
  79. source: UM.Theme.getIcon("Folder", "medium")
  80. color: UM.Theme.getColor("icon")
  81. sourceSize.height: height
  82. }
  83. contentItem: Item
  84. {
  85. id: popup
  86. Column
  87. {
  88. id: openProviderColumn
  89. //The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size.
  90. onChildrenRectChanged:
  91. {
  92. popup.height = childrenRect.height
  93. popup.width = childrenRect.width
  94. }
  95. onPositioningComplete:
  96. {
  97. popup.height = childrenRect.height
  98. popup.width = childrenRect.width
  99. }
  100. Repeater
  101. {
  102. model: prepareMenu.fileProviderModel
  103. delegate: Button
  104. {
  105. leftPadding: UM.Theme.getSize("default_margin").width
  106. rightPadding: UM.Theme.getSize("default_margin").width
  107. width: contentItem.width + leftPadding + rightPadding
  108. height: UM.Theme.getSize("action_button").height
  109. hoverEnabled: true
  110. contentItem: Label
  111. {
  112. text: model.displayText
  113. color: UM.Theme.getColor("text")
  114. font: UM.Theme.getFont("medium")
  115. renderType: Text.NativeRendering
  116. verticalAlignment: Text.AlignVCenter
  117. width: contentWidth
  118. height: parent.height
  119. }
  120. onClicked:
  121. {
  122. if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog.
  123. {
  124. Cura.Actions.open.trigger();
  125. }
  126. else
  127. {
  128. prepareMenu.fileProviderModel.trigger(model.name);
  129. }
  130. }
  131. background: Rectangle
  132. {
  133. color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  134. radius: UM.Theme.getSize("action_button_radius").width
  135. width: popup.width
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. //If there is just a single item, show a button instead that directly chooses the one option.
  143. Button
  144. {
  145. id: openFileButton
  146. visible: prepareMenu.fileProviderModel.count <= 1
  147. height: parent.height
  148. width: visible ? height : 0 //Square button (and don't take up space if invisible).
  149. onClicked: Cura.Actions.open.trigger()
  150. enabled: visible && prepareMenu.fileProviderModel.count > 0
  151. hoverEnabled: true
  152. contentItem: Item
  153. {
  154. UM.RecolorImage
  155. {
  156. id: buttonIcon
  157. source: UM.Theme.getIcon("Folder", "medium")
  158. anchors.centerIn: parent
  159. width: UM.Theme.getSize("button_icon").width
  160. height: UM.Theme.getSize("button_icon").height
  161. color: UM.Theme.getColor("icon")
  162. sourceSize.height: height
  163. }
  164. }
  165. background: Rectangle
  166. {
  167. id: background
  168. height: parent.height
  169. width: parent.width
  170. border.color: UM.Theme.getColor("lining")
  171. border.width: UM.Theme.getSize("default_lining").width
  172. radius: UM.Theme.getSize("default_radius").width
  173. color: openFileButton.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  174. }
  175. }
  176. }
  177. }