PrepareMenu.qml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.ColorImage
  77. {
  78. id: menuIcon
  79. source: UM.Theme.getIcon("Folder", "medium")
  80. color: UM.Theme.getColor("icon")
  81. }
  82. contentItem: Item
  83. {
  84. id: popup
  85. Column
  86. {
  87. id: openProviderColumn
  88. //The column doesn't automatically listen to its children rect if the children change internally, so we need to explicitly update the size.
  89. onChildrenRectChanged:
  90. {
  91. popup.implicitHeight = childrenRect.height
  92. popup.implicitWidth = childrenRect.width
  93. }
  94. onPositioningComplete:
  95. {
  96. popup.implicitHeight = childrenRect.height
  97. popup.implicitWidth = childrenRect.width
  98. }
  99. Repeater
  100. {
  101. model: prepareMenu.fileProviderModel
  102. delegate: Button
  103. {
  104. leftPadding: UM.Theme.getSize("default_margin").width
  105. rightPadding: UM.Theme.getSize("default_margin").width
  106. width: contentItem.width + leftPadding + rightPadding
  107. height: UM.Theme.getSize("action_button").height
  108. hoverEnabled: true
  109. contentItem: UM.Label
  110. {
  111. text: model.displayText
  112. font: UM.Theme.getFont("medium")
  113. width: contentWidth
  114. height: parent.height
  115. }
  116. onClicked:
  117. {
  118. if(model.index == 0) //The 0th element is the "From Disk" option, which should activate the open local file dialog.
  119. {
  120. Cura.Actions.open.trigger();
  121. }
  122. else
  123. {
  124. prepareMenu.fileProviderModel.trigger(model.name);
  125. }
  126. }
  127. background: Rectangle
  128. {
  129. color: parent.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  130. radius: UM.Theme.getSize("action_button_radius").width
  131. width: popup.width
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. //If there is just a single item, show a button instead that directly chooses the one option.
  139. Button
  140. {
  141. id: openFileButton
  142. visible: prepareMenu.fileProviderModel.count <= 1
  143. height: parent.height
  144. width: visible ? height : 0 //Square button (and don't take up space if invisible).
  145. onClicked: Cura.Actions.open.trigger()
  146. enabled: visible && prepareMenu.fileProviderModel.count > 0
  147. hoverEnabled: true
  148. contentItem: Item
  149. {
  150. UM.ColorImage
  151. {
  152. id: buttonIcon
  153. source: UM.Theme.getIcon("Folder", "medium")
  154. anchors.centerIn: parent
  155. width: UM.Theme.getSize("button_icon").width
  156. height: UM.Theme.getSize("button_icon").height
  157. color: UM.Theme.getColor("icon")
  158. }
  159. }
  160. background: Rectangle
  161. {
  162. id: background
  163. height: parent.height
  164. width: parent.width
  165. border.color: UM.Theme.getColor("lining")
  166. border.width: UM.Theme.getSize("default_lining").width
  167. radius: UM.Theme.getSize("default_radius").width
  168. color: openFileButton.hovered ? UM.Theme.getColor("action_button_hovered") : UM.Theme.getColor("action_button")
  169. }
  170. }
  171. }
  172. }