PrintSetupSelectorContents.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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: popup
  12. width: UM.Theme.getSize("print_setup_widget").width - 2 * UM.Theme.getSize("default_margin").width
  13. height: childrenRect.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. // Header of the popup
  31. Cura.RoundedRectangle
  32. {
  33. id: header
  34. height: UM.Theme.getSize("print_setup_widget_header").height
  35. color: UM.Theme.getColor("secondary")
  36. cornerSide: Cura.RoundedRectangle.Direction.Up
  37. radius: UM.Theme.getSize("default_radius").width
  38. anchors
  39. {
  40. top: parent.top
  41. right: parent.right
  42. left: parent.left
  43. }
  44. Label
  45. {
  46. id: headerLabel
  47. text: catalog.i18nc("@label", "Print settings")
  48. font: UM.Theme.getFont("default")
  49. renderType: Text.NativeRendering
  50. verticalAlignment: Text.AlignVCenter
  51. color: UM.Theme.getColor("text")
  52. height: parent.height
  53. anchors
  54. {
  55. topMargin: UM.Theme.getSize("default_margin").height
  56. left: parent.left
  57. leftMargin: UM.Theme.getSize("default_margin").height
  58. }
  59. }
  60. Button
  61. {
  62. id: closeButton
  63. width: UM.Theme.getSize("message_close").width
  64. height: UM.Theme.getSize("message_close").height
  65. hoverEnabled: true
  66. anchors
  67. {
  68. right: parent.right
  69. rightMargin: UM.Theme.getSize("default_margin").width
  70. verticalCenter: parent.verticalCenter
  71. }
  72. contentItem: UM.RecolorImage
  73. {
  74. anchors.fill: parent
  75. sourceSize.width: width
  76. color: closeButton.hovered ? UM.Theme.getColor("small_button_text_hover") : UM.Theme.getColor("small_button_text")
  77. source: UM.Theme.getIcon("cross1")
  78. }
  79. background: Item {}
  80. onClicked: toggleContent() // Will hide the popup item
  81. }
  82. }
  83. Rectangle
  84. {
  85. id: topSeparator
  86. anchors.bottom: header.bottom
  87. width: parent.width
  88. height: UM.Theme.getSize("default_lining").height
  89. color: UM.Theme.getColor("lining")
  90. }
  91. Item
  92. {
  93. id: contents
  94. // Use the visible property instead of checking the currentModeIndex. That creates a binding that
  95. // evaluates the new height every time the visible property changes.
  96. height: recommendedPrintSetup.visible ? recommendedPrintSetup.height : customPrintSetup.height
  97. anchors
  98. {
  99. top: header.bottom
  100. left: parent.left
  101. right: parent.right
  102. }
  103. RecommendedPrintSetup
  104. {
  105. id: recommendedPrintSetup
  106. anchors
  107. {
  108. left: parent.left
  109. right: parent.right
  110. top: parent.top
  111. }
  112. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
  113. }
  114. CustomPrintSetup
  115. {
  116. id: customPrintSetup
  117. anchors
  118. {
  119. left: parent.left
  120. right: parent.right
  121. top: parent.top
  122. }
  123. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  124. }
  125. }
  126. Rectangle
  127. {
  128. id: buttonsSeparator
  129. // The buttonsSeparator is inside the contents. This is to avoid a double line in the bottom
  130. anchors.bottom: contents.bottom
  131. width: parent.width
  132. height: UM.Theme.getSize("default_lining").height
  133. color: UM.Theme.getColor("lining")
  134. }
  135. Item
  136. {
  137. id: buttonRow
  138. property real padding: UM.Theme.getSize("default_margin").width
  139. height: childrenRect.height + 2 * padding
  140. anchors
  141. {
  142. top: buttonsSeparator.bottom
  143. left: parent.left
  144. right: parent.right
  145. }
  146. Cura.SecondaryButton
  147. {
  148. anchors.top: parent.top
  149. anchors.left: parent.left
  150. anchors.margins: parent.padding
  151. leftPadding: UM.Theme.getSize("default_margin").width
  152. rightPadding: UM.Theme.getSize("default_margin").width
  153. text: catalog.i18nc("@button", "Recommended")
  154. iconSource: UM.Theme.getIcon("arrow_left")
  155. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Custom
  156. onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Recommended
  157. }
  158. Cura.SecondaryButton
  159. {
  160. anchors.top: parent.top
  161. anchors.right: parent.right
  162. anchors.margins: UM.Theme.getSize("default_margin").width
  163. leftPadding: UM.Theme.getSize("default_margin").width
  164. rightPadding: UM.Theme.getSize("default_margin").width
  165. text: catalog.i18nc("@button", "Custom")
  166. iconSource: UM.Theme.getIcon("arrow_right")
  167. isIconOnRightSide: true
  168. visible: currentModeIndex == PrintSetupSelectorContents.Mode.Recommended
  169. onClicked: currentModeIndex = PrintSetupSelectorContents.Mode.Custom
  170. }
  171. }
  172. }