PrintSetupSelectorContents.qml 8.0 KB

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