PrintSetupSelectorContents.qml 7.6 KB

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