ClusterControlItem.qml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. import QtQuick 2.3
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.3
  4. import QtGraphicalEffects 1.0
  5. import UM 1.3 as UM
  6. import Cura 1.0 as Cura
  7. Component
  8. {
  9. Rectangle
  10. {
  11. id: base
  12. property var lineColor: "#DCDCDC" // TODO: Should be linked to theme.
  13. property var cornerRadius: 4 * screenScaleFactor // TODO: Should be linked to theme.
  14. visible: OutputDevice != null
  15. anchors.fill: parent
  16. color: UM.Theme.getColor("viewport_background")
  17. UM.I18nCatalog
  18. {
  19. id: catalog
  20. name: "cura"
  21. }
  22. Label
  23. {
  24. id: activePrintersLabel
  25. font: UM.Theme.getFont("large")
  26. anchors
  27. {
  28. margins: UM.Theme.getSize("default_margin").width
  29. top: parent.top
  30. left: parent.left
  31. right: parent.right
  32. }
  33. text: catalog.i18nc("@label", "Printing")
  34. elide: Text.ElideRight
  35. }
  36. ScrollView
  37. {
  38. anchors
  39. {
  40. top: activePrintersLabel.bottom
  41. left: parent.left
  42. right: parent.right
  43. topMargin: UM.Theme.getSize("default_margin").height
  44. bottom: parent.bottom
  45. bottomMargin: UM.Theme.getSize("default_margin").height
  46. }
  47. style: UM.Theme.styles.scrollview
  48. ListView
  49. {
  50. anchors
  51. {
  52. top: parent.top
  53. bottom: parent.bottom
  54. left: parent.left
  55. right: parent.right
  56. leftMargin: 2 * UM.Theme.getSize("default_margin").width
  57. rightMargin: 2 * UM.Theme.getSize("default_margin").width
  58. }
  59. spacing: UM.Theme.getSize("default_margin").height
  60. model: OutputDevice.printers
  61. delegate: Rectangle
  62. {
  63. width: parent.width - 2 * shadowRadius
  64. height: childrenRect.height + UM.Theme.getSize("default_margin").height
  65. anchors.horizontalCenter: parent.horizontalCenter
  66. id: base
  67. property var shadowRadius: 5
  68. property var collapsed: true
  69. layer.enabled: true
  70. layer.effect: DropShadow
  71. {
  72. radius: base.shadowRadius
  73. verticalOffset: 2
  74. color: "#3F000000" // 25% shadow
  75. }
  76. Item
  77. {
  78. id: printerInfo
  79. height: machineIcon.height
  80. anchors
  81. {
  82. top: parent.top
  83. left: parent.left
  84. right: parent.right
  85. margins: UM.Theme.getSize("default_margin").width
  86. }
  87. MouseArea
  88. {
  89. anchors.fill: parent
  90. onClicked: base.collapsed = !base.collapsed
  91. }
  92. Rectangle
  93. {
  94. id: machineIcon
  95. anchors.top: parent.top
  96. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  97. anchors.left: parent.left
  98. width: 50
  99. height: 50
  100. color: modelData.activePrintJob != undefined ? UM.Theme.getColor("primary") : UM.Theme.getColor("setting_control_disabled")
  101. }
  102. Label
  103. {
  104. id: machineNameLabel
  105. text: modelData.name
  106. anchors.top: machineIcon.top
  107. anchors.left: machineIcon.right
  108. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  109. anchors.right: collapseIcon.left
  110. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  111. elide: Text.ElideRight
  112. }
  113. UM.RecolorImage
  114. {
  115. id: collapseIcon
  116. width: 15
  117. height: 15
  118. sourceSize.width: width
  119. sourceSize.height: height
  120. source: base.collapsed ? UM.Theme.getIcon("arrow_left") : UM.Theme.getIcon("arrow_bottom")
  121. anchors.verticalCenter: parent.verticalCenter
  122. anchors.right: parent.right
  123. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  124. color: "black"
  125. }
  126. Label
  127. {
  128. id: activeJobLabel
  129. text: modelData.activePrintJob != null ? modelData.activePrintJob.name : "waiting"
  130. anchors.top: machineNameLabel.bottom
  131. anchors.left: machineNameLabel.left
  132. anchors.right: collapseIcon.left
  133. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  134. elide: Text.ElideRight
  135. }
  136. }
  137. Item
  138. {
  139. id: detailedInfo
  140. property var printJob: modelData.activePrintJob
  141. visible: height == childrenRect.height
  142. anchors.top: printerInfo.bottom
  143. width: parent.width
  144. height: !base.collapsed ? childrenRect.height : 0
  145. opacity: visible ? 1 : 0
  146. Behavior on height { NumberAnimation { duration: 100 } }
  147. Behavior on opacity { NumberAnimation { duration: 100 } }
  148. Rectangle
  149. {
  150. id: topSpacer
  151. color: UM.Theme.getColor("viewport_background")
  152. height: 1
  153. anchors
  154. {
  155. left: parent.left
  156. right: parent.right
  157. margins: UM.Theme.getSize("default_margin").width
  158. top: parent.top
  159. topMargin: UM.Theme.getSize("default_margin").width
  160. }
  161. }
  162. Row
  163. {
  164. id: extrudersInfo
  165. anchors.top: topSpacer.bottom
  166. anchors.topMargin: 2 * UM.Theme.getSize("default_margin").height
  167. anchors.left: parent.left
  168. anchors.leftMargin: 2 * UM.Theme.getSize("default_margin").width
  169. anchors.right: parent.right
  170. anchors.rightMargin: 2 * UM.Theme.getSize("default_margin").width
  171. height: childrenRect.height
  172. spacing: UM.Theme.getSize("default_margin").width
  173. PrintCoreConfiguration
  174. {
  175. id: leftExtruderInfo
  176. width: Math.round(parent.width / 2)
  177. printCoreConfiguration: modelData.printerConfiguration.extruderConfigurations[0]
  178. }
  179. PrintCoreConfiguration
  180. {
  181. id: rightExtruderInfo
  182. width: Math.round(parent.width / 2)
  183. printCoreConfiguration: modelData.printerConfiguration.extruderConfigurations[1]
  184. }
  185. }
  186. Rectangle
  187. {
  188. id: jobSpacer
  189. color: UM.Theme.getColor("viewport_background")
  190. height: 1
  191. anchors
  192. {
  193. left: parent.left
  194. right: parent.right
  195. margins: UM.Theme.getSize("default_margin").width
  196. top: extrudersInfo.bottom
  197. topMargin: 2 * UM.Theme.getSize("default_margin").height
  198. }
  199. }
  200. Item
  201. {
  202. id: jobInfo
  203. property var showJobInfo: modelData.activePrintJob != null && modelData.activePrintJob.state != "queued"
  204. anchors.top: jobSpacer.bottom
  205. anchors.topMargin: 2 * UM.Theme.getSize("default_margin").height
  206. anchors.left: parent.left
  207. anchors.right: parent.right
  208. anchors.margins: UM.Theme.getSize("default_margin").width
  209. anchors.leftMargin: 2 * UM.Theme.getSize("default_margin").width
  210. height: showJobInfo ? childrenRect.height + 2 * UM.Theme.getSize("default_margin").height: 0
  211. visible: showJobInfo
  212. Label
  213. {
  214. id: printJobName
  215. text: modelData.activePrintJob != null ? modelData.activePrintJob.name : ""
  216. font: UM.Theme.getFont("default_bold")
  217. }
  218. Label
  219. {
  220. id: ownerName
  221. anchors.top: printJobName.bottom
  222. text: modelData.activePrintJob != null ? modelData.activePrintJob.owner : ""
  223. }
  224. Image
  225. {
  226. id: printJobPreview
  227. source: modelData.activePrintJob != null ? modelData.activePrintJob.preview_image_url : ""
  228. anchors.top: ownerName.bottom
  229. anchors.horizontalCenter: parent.horizontalCenter
  230. width: parent.width / 3
  231. height: width
  232. }
  233. Rectangle
  234. {
  235. id: showCameraIcon
  236. width: 35 * screenScaleFactor
  237. height: width
  238. radius: 0.5 * width
  239. anchors.left: parent.left
  240. anchors.top: printJobPreview.bottom
  241. color: UM.Theme.getColor("setting_control_border_highlight")
  242. Image
  243. {
  244. width: parent.width
  245. height: width
  246. anchors.right: parent.right
  247. anchors.rightMargin: parent.rightMargin
  248. source: "camera-icon.svg"
  249. }
  250. MouseArea
  251. {
  252. anchors.fill:parent
  253. onClicked:
  254. {
  255. OutputDevice.setActiveCamera(modelData.camera)
  256. }
  257. }
  258. }
  259. }
  260. }
  261. ProgressBar
  262. {
  263. property var progress:
  264. {
  265. if(modelData.activePrintJob == null)
  266. {
  267. return 0
  268. }
  269. var result = modelData.activePrintJob.timeElapsed / modelData.activePrintJob.timeTotal
  270. if(result > 1.0)
  271. {
  272. result = 1.0
  273. }
  274. return result
  275. }
  276. id: jobProgressBar
  277. width: parent.width
  278. value: progress
  279. anchors.top: detailedInfo.bottom
  280. anchors.topMargin: UM.Theme.getSize("default_margin").height
  281. visible: modelData.activePrintJob != null && modelData.activePrintJob != undefined
  282. style: ProgressBarStyle
  283. {
  284. property var progressText:
  285. {
  286. if(modelData.activePrintJob == null)
  287. {
  288. return ""
  289. }
  290. switch(modelData.activePrintJob.state)
  291. {
  292. case "wait_cleanup":
  293. return catalog.i18nc("@label:status", "Finshed")
  294. case "pre_print":
  295. case "sent_to_printer":
  296. return catalog.i18nc("@label:status", "Preparing")
  297. case "aborted":
  298. case "wait_user_action":
  299. return catalog.i18nc("@label:status", "Aborted")
  300. case "pausing":
  301. case "paused":
  302. return catalog.i18nc("@label:status", "Paused")
  303. case "resuming":
  304. return catalog.i18nc("@label:status", "Resuming")
  305. default:
  306. OutputDevice.formatDuration(modelData.activePrintJob.timeTotal - modelData.activePrintJob.timeElapsed)
  307. }
  308. }
  309. background: Rectangle
  310. {
  311. implicitWidth: 100
  312. implicitHeight: visible ? 24 : 0
  313. color: UM.Theme.getColor("viewport_background")
  314. }
  315. progress: Rectangle
  316. {
  317. color: UM.Theme.getColor("primary")
  318. id: progressItem
  319. function getTextOffset()
  320. {
  321. if(progressItem.width + progressLabel.width < control.width)
  322. {
  323. return progressItem.width + UM.Theme.getSize("default_margin").width
  324. }
  325. else
  326. {
  327. return progressItem.width - progressLabel.width - UM.Theme.getSize("default_margin").width
  328. }
  329. }
  330. Label
  331. {
  332. id: progressLabel
  333. anchors.left: parent.left
  334. anchors.leftMargin: getTextOffset()
  335. text: progressText
  336. anchors.verticalCenter: parent.verticalCenter
  337. color: progressItem.width + progressLabel.width < control.width ? "black" : "white"
  338. width: contentWidth
  339. }
  340. }
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }