PrintSetupSelectorContents.qml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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 - (recommendedPrintSetup.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(height, maxHeight);
  63. }
  64. Connections
  65. {
  66. target: UM.Preferences
  67. function onPreferenceChanged(preference)
  68. {
  69. if (preference !== "view/settings_list_height" && preference !== "general/window_height" && preference !== "general/window_state")
  70. {
  71. return;
  72. }
  73. const height = base.height - (recommendedPrintSetup.mapToItem(null, 0, 0).y + buttonRow.height + UM.Theme.getSize("default_margin").height);
  74. const maxHeight = UM.Preferences.getValue("view/settings_list_height");
  75. recommendedPrintSetup.height = Math.min(maxHeight, height);
  76. updateDragPosition();
  77. }
  78. }
  79. function onModeChanged()
  80. {
  81. currentModeIndex = PrintSetupSelectorContents.Mode.Custom;
  82. }
  83. }
  84. CustomPrintSetup
  85. {
  86. id: customPrintSetup
  87. anchors
  88. {
  89. left: parent.left
  90. right: parent.right
  91. top: parent.top
  92. }
  93. height: UM.Preferences.getValue("view/settings_list_height") - UM.Theme.getSize("default_margin").height
  94. Connections
  95. {
  96. target: UM.Preferences
  97. function onPreferenceChanged(preference)
  98. {
  99. if (preference !== "view/settings_list_height" && preference !== "general/window_height" && preference !== "general/window_state")
  100. {
  101. return;
  102. }
  103. customPrintSetup.height =
  104. Math.min
  105. (
  106. UM.Preferences.getValue("view/settings_list_height"),
  107. Math.max
  108. (
  109. absoluteMinimumHeight,
  110. base.height - (customPrintSetup.mapToItem(null, 0, 0).y + buttonRow.height + UM.Theme.getSize("default_margin").height)
  111. )
  112. );
  113. updateDragPosition();
  114. }
  115. }
  116. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  117. }
  118. }
  119. Rectangle
  120. {
  121. id: buttonsSeparator
  122. // The buttonsSeparator is inside the contents. This is to avoid a double line in the bottom
  123. anchors.bottom: contents.bottom
  124. width: parent.width
  125. height: UM.Theme.getSize("default_lining").height
  126. color: UM.Theme.getColor("lining")
  127. }
  128. Item
  129. {
  130. id: buttonRow
  131. property real padding: UM.Theme.getSize("default_margin").width
  132. height:
  133. {
  134. const draggable_area_height = draggableArea.visible ? draggableArea.height : 0;
  135. if (currentModeIndex == PrintSetupSelectorContents.Mode.Custom)
  136. {
  137. return recommendedButton.height + 2 * padding + draggable_area_height;
  138. }
  139. return draggable_area_height;
  140. }
  141. anchors
  142. {
  143. bottom: parent.bottom
  144. left: parent.left
  145. right: parent.right
  146. }
  147. Cura.SecondaryButton
  148. {
  149. id: recommendedButton
  150. anchors.top: parent.top
  151. anchors.left: parent.left
  152. anchors.margins: parent.padding
  153. leftPadding: UM.Theme.getSize("default_margin").width
  154. rightPadding: UM.Theme.getSize("default_margin").width
  155. text: catalog.i18nc("@button", "Recommended")
  156. iconSource: UM.Theme.getIcon("ChevronSingleLeft")
  157. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  158. onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
  159. }
  160. //Invisible area at the bottom with which you can resize the panel.
  161. MouseArea
  162. {
  163. id: draggableArea
  164. anchors
  165. {
  166. left: parent.left
  167. right: parent.right
  168. bottom: parent.bottom
  169. }
  170. height: childrenRect.height
  171. cursorShape: Qt.SplitVCursor
  172. drag
  173. {
  174. target: parent
  175. axis: Drag.YAxis
  176. }
  177. onMouseYChanged:
  178. {
  179. if(drag.active)
  180. {
  181. // position of mouse relative to dropdown align vertical centre of mouse area to cursor
  182. // v------------------------------v v------------v
  183. var h = mouseY + buttonRow.y + content.y - height / 2 | 0;
  184. if(h < absoluteMinimumHeight) //Enforce a minimum size.
  185. {
  186. h = absoluteMinimumHeight;
  187. }
  188. //Absolute mouse Y position in the window, to prevent it from going outside the window.
  189. var mouse_absolute_y = mapToGlobal(mouseX, mouseY).y - UM.Preferences.getValue("general/window_top");
  190. if(mouse_absolute_y > base.height)
  191. {
  192. h -= mouse_absolute_y - base.height;
  193. }
  194. // Enforce a minimum size (again).
  195. // This is a bit of a hackish way to do it, but we've seen some occasional reports that the size
  196. // could get below the the minimum height.
  197. if(h < absoluteMinimumHeight)
  198. {
  199. h = absoluteMinimumHeight;
  200. }
  201. UM.Preferences.setValue("view/settings_list_height", h);
  202. }
  203. }
  204. Rectangle
  205. {
  206. width: parent.width
  207. height: UM.Theme.getSize("narrow_margin").height
  208. color: UM.Theme.getColor("secondary")
  209. Rectangle
  210. {
  211. anchors.bottom: parent.top
  212. width: parent.width
  213. height: UM.Theme.getSize("default_lining").height
  214. color: UM.Theme.getColor("lining")
  215. }
  216. UM.ColorImage
  217. {
  218. width: UM.Theme.getSize("drag_icon").width
  219. height: UM.Theme.getSize("drag_icon").height
  220. anchors.centerIn: parent
  221. source: UM.Theme.getIcon("ThreeDots")
  222. color: UM.Theme.getColor("small_button_text")
  223. }
  224. }
  225. }
  226. }
  227. }