ActionPanelWidget.qml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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.0
  5. import QtQuick.Layouts 1.3
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. Rectangle
  9. {
  10. id: base
  11. // We need a whole lot of print duration information.
  12. property variant printDuration: PrintInformation.currentPrintTime
  13. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
  14. signal showTooltip(Item item, point location, string text)
  15. signal hideTooltip()
  16. color: UM.Theme.getColor("main_background")
  17. // Also add an extra margin, as we want some breathing room around the edges.
  18. height: saveButton.height + UM.Theme.getSize("thick_margin").height
  19. Label
  20. {
  21. id: timeDetails
  22. anchors.left: parent.left
  23. anchors.bottom: costSpec.top
  24. anchors.leftMargin: UM.Theme.getSize("thick_margin").width
  25. font: UM.Theme.getFont("large")
  26. color: UM.Theme.getColor("text_subtext")
  27. text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label Hours and minutes", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
  28. renderType: Text.NativeRendering
  29. MouseArea
  30. {
  31. id: timeDetailsMouseArea
  32. anchors.fill: parent
  33. hoverEnabled: true
  34. onEntered:
  35. {
  36. if(base.printDuration.valid && !base.printDuration.isTotalDurationZero)
  37. {
  38. // All the time information for the different features is achieved
  39. var print_time = PrintInformation.getFeaturePrintTimes();
  40. var total_seconds = parseInt(base.printDuration.getDisplayString(UM.DurationFormat.Seconds))
  41. // A message is created and displayed when the user hover the time label
  42. var tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@tooltip", "Time specification"));
  43. for(var feature in print_time)
  44. {
  45. if(!print_time[feature].isTotalDurationZero)
  46. {
  47. tooltip_html += "<tr><td>" + feature + ":</td>" +
  48. "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(print_time[feature].getDisplayString(UM.DurationFormat.ISO8601).slice(0,-3)) +
  49. "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1%</td>".arg(Math.round(100 * parseInt(print_time[feature].getDisplayString(UM.DurationFormat.Seconds)) / total_seconds)) +
  50. "</td></tr>";
  51. }
  52. }
  53. tooltip_html += "</table>";
  54. base.showTooltip(parent, Qt.point(-UM.Theme.getSize("thick_margin").width, 0), tooltip_html);
  55. }
  56. }
  57. onExited:
  58. {
  59. base.hideTooltip();
  60. }
  61. }
  62. }
  63. Label
  64. {
  65. function formatRow(items)
  66. {
  67. var row_html = "<tr>";
  68. for(var item = 0; item < items.length; item++)
  69. {
  70. if (item == 0)
  71. {
  72. row_html += "<td valign=\"bottom\">%1</td>".arg(items[item]);
  73. }
  74. else
  75. {
  76. row_html += "<td align=\"right\" valign=\"bottom\">&nbsp;&nbsp;%1</td>".arg(items[item]);
  77. }
  78. }
  79. row_html += "</tr>";
  80. return row_html;
  81. }
  82. function getSpecsData()
  83. {
  84. var lengths = [];
  85. var total_length = 0;
  86. var weights = [];
  87. var total_weight = 0;
  88. var costs = [];
  89. var total_cost = 0;
  90. var some_costs_known = false;
  91. var names = [];
  92. if(base.printMaterialLengths)
  93. {
  94. for(var index = 0; index < base.printMaterialLengths.length; index++)
  95. {
  96. if(base.printMaterialLengths[index] > 0)
  97. {
  98. names.push(base.printMaterialNames[index]);
  99. lengths.push(base.printMaterialLengths[index].toFixed(2));
  100. weights.push(String(Math.round(base.printMaterialWeights[index])));
  101. var cost = base.printMaterialCosts[index] == undefined ? 0 : base.printMaterialCosts[index].toFixed(2);
  102. costs.push(cost);
  103. if(cost > 0)
  104. {
  105. some_costs_known = true;
  106. }
  107. total_length += base.printMaterialLengths[index];
  108. total_weight += base.printMaterialWeights[index];
  109. total_cost += base.printMaterialCosts[index];
  110. }
  111. }
  112. }
  113. if(lengths.length == 0)
  114. {
  115. lengths = ["0.00"];
  116. weights = ["0"];
  117. costs = ["0.00"];
  118. }
  119. var tooltip_html = "<b>%1</b><br/><table width=\"100%\">".arg(catalog.i18nc("@label", "Cost specification"));
  120. for(var index = 0; index < lengths.length; index++)
  121. {
  122. tooltip_html += formatRow([
  123. "%1:".arg(names[index]),
  124. catalog.i18nc("@label m for meter", "%1m").arg(lengths[index]),
  125. catalog.i18nc("@label g for grams", "%1g").arg(weights[index]),
  126. "%1&nbsp;%2".arg(UM.Preferences.getValue("cura/currency")).arg(costs[index]),
  127. ]);
  128. }
  129. if(lengths.length > 1)
  130. {
  131. tooltip_html += formatRow([
  132. catalog.i18nc("@label", "Total:"),
  133. catalog.i18nc("@label m for meter", "%1m").arg(total_length.toFixed(2)),
  134. catalog.i18nc("@label g for grams", "%1g").arg(Math.round(total_weight)),
  135. "%1 %2".arg(UM.Preferences.getValue("cura/currency")).arg(total_cost.toFixed(2)),
  136. ]);
  137. }
  138. tooltip_html += "</table>";
  139. tooltipText = tooltip_html;
  140. return tooltipText
  141. }
  142. id: costSpec
  143. anchors.left: parent.left
  144. anchors.bottom: parent.bottom
  145. anchors.bottomMargin: UM.Theme.getSize("thick_margin").height
  146. anchors.leftMargin: UM.Theme.getSize("thick_margin").width
  147. font: UM.Theme.getFont("very_small")
  148. renderType: Text.NativeRendering
  149. color: UM.Theme.getColor("text_subtext")
  150. elide: Text.ElideMiddle
  151. width: parent.width
  152. property string tooltipText
  153. text:
  154. {
  155. var lengths = [];
  156. var weights = [];
  157. var costs = [];
  158. var someCostsKnown = false;
  159. if(base.printMaterialLengths)
  160. {
  161. for(var index = 0; index < base.printMaterialLengths.length; index++)
  162. {
  163. if(base.printMaterialLengths[index] > 0)
  164. {
  165. lengths.push(base.printMaterialLengths[index].toFixed(2));
  166. weights.push(String(Math.round(base.printMaterialWeights[index])));
  167. var cost = base.printMaterialCosts[index] == undefined ? 0 : base.printMaterialCosts[index].toFixed(2);
  168. costs.push(cost);
  169. if(cost > 0)
  170. {
  171. someCostsKnown = true;
  172. }
  173. }
  174. }
  175. }
  176. if(lengths.length == 0)
  177. {
  178. lengths = ["0.00"];
  179. weights = ["0"];
  180. costs = ["0.00"];
  181. }
  182. var result = lengths.join(" + ") + "m / ~ " + weights.join(" + ") + "g";
  183. if(someCostsKnown)
  184. {
  185. result += " / ~ " + costs.join(" + ") + " " + UM.Preferences.getValue("cura/currency");
  186. }
  187. return result;
  188. }
  189. MouseArea
  190. {
  191. id: costSpecMouseArea
  192. anchors.fill: parent
  193. hoverEnabled: true
  194. onEntered:
  195. {
  196. if(base.printDuration.valid && !base.printDuration.isTotalDurationZero)
  197. {
  198. var show_data = costSpec.getSpecsData()
  199. base.showTooltip(parent, Qt.point(-UM.Theme.getSize("thick_margin").width, 0), show_data);
  200. }
  201. }
  202. onExited:
  203. {
  204. base.hideTooltip();
  205. }
  206. }
  207. }
  208. SaveButton
  209. {
  210. id: saveButton
  211. width: parent.width
  212. height: 100 * screenScaleFactor
  213. anchors.bottom: parent.bottom
  214. }
  215. }