JobSpecs.qml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.1 as UM
  8. import Cura 1.0 as Cura
  9. Item {
  10. id: base
  11. property bool activity: Printer.getPlatformActivity
  12. property string fileBaseName
  13. property variant activeMachineName: Cura.MachineManager.activeMachineName
  14. onActiveMachineNameChanged:
  15. {
  16. printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
  17. }
  18. UM.I18nCatalog { id: catalog; name:"cura"}
  19. property variant printDuration: PrintInformation.currentPrintTime
  20. property variant printMaterialLengths: PrintInformation.materialLengths
  21. property variant printMaterialWeights: PrintInformation.materialWeights
  22. property variant printMaterialCosts: PrintInformation.materialCosts
  23. height: childrenRect.height
  24. Connections
  25. {
  26. target: backgroundItem
  27. onHasMesh:
  28. {
  29. base.fileBaseName = name
  30. }
  31. }
  32. onActivityChanged: {
  33. if (activity == true && base.fileBaseName == ''){
  34. //this only runs when you open a file from the terminal (or something that works the same way; for example when you drag a file on the icon in MacOS or use 'open with' on Windows)
  35. base.fileBaseName = PrintInformation.jobName; //get the fileBaseName from PrintInformation.py because this saves the filebase when the file is opened using the terminal (or something alike)
  36. printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
  37. }
  38. if (activity == true && base.fileBaseName != ''){
  39. //this runs in all other cases where there is a mesh on the buildplate (activity == true). It uses the fileBaseName from the hasMesh signal
  40. printJobTextfield.text = PrintInformation.createJobName(base.fileBaseName);
  41. }
  42. if (activity == false){
  43. //When there is no mesh in the buildplate; the printJobTextField is set to an empty string so it doesn't set an empty string as a jobName (which is later used for saving the file)
  44. printJobTextfield.text = '';
  45. }
  46. }
  47. Rectangle
  48. {
  49. id: jobNameRow
  50. anchors.top: parent.top
  51. anchors.right: parent.right
  52. height: UM.Theme.getSize("jobspecs_line").height
  53. visible: base.activity
  54. Item
  55. {
  56. width: parent.width
  57. height: parent.height
  58. Button
  59. {
  60. id: printJobPencilIcon
  61. anchors.right: parent.right
  62. anchors.verticalCenter: parent.verticalCenter
  63. width: UM.Theme.getSize("save_button_specs_icons").width
  64. height: UM.Theme.getSize("save_button_specs_icons").height
  65. onClicked:
  66. {
  67. printJobTextfield.selectAll();
  68. printJobTextfield.focus = true;
  69. }
  70. style: ButtonStyle
  71. {
  72. background: Item
  73. {
  74. UM.RecolorImage
  75. {
  76. width: UM.Theme.getSize("save_button_specs_icons").width;
  77. height: UM.Theme.getSize("save_button_specs_icons").height;
  78. sourceSize.width: width;
  79. sourceSize.height: width;
  80. color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("text");
  81. source: UM.Theme.getIcon("pencil");
  82. }
  83. }
  84. }
  85. }
  86. TextField
  87. {
  88. id: printJobTextfield
  89. anchors.right: printJobPencilIcon.left
  90. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  91. height: UM.Theme.getSize("jobspecs_line").height
  92. width: Math.max(__contentWidth + UM.Theme.getSize("default_margin").width, 50)
  93. maximumLength: 120
  94. property int unremovableSpacing: 5
  95. text: ''
  96. horizontalAlignment: TextInput.AlignRight
  97. onTextChanged: {
  98. PrintInformation.setJobName(text);
  99. }
  100. onEditingFinished: {
  101. if (printJobTextfield.text != ''){
  102. printJobTextfield.focus = false;
  103. }
  104. }
  105. validator: RegExpValidator {
  106. regExp: /^[^\\ \/ \*\?\|\[\]]*$/
  107. }
  108. style: TextFieldStyle{
  109. textColor: UM.Theme.getColor("setting_control_text");
  110. font: UM.Theme.getFont("default_bold");
  111. background: Rectangle {
  112. opacity: 0
  113. border.width: 0
  114. }
  115. }
  116. }
  117. }
  118. }
  119. Label
  120. {
  121. id: boundingSpec
  122. anchors.top: jobNameRow.bottom
  123. anchors.right: parent.right
  124. height: UM.Theme.getSize("jobspecs_line").height
  125. verticalAlignment: Text.AlignVCenter
  126. font: UM.Theme.getFont("small")
  127. color: UM.Theme.getColor("text_subtext")
  128. text: Printer.getSceneBoundingBoxString
  129. }
  130. Rectangle
  131. {
  132. id: specsRow
  133. anchors.top: boundingSpec.bottom
  134. anchors.right: parent.right
  135. height: UM.Theme.getSize("jobspecs_line").height
  136. Item
  137. {
  138. width: parent.width
  139. height: parent.height
  140. UM.RecolorImage
  141. {
  142. id: timeIcon
  143. anchors.right: timeSpec.left
  144. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  145. anchors.verticalCenter: parent.verticalCenter
  146. width: UM.Theme.getSize("save_button_specs_icons").width
  147. height: UM.Theme.getSize("save_button_specs_icons").height
  148. sourceSize.width: width
  149. sourceSize.height: width
  150. color: UM.Theme.getColor("text_subtext")
  151. source: UM.Theme.getIcon("print_time")
  152. }
  153. Label
  154. {
  155. id: timeSpec
  156. anchors.right: lengthIcon.left
  157. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  158. anchors.verticalCenter: parent.verticalCenter
  159. font: UM.Theme.getFont("small")
  160. color: UM.Theme.getColor("text_subtext")
  161. text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
  162. }
  163. UM.RecolorImage
  164. {
  165. id: lengthIcon
  166. anchors.right: lengthSpec.left
  167. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  168. anchors.verticalCenter: parent.verticalCenter
  169. width: UM.Theme.getSize("save_button_specs_icons").width
  170. height: UM.Theme.getSize("save_button_specs_icons").height
  171. sourceSize.width: width
  172. sourceSize.height: width
  173. color: UM.Theme.getColor("text_subtext")
  174. source: UM.Theme.getIcon("category_material")
  175. }
  176. Label
  177. {
  178. id: lengthSpec
  179. anchors.right: parent.right
  180. anchors.verticalCenter: parent.verticalCenter
  181. font: UM.Theme.getFont("small")
  182. color: UM.Theme.getColor("text_subtext")
  183. text:
  184. {
  185. var lengths = [];
  186. var weights = [];
  187. var costs = [];
  188. var someCostsKnown = false;
  189. if(base.printMaterialLengths) {
  190. for(var index = 0; index < base.printMaterialLengths.length; index++)
  191. {
  192. if(base.printMaterialLengths[index] > 0)
  193. {
  194. lengths.push(base.printMaterialLengths[index].toFixed(2));
  195. weights.push(String(Math.floor(base.printMaterialWeights[index])));
  196. costs.push(base.printMaterialCosts[index].toFixed(2));
  197. if(base.printMaterialCosts[index] > 0)
  198. {
  199. someCostsKnown = true;
  200. }
  201. }
  202. }
  203. }
  204. if(lengths.length == 0)
  205. {
  206. lengths = ["0.00"];
  207. weights = ["0"];
  208. costs = ["0.00"];
  209. }
  210. if(someCostsKnown)
  211. {
  212. return catalog.i18nc("@label", "%1 m / ~ %2 g / ~ %4 %3").arg(lengths.join(" + "))
  213. .arg(weights.join(" + ")).arg(costs.join(" + ")).arg(UM.Preferences.getValue("cura/currency"));
  214. }
  215. else
  216. {
  217. return catalog.i18nc("@label", "%1 m / ~ %2 g").arg(lengths.join(" + ")).arg(weights.join(" + "));
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }