PrintSetupSelectorContents.qml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.3
  5. import UM 1.3 as UM
  6. import Cura 1.0 as Cura
  7. import "Recommended"
  8. import "Custom"
  9. Item
  10. {
  11. id: content
  12. property int absoluteMinimumHeight: 200 * screenScaleFactor
  13. implicitWidth: UM.Theme.getSize("print_setup_widget").width
  14. implicitHeight: contents.height + buttonRow.height
  15. enum Mode
  16. {
  17. Recommended = 0,
  18. Custom = 1
  19. }
  20. // Catch all mouse events
  21. MouseArea
  22. {
  23. anchors.fill: parent
  24. hoverEnabled: true
  25. }
  26. // Set the current mode index to the value that is stored in the preferences or Recommended mode otherwise.
  27. property int currentModeIndex:
  28. {
  29. var index = Math.round(UM.Preferences.getValue("cura/active_mode"))
  30. if (index != null && !isNaN(index))
  31. {
  32. return index
  33. }
  34. return PrintSetupSelectorContents.Mode.Recommended
  35. }
  36. onCurrentModeIndexChanged: UM.Preferences.setValue("cura/active_mode", currentModeIndex)
  37. Item
  38. {
  39. id: contents
  40. // Use the visible property instead of checking the currentModeIndex. That creates a binding that
  41. // evaluates the new height every time the visible property changes.
  42. height: recommendedPrintSetup.visible ? recommendedPrintSetup.height : customPrintSetup.height
  43. anchors
  44. {
  45. top: parent.top
  46. left: parent.left
  47. right: parent.right
  48. }
  49. RecommendedPrintSetup
  50. {
  51. id: recommendedPrintSetup
  52. anchors
  53. {
  54. left: parent.left
  55. right: parent.right
  56. top: parent.top
  57. }
  58. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
  59. height: {
  60. const height = base.height - (customPrintSetup.mapToItem(null, 0, 0).y + buttonRow.height + UM.Theme.getSize("default_margin").height);
  61. const maxHeight = UM.Preferences.getValue("view/settings_list_height");
  62. return Math.min(implicitHeight, height, maxHeight);
  63. }
  64. function onModeChanged()
  65. {
  66. currentModeIndex = PrintSetupSelectorContents.Mode.Custom;
  67. }
  68. }
  69. CustomPrintSetup
  70. {
  71. id: customPrintSetup
  72. anchors
  73. {
  74. left: parent.left
  75. right: parent.right
  76. top: parent.top
  77. }
  78. height: UM.Preferences.getValue("view/settings_list_height") - UM.Theme.getSize("default_margin").height
  79. Connections
  80. {
  81. target: UM.Preferences
  82. function onPreferenceChanged(preference)
  83. {
  84. if (preference !== "view/settings_list_height" && preference !== "general/window_height" && preference !== "general/window_state")
  85. {
  86. return;
  87. }
  88. customPrintSetup.height =
  89. Math.min
  90. (
  91. UM.Preferences.getValue("view/settings_list_height"),
  92. Math.max
  93. (
  94. absoluteMinimumHeight,
  95. base.height - (customPrintSetup.mapToItem(null, 0, 0).y + buttonRow.height + UM.Theme.getSize("default_margin").height)
  96. )
  97. );
  98. updateDragPosition();
  99. }
  100. }
  101. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  102. }
  103. }
  104. Rectangle
  105. {
  106. id: buttonsSeparator
  107. // The buttonsSeparator is inside the contents. This is to avoid a double line in the bottom
  108. anchors.bottom: contents.bottom
  109. width: parent.width
  110. height: UM.Theme.getSize("default_lining").height
  111. color: UM.Theme.getColor("lining")
  112. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  113. }
  114. Item
  115. {
  116. id: buttonRow
  117. property real padding: UM.Theme.getSize("default_margin").width
  118. height:
  119. {
  120. if (currentModeIndex == PrintSetupSelectorContents.Mode.Custom)
  121. {
  122. return recommendedButton.height + 2 * padding + (draggableArea.visible ? draggableArea.height : 0)
  123. }
  124. return 0
  125. }
  126. anchors
  127. {
  128. bottom: parent.bottom
  129. left: parent.left
  130. right: parent.right
  131. }
  132. Cura.SecondaryButton
  133. {
  134. id: recommendedButton
  135. anchors.top: parent.top
  136. anchors.left: parent.left
  137. anchors.margins: parent.padding
  138. leftPadding: UM.Theme.getSize("default_margin").width
  139. rightPadding: UM.Theme.getSize("default_margin").width
  140. text: catalog.i18nc("@button", "Recommended")
  141. iconSource: UM.Theme.getIcon("ChevronSingleLeft")
  142. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  143. onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
  144. }
  145. //Invisible area at the bottom with which you can resize the panel.
  146. MouseArea
  147. {
  148. id: draggableArea
  149. anchors
  150. {
  151. left: parent.left
  152. right: parent.right
  153. bottom: parent.bottom
  154. }
  155. height: childrenRect.height
  156. cursorShape: Qt.SplitVCursor
  157. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  158. drag
  159. {
  160. target: parent
  161. axis: Drag.YAxis
  162. }
  163. onMouseYChanged:
  164. {
  165. if(drag.active)
  166. {
  167. // position of mouse relative to dropdown align vertical centre of mouse area to cursor
  168. // v------------------------------v v------------v
  169. var h = mouseY + buttonRow.y + content.y - height / 2 | 0;
  170. if(h < absoluteMinimumHeight) //Enforce a minimum size.
  171. {
  172. h = absoluteMinimumHeight;
  173. }
  174. //Absolute mouse Y position in the window, to prevent it from going outside the window.
  175. var mouse_absolute_y = mapToGlobal(mouseX, mouseY).y - UM.Preferences.getValue("general/window_top");
  176. if(mouse_absolute_y > base.height)
  177. {
  178. h -= mouse_absolute_y - base.height;
  179. }
  180. // Enforce a minimum size (again).
  181. // This is a bit of a hackish way to do it, but we've seen some occasional reports that the size
  182. // could get below the the minimum height.
  183. if(h < absoluteMinimumHeight)
  184. {
  185. h = absoluteMinimumHeight;
  186. }
  187. UM.Preferences.setValue("view/settings_list_height", h);
  188. }
  189. }
  190. Rectangle
  191. {
  192. width: parent.width
  193. height: UM.Theme.getSize("narrow_margin").height
  194. color: UM.Theme.getColor("secondary")
  195. Rectangle
  196. {
  197. anchors.bottom: parent.top
  198. width: parent.width
  199. height: UM.Theme.getSize("default_lining").height
  200. color: UM.Theme.getColor("lining")
  201. }
  202. UM.ColorImage
  203. {
  204. width: UM.Theme.getSize("drag_icon").width
  205. height: UM.Theme.getSize("drag_icon").height
  206. anchors.centerIn: parent
  207. source: UM.Theme.getIcon("ThreeDots")
  208. color: UM.Theme.getColor("small_button_text")
  209. }
  210. }
  211. }
  212. }
  213. }