PrintSetupSelectorContents.qml 7.1 KB

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