JobSpecs.qml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. Rectangle {
  9. id: base;
  10. property bool activity: Printer.getPlatformActivity;
  11. property string fileBaseName
  12. property variant activeMachineInstance: UM.MachineManager.activeMachineInstance
  13. onActiveMachineInstanceChanged:
  14. {
  15. base.createFileName()
  16. }
  17. UM.I18nCatalog { id: catalog; name:"cura"}
  18. property variant printDuration: PrintInformation.currentPrintTime;
  19. property real printMaterialAmount: PrintInformation.materialAmount;
  20. height: childrenRect.height
  21. color: "transparent"
  22. function createFileName(){
  23. var splitMachineName = UM.MachineManager.activeMachineInstance.split(" ")
  24. var abbrMachine = ''
  25. for (var i = 0; i < splitMachineName.length; i++){
  26. if (splitMachineName[i].search(/ultimaker/i) != -1){
  27. abbrMachine += 'UM'
  28. }
  29. else{
  30. if (splitMachineName[i].charAt(0).search(/[0-9]/g) == -1)
  31. abbrMachine += splitMachineName[i].charAt(0)
  32. }
  33. var regExpAdditives = /[0-9\+]/g;
  34. var resultAdditives = splitMachineName[i].match(regExpAdditives);
  35. if (resultAdditives != null){
  36. for (var j = 0; j < resultAdditives.length; j++){
  37. abbrMachine += resultAdditives[j]
  38. }
  39. }
  40. }
  41. printJobTextfield.text = abbrMachine + '_' + base.fileBaseName
  42. }
  43. Connections {
  44. target: backgroundItem
  45. onHasMesh: {
  46. base.fileBaseName = name
  47. }
  48. }
  49. onActivityChanged: {
  50. if (activity == true && base.fileBaseName == ''){
  51. //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)
  52. base.fileBaseName = Printer.jobName //it gets the fileBaseName from CuraApplication.py because this saves the filebase when the file is opened using the terminal (or something alike)
  53. base.createFileName()
  54. }
  55. if (activity == true && base.fileBaseName != ''){
  56. //this runs in all other cases where there is a mesh on the buildplate (activity == true). It uses the fileBaseName from the hasMesh signal
  57. base.createFileName()
  58. }
  59. if (activity == false){
  60. //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)
  61. printJobTextfield.text = ''
  62. }
  63. }
  64. Rectangle
  65. {
  66. id: jobNameRow
  67. anchors.top: parent.top
  68. anchors.right: parent.right
  69. height: UM.Theme.getSize("jobspecs_line").height
  70. visible: base.activity
  71. Item
  72. {
  73. width: parent.width
  74. height: parent.height
  75. Button
  76. {
  77. id: printJobPencilIcon
  78. anchors.right: parent.right
  79. anchors.verticalCenter: parent.verticalCenter
  80. width: UM.Theme.getSize("save_button_specs_icons").width
  81. height: UM.Theme.getSize("save_button_specs_icons").height
  82. onClicked:
  83. {
  84. printJobTextfield.selectAll()
  85. printJobTextfield.focus = true
  86. }
  87. style: ButtonStyle
  88. {
  89. background: Rectangle
  90. {
  91. color: "transparent"
  92. UM.RecolorImage
  93. {
  94. width: UM.Theme.getSize("save_button_specs_icons").width
  95. height: UM.Theme.getSize("save_button_specs_icons").height
  96. sourceSize.width: width
  97. sourceSize.height: width
  98. color: control.hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("text");
  99. source: UM.Theme.getIcon("pencil");
  100. }
  101. }
  102. }
  103. }
  104. TextField
  105. {
  106. id: printJobTextfield
  107. anchors.right: printJobPencilIcon.left
  108. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  109. height: UM.Theme.getSize("jobspecs_line").height
  110. width: __contentWidth + UM.Theme.getSize("default_margin").width
  111. maximumLength: 120
  112. property int unremovableSpacing: 5
  113. text: ''
  114. horizontalAlignment: TextInput.AlignRight
  115. onTextChanged: {
  116. if(text != ''){
  117. //Prevent that jobname is set to an empty string
  118. Printer.setJobName(text)
  119. }
  120. }
  121. onEditingFinished: {
  122. if (printJobTextfield.text != ''){
  123. printJobTextfield.focus = false
  124. }
  125. }
  126. validator: RegExpValidator {
  127. regExp: /^[^\\ \/ \.]*$/
  128. }
  129. style: TextFieldStyle{
  130. textColor: UM.Theme.getColor("setting_control_text");
  131. font: UM.Theme.getFont("default_bold");
  132. background: Rectangle {
  133. opacity: 0
  134. border.width: 0
  135. }
  136. }
  137. }
  138. }
  139. }
  140. Label{
  141. id: boundingSpec
  142. anchors.top: jobNameRow.bottom
  143. anchors.right: parent.right
  144. height: UM.Theme.getSize("jobspecs_line").height
  145. verticalAlignment: Text.AlignVCenter
  146. font: UM.Theme.getFont("small")
  147. color: UM.Theme.getColor("text_subtext")
  148. text: Printer.getSceneBoundingBoxString
  149. }
  150. Rectangle {
  151. id: specsRow
  152. anchors.top: boundingSpec.bottom
  153. anchors.right: parent.right
  154. height: UM.Theme.getSize("jobspecs_line").height
  155. Item{
  156. width: parent.width
  157. height: parent.height
  158. UM.RecolorImage {
  159. id: timeIcon
  160. anchors.right: timeSpec.left
  161. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  162. anchors.verticalCenter: parent.verticalCenter
  163. width: UM.Theme.getSize("save_button_specs_icons").width
  164. height: UM.Theme.getSize("save_button_specs_icons").height
  165. sourceSize.width: width
  166. sourceSize.height: width
  167. color: UM.Theme.getColor("text_subtext")
  168. source: UM.Theme.getIcon("print_time");
  169. }
  170. Label{
  171. id: timeSpec
  172. anchors.right: lengthIcon.left
  173. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  174. anchors.verticalCenter: parent.verticalCenter
  175. font: UM.Theme.getFont("small")
  176. color: UM.Theme.getColor("text_subtext")
  177. text: (!base.printDuration || !base.printDuration.valid) ? catalog.i18nc("@label", "00h 00min") : base.printDuration.getDisplayString(UM.DurationFormat.Short)
  178. }
  179. UM.RecolorImage {
  180. id: lengthIcon
  181. anchors.right: lengthSpec.left
  182. anchors.rightMargin: UM.Theme.getSize("default_margin").width/2
  183. anchors.verticalCenter: parent.verticalCenter
  184. width: UM.Theme.getSize("save_button_specs_icons").width
  185. height: UM.Theme.getSize("save_button_specs_icons").height
  186. sourceSize.width: width
  187. sourceSize.height: width
  188. color: UM.Theme.getColor("text_subtext")
  189. source: UM.Theme.getIcon("category_material");
  190. }
  191. Label{
  192. id: lengthSpec
  193. anchors.right: parent.right
  194. anchors.verticalCenter: parent.verticalCenter
  195. font: UM.Theme.getFont("small")
  196. color: UM.Theme.getColor("text_subtext")
  197. text: base.printMaterialAmount <= 0 ? catalog.i18nc("@label", "0.0 m") : catalog.i18nc("@label", "%1 m").arg(base.printMaterialAmount)
  198. }
  199. }
  200. }
  201. }