MonitorCarousel.qml 7.3 KB

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