PrintJobInformation.qml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.1
  5. import UM 1.1 as UM
  6. import Cura 1.0 as Cura
  7. Column
  8. {
  9. id: base
  10. spacing: UM.Theme.getSize("default_margin").width
  11. UM.I18nCatalog
  12. {
  13. id: catalog
  14. name: "cura"
  15. }
  16. Column
  17. {
  18. id: timeSpecification
  19. spacing: UM.Theme.getSize("thin_margin").width
  20. width: parent.width
  21. topPadding: UM.Theme.getSize("default_margin").height
  22. leftPadding: UM.Theme.getSize("default_margin").width
  23. rightPadding: UM.Theme.getSize("default_margin").width
  24. Label
  25. {
  26. text: catalog.i18nc("@label", "Time specification").toUpperCase()
  27. color: UM.Theme.getColor("primary")
  28. font: UM.Theme.getFont("small")
  29. renderType: Text.NativeRendering
  30. }
  31. Label
  32. {
  33. property var printDuration: PrintInformation.currentPrintTime
  34. function getTimeSpecifications()
  35. {
  36. // All the time information for the different features is achieved
  37. var printTime = PrintInformation.getFeaturePrintTimes()
  38. var totalSeconds = parseInt(printDuration.getDisplayString(UM.DurationFormat.Seconds))
  39. // A message is created and displayed when the user hover the time label
  40. var text = "<table width=\"100%\">"
  41. for(var feature in printTime)
  42. {
  43. if(!printTime[feature].isTotalDurationZero)
  44. {
  45. text += "<tr><td>" + feature + ":</td>" +
  46. "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(printTime[feature].getDisplayString(UM.DurationFormat.ISO8601).slice(0,-3)) +
  47. "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1%</td>".arg(Math.round(100 * parseInt(printTime[feature].getDisplayString(UM.DurationFormat.Seconds)) / totalSeconds)) +
  48. "</tr>"
  49. }
  50. }
  51. text += "</table>"
  52. return text
  53. }
  54. text: getTimeSpecifications()
  55. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  56. color: UM.Theme.getColor("text")
  57. font: UM.Theme.getFont("very_small")
  58. renderType: Text.NativeRendering
  59. textFormat: Text.RichText
  60. }
  61. }
  62. Column
  63. {
  64. id: materialSpecification
  65. spacing: UM.Theme.getSize("thin_margin").width
  66. width: parent.width
  67. bottomPadding: UM.Theme.getSize("default_margin").height
  68. leftPadding: UM.Theme.getSize("default_margin").width
  69. rightPadding: UM.Theme.getSize("default_margin").width
  70. Label
  71. {
  72. text: catalog.i18nc("@label", "Material specification").toUpperCase()
  73. color: UM.Theme.getColor("primary")
  74. font: UM.Theme.getFont("small")
  75. renderType: Text.NativeRendering
  76. }
  77. Label
  78. {
  79. property var printMaterialLengths: PrintInformation.materialLengths
  80. property var printMaterialWeights: PrintInformation.materialWeights
  81. property var printMaterialCosts: PrintInformation.materialCosts
  82. property var printMaterialNames: PrintInformation.materialNames
  83. function formatRow(items)
  84. {
  85. var rowHTML = "<tr>"
  86. for(var item = 0; item < items.length; item++)
  87. {
  88. if (item == 0)
  89. {
  90. rowHTML += "<td valign=\"bottom\">%1</td>".arg(items[item])
  91. }
  92. else
  93. {
  94. rowHTML += "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(items[item])
  95. }
  96. }
  97. rowHTML += "</tr>"
  98. return rowHTML
  99. }
  100. function getMaterialSpecifications()
  101. {
  102. var lengths = []
  103. var weights = []
  104. var costs = []
  105. var names = []
  106. if(printMaterialLengths)
  107. {
  108. for(var index = 0; index < printMaterialLengths.length; index++)
  109. {
  110. if(printMaterialLengths[index] > 0)
  111. {
  112. names.push(printMaterialNames[index])
  113. lengths.push(printMaterialLengths[index].toFixed(2))
  114. weights.push(String(Math.round(printMaterialWeights[index])))
  115. var cost = printMaterialCosts[index] == undefined ? 0 : printMaterialCosts[index].toFixed(2)
  116. costs.push(cost)
  117. }
  118. }
  119. }
  120. if(lengths.length == 0)
  121. {
  122. lengths = ["0.00"]
  123. weights = ["0"]
  124. costs = ["0.00"]
  125. }
  126. var text = "<table width=\"100%\">"
  127. for(var index = 0; index < lengths.length; index++)
  128. {
  129. text += formatRow([
  130. "%1:".arg(names[index]),
  131. catalog.i18nc("@label m for meter", "%1m").arg(lengths[index]),
  132. catalog.i18nc("@label g for grams", "%1g").arg(weights[index]),
  133. "%1&nbsp;%2".arg(UM.Preferences.getValue("cura/currency")).arg(costs[index]),
  134. ])
  135. }
  136. text += "</table>"
  137. return text
  138. }
  139. text: getMaterialSpecifications()
  140. width: parent.width - 2 * UM.Theme.getSize("default_margin").width
  141. color: UM.Theme.getColor("text")
  142. font: UM.Theme.getFont("very_small")
  143. renderType: Text.NativeRendering
  144. textFormat: Text.RichText
  145. }
  146. }
  147. }