JobSpecs.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. Rectangle {
  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. height: childrenRect.height
  23. color: "transparent"
  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: Rectangle
  73. {
  74. color: "transparent"
  75. UM.RecolorImage
  76. {
  77. width: UM.Theme.getSize("save_button_specs_icons").width;
  78. height: UM.Theme.getSize("save_button_specs_icons").height;
  79. sourceSize.width: width;
  80. sourceSize.height: width;
  81. color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("text");
  82. source: UM.Theme.getIcon("pencil");
  83. }
  84. }
  85. }
  86. }
  87. TextField
  88. {
  89. id: printJobTextfield
  90. anchors.right: printJobPencilIcon.left
  91. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  92. height: UM.Theme.getSize("jobspecs_line").height
  93. width: Math.max(__contentWidth + UM.Theme.getSize("default_margin").width, 50)
  94. maximumLength: 120
  95. property int unremovableSpacing: 5
  96. text: ''
  97. horizontalAlignment: TextInput.AlignRight
  98. onTextChanged: {
  99. PrintInformation.setJobName(text);
  100. }
  101. onEditingFinished: {
  102. if (printJobTextfield.text != ''){
  103. printJobTextfield.focus = false;
  104. }
  105. }
  106. validator: RegExpValidator {
  107. regExp: /^[^\\ \/ \*\?\|\[\]]*$/
  108. }
  109. style: TextFieldStyle{
  110. textColor: UM.Theme.getColor("setting_control_text");
  111. font: UM.Theme.getFont("default_bold");
  112. background: Rectangle {
  113. opacity: 0
  114. border.width: 0
  115. }
  116. }
  117. }
  118. }
  119. }
  120. Label{
  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. id: specsRow
  132. anchors.top: boundingSpec.bottom
  133. anchors.right: parent.right
  134. height: UM.Theme.getSize("jobspecs_line").height
  135. Item{
  136. width: parent.width
  137. height: parent.height
  138. UM.RecolorImage {
  139. id: timeIcon
  140. anchors.right: timeSpec.left
  141. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  142. anchors.verticalCenter: parent.verticalCenter
  143. width: UM.Theme.getSize("save_button_specs_icons").width
  144. height: UM.Theme.getSize("save_button_specs_icons").height
  145. sourceSize.width: width
  146. sourceSize.height: width
  147. color: UM.Theme.getColor("text_subtext")
  148. source: UM.Theme.getIcon("print_time")
  149. }
  150. Label{
  151. id: timeSpec
  152. anchors.right: lengthIcon.left
  153. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  154. anchors.verticalCenter: parent.verticalCenter
  155. font: UM.Theme.getFont("small")
  156. color: UM.Theme.getColor("text_subtext")
  157. text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
  158. }
  159. UM.RecolorImage {
  160. id: lengthIcon
  161. anchors.right: lengthSpec.left
  162. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  163. anchors.verticalCenter: parent.verticalCenter
  164. width: UM.Theme.getSize("save_button_specs_icons").width
  165. height: UM.Theme.getSize("save_button_specs_icons").height
  166. sourceSize.width: width
  167. sourceSize.height: width
  168. color: UM.Theme.getColor("text_subtext")
  169. source: UM.Theme.getIcon("category_material")
  170. }
  171. Label{
  172. id: lengthSpec
  173. anchors.right: parent.right
  174. anchors.verticalCenter: parent.verticalCenter
  175. font: UM.Theme.getFont("small")
  176. color: UM.Theme.getColor("text_subtext")
  177. text:
  178. {
  179. var lengths = [];
  180. var weights = [];
  181. if(base.printMaterialLengths) {
  182. for(var index = 0; index < base.printMaterialLengths.length; index++) {
  183. if(base.printMaterialLengths[index] > 0) {
  184. lengths.push(base.printMaterialLengths[index].toFixed(2));
  185. weights.push(String(Math.floor(base.printMaterialWeights[index])));
  186. }
  187. }
  188. }
  189. if(lengths.length == 0) {
  190. lengths = ["0.00"];
  191. weights = ["0"];
  192. }
  193. return catalog.i18nc("@label", "%1 m / ~ %2 g").arg(lengths.join(" + ")).arg(weights.join(" + "));
  194. }
  195. }
  196. }
  197. }
  198. }