PrepareMenu.qml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.5 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: UM.Label
  111. {
  112. text: model.displayText
  113. font: UM.Theme.getFont("medium")
  114. width: contentWidth
  115. height: parent.height
  116. }
  117. onClicked:
  118. {
  119. if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog.
  120. {
  121. Cura.Actions.open.trigger();
  122. }
  123. else
  124. {
  125. prepareMenu.fileProviderModel.trigger(model.name);
  126. }
  127. }
  128. background: Rectangle
  129. {
  130. color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  131. radius: UM.Theme.getSize("action_button_radius").width
  132. width: popup.width
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. //If there is just a single item, show a button instead that directly chooses the one option.
  140. Button
  141. {
  142. id: openFileButton
  143. visible: prepareMenu.fileProviderModel.count <= 1
  144. height: parent.height
  145. width: visible ? height : 0 //Square button (and don't take up space if invisible).
  146. onClicked: Cura.Actions.open.trigger()
  147. enabled: visible && prepareMenu.fileProviderModel.count > 0
  148. hoverEnabled: true
  149. contentItem: Item
  150. {
  151. UM.RecolorImage
  152. {
  153. id: buttonIcon
  154. source: UM.Theme.getIcon("Folder", "medium")
  155. anchors.centerIn: parent
  156. width: UM.Theme.getSize("button_icon").width
  157. height: UM.Theme.getSize("button_icon").height
  158. color: UM.Theme.getColor("icon")
  159. sourceSize.height: height
  160. }
  161. }
  162. background: Rectangle
  163. {
  164. id: background
  165. height: parent.height
  166. width: parent.width
  167. border.color: UM.Theme.getColor("lining")
  168. border.width: UM.Theme.getSize("default_lining").width
  169. radius: UM.Theme.getSize("default_radius").width
  170. color: openFileButton.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  171. }
  172. }
  173. }
  174. }