PrintSetupSelectorContents.qml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. onPreferenceChanged:
  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("arrow_left")
  125. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  126. onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
  127. }
  128. Cura.SecondaryButton
  129. {
  130. anchors.top: parent.top
  131. anchors.right: parent.right
  132. anchors.margins: UM.Theme.getSize("default_margin").width
  133. leftPadding: UM.Theme.getSize("default_margin").width
  134. rightPadding: UM.Theme.getSize("default_margin").width
  135. text: catalog.i18nc("@button", "Custom")
  136. iconSource: UM.Theme.getIcon("arrow_right")
  137. isIconOnRightSide: true
  138. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
  139. onClicked:
  140. {
  141. currentModeIndex = PrintSetupSelectorContents.Mode.Custom
  142. updateDragPosition();
  143. }
  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. UM.Preferences.setValue("view/settings_list_height", h);
  181. }
  182. }
  183. Rectangle
  184. {
  185. width: parent.width
  186. height: UM.Theme.getSize("narrow_margin").height
  187. color: UM.Theme.getColor("secondary")
  188. Rectangle
  189. {
  190. anchors.bottom: parent.top
  191. width: parent.width
  192. height: UM.Theme.getSize("default_lining").height
  193. color: UM.Theme.getColor("lining")
  194. }
  195. UM.RecolorImage
  196. {
  197. width: UM.Theme.getSize("drag_icon").width
  198. height: UM.Theme.getSize("drag_icon").height
  199. anchors.centerIn: parent
  200. source: UM.Theme.getIcon("resize")
  201. color: UM.Theme.getColor("small_button_text")
  202. }
  203. }
  204. }
  205. }
  206. }