MonitorCarousel.qml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. // Copyright (c) 2019 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.3
  4. import QtQuick.Controls 2.0
  5. import UM 1.3 as UM
  6. Item
  7. {
  8. id: base
  9. property var currentIndex: 0
  10. property var tileWidth: 834 * screenScaleFactor // TODO: Theme!
  11. property var tileHeight: 216 * screenScaleFactor // TODO: Theme!
  12. property var tileSpacing: 60 * screenScaleFactor // TODO: Theme!
  13. // Array/model of printers to populate the carousel with
  14. property var printers: []
  15. // Maximum distance the carousel can be shifted
  16. property var maxOffset: (printers.length - 1) * (tileWidth + tileSpacing)
  17. height: centerSection.height
  18. width: maximumWidth
  19. // Enable keyboard navigation
  20. Keys.onLeftPressed: navigateTo(currentIndex - 1)
  21. Keys.onRightPressed: navigateTo(currentIndex + 1)
  22. Item
  23. {
  24. id: leftHint
  25. anchors
  26. {
  27. right: leftButton.left
  28. rightMargin: 12 * screenScaleFactor // TODO: Theme!
  29. left: parent.left
  30. }
  31. height: parent.height
  32. z: 10
  33. Rectangle
  34. {
  35. anchors.fill: parent
  36. color: UM.Theme.getColor("monitor_stage_background")
  37. }
  38. MouseArea
  39. {
  40. anchors.fill: parent
  41. onClicked: navigateTo(currentIndex - 1)
  42. }
  43. }
  44. Button
  45. {
  46. id: leftButton
  47. anchors
  48. {
  49. verticalCenter: parent.verticalCenter
  50. right: centerSection.left
  51. rightMargin: 12 * screenScaleFactor // TODO: Theme!
  52. }
  53. width: 36 * screenScaleFactor // TODO: Theme!
  54. height: 72 * screenScaleFactor // TODO: Theme!
  55. visible: currentIndex > 0
  56. hoverEnabled: true
  57. z: 10
  58. onClicked: navigateTo(currentIndex - 1)
  59. background: Rectangle
  60. {
  61. color: leftButton.hovered ? UM.Theme.getColor("monitor_card_hover") : UM.Theme.getColor("monitor_card_background")
  62. border.width: 1 * screenScaleFactor // TODO: Theme!
  63. border.color: UM.Theme.getColor("monitor_card_border")
  64. radius: 2 * screenScaleFactor // TODO: Theme!
  65. }
  66. contentItem: Item
  67. {
  68. anchors.fill: parent
  69. UM.ColorImage
  70. {
  71. anchors.centerIn: parent
  72. width: 18 // TODO: Theme!
  73. height: width // TODO: Theme!
  74. color: UM.Theme.getColor("text")
  75. source: UM.Theme.getIcon("ChevronSingleLeft")
  76. }
  77. }
  78. }
  79. Item
  80. {
  81. id: centerSection
  82. anchors
  83. {
  84. verticalCenter: parent.verticalCenter
  85. horizontalCenter: parent.horizontalCenter
  86. }
  87. width: tileWidth
  88. height: tiles.height
  89. z: 1
  90. Row
  91. {
  92. id: tiles
  93. height: childrenRect.height
  94. width: 5 * tileWidth + 4 * tileSpacing // TODO: Theme!
  95. x: 0
  96. z: 0
  97. Behavior on x
  98. {
  99. NumberAnimation
  100. {
  101. duration: 200
  102. easing.type: Easing.InOutCubic
  103. }
  104. }
  105. spacing: 60 * screenScaleFactor // TODO: Theme!
  106. Repeater
  107. {
  108. model: printers
  109. MonitorPrinterCard
  110. {
  111. printer: modelData
  112. enabled: model.index == currentIndex
  113. }
  114. }
  115. }
  116. }
  117. Button
  118. {
  119. id: rightButton
  120. anchors
  121. {
  122. verticalCenter: parent.verticalCenter
  123. left: centerSection.right
  124. leftMargin: 12 * screenScaleFactor // TODO: Theme!
  125. }
  126. width: 36 * screenScaleFactor // TODO: Theme!
  127. height: 72 * screenScaleFactor // TODO: Theme!
  128. z: 10
  129. visible: currentIndex < printers.length - 1
  130. onClicked: navigateTo(currentIndex + 1)
  131. hoverEnabled: true
  132. background: Rectangle
  133. {
  134. color: rightButton.hovered ? UM.Theme.getColor("monitor_card_hover") : UM.Theme.getColor("monitor_card_background")
  135. border.width: 1 * screenScaleFactor // TODO: Theme!
  136. border.color: UM.Theme.getColor("monitor_card_border")
  137. radius: 2 * screenScaleFactor // TODO: Theme!
  138. }
  139. contentItem: Item
  140. {
  141. anchors.fill: parent
  142. UM.ColorImage
  143. {
  144. anchors.centerIn: parent
  145. width: 18 // TODO: Theme!
  146. height: width // TODO: Theme!
  147. color: UM.Theme.getColor("text")
  148. source: UM.Theme.getIcon("ChevronSingleRight")
  149. }
  150. }
  151. }
  152. Item
  153. {
  154. id: rightHint
  155. anchors
  156. {
  157. left: rightButton.right
  158. leftMargin: 12 * screenScaleFactor // TODO: Theme!
  159. right: parent.right
  160. }
  161. height: centerSection.height
  162. z: 10
  163. Rectangle
  164. {
  165. anchors.fill: parent
  166. color: UM.Theme.getColor("monitor_stage_background_fade")
  167. }
  168. MouseArea
  169. {
  170. anchors.fill: parent
  171. onClicked: navigateTo(currentIndex + 1)
  172. }
  173. }
  174. Row
  175. {
  176. id: navigationDots
  177. anchors
  178. {
  179. horizontalCenter: centerSection.horizontalCenter
  180. top: centerSection.bottom
  181. topMargin: 36 * screenScaleFactor // TODO: Theme!
  182. }
  183. spacing: 8 * screenScaleFactor // TODO: Theme!
  184. visible: printers.length > 1
  185. Repeater
  186. {
  187. model: printers
  188. Button
  189. {
  190. background: Rectangle
  191. {
  192. color: model.index == currentIndex ? UM.Theme.getColor("monitor_carousel_dot_current") : UM.Theme.getColor("monitor_carousel_dot")
  193. radius: Math.floor(width / 2)
  194. width: 12 * screenScaleFactor // TODO: Theme!
  195. height: width // TODO: Theme!
  196. }
  197. onClicked: navigateTo(model.index)
  198. }
  199. }
  200. }
  201. function navigateTo( i ) {
  202. if (i >= 0 && i < printers.length)
  203. {
  204. tiles.x = -1 * i * (tileWidth + tileSpacing)
  205. currentIndex = i
  206. }
  207. }
  208. }