JobSpecs.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. Item
  9. {
  10. id: base
  11. property bool activity: CuraApplication.platformActivity
  12. property string fileBaseName: (PrintInformation === null) ? "" : PrintInformation.baseName
  13. UM.I18nCatalog
  14. {
  15. id: catalog
  16. name: "cura"
  17. }
  18. width: childrenRect.width
  19. height: childrenRect.height
  20. onActivityChanged:
  21. {
  22. if (!activity)
  23. {
  24. // When there is no mesh in the buildplate; the printJobTextField is set to an empty string so it doesn't
  25. // set an empty string as a jobName (which is later used for saving the file)
  26. PrintInformation.baseName = ""
  27. }
  28. }
  29. Item
  30. {
  31. id: jobNameRow
  32. anchors.top: parent.top
  33. anchors.left: parent.left
  34. height: UM.Theme.getSize("jobspecs_line").height
  35. UM.SimpleButton
  36. {
  37. id: printJobPencilIcon
  38. anchors.left: parent.left
  39. anchors.verticalCenter: parent.verticalCenter
  40. width: UM.Theme.getSize("save_button_specs_icons").width
  41. height: UM.Theme.getSize("save_button_specs_icons").height
  42. iconSource: UM.Theme.getIcon("Pen")
  43. hoverColor: UM.Theme.getColor("small_button_text_hover")
  44. color: UM.Theme.getColor("small_button_text")
  45. onClicked:
  46. {
  47. printJobTextfield.selectAll()
  48. printJobTextfield.focus = true
  49. }
  50. }
  51. Cura.TextField
  52. {
  53. id: printJobTextfield
  54. anchors.left: printJobPencilIcon.right
  55. anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
  56. height: UM.Theme.getSize("jobspecs_line").height
  57. width: Math.max(contentWidth + UM.Theme.getSize("default_margin").width + 2, 50) // add two pixels to width to prevent inner text from shifting
  58. maximumLength: 120
  59. text: PrintInformation === null ? "" : PrintInformation.jobName
  60. horizontalAlignment: TextInput.AlignLeft
  61. onTextChanged:
  62. {
  63. if (!activeFocus)
  64. {
  65. // Text is changed from outside, reset the cursor position.
  66. cursorPosition = 0
  67. }
  68. }
  69. property string textBeforeEdit: ""
  70. onActiveFocusChanged:
  71. {
  72. if (activeFocus)
  73. {
  74. textBeforeEdit = text
  75. }
  76. }
  77. onEditingFinished:
  78. {
  79. if (text != textBeforeEdit) {
  80. var new_name = text == "" ? catalog.i18nc("@text Print job name", "Untitled") : text
  81. PrintInformation.setJobName(new_name, true)
  82. }
  83. printJobTextfield.focus = false
  84. cursorPosition = 0
  85. }
  86. validator: RegExpValidator {
  87. regExp: /^[^\\\/\*\?\|\[\]]*$/
  88. }
  89. color: UM.Theme.getColor("text_scene")
  90. background: Item {}
  91. selectByMouse: true
  92. }
  93. }
  94. UM.Label
  95. {
  96. id: boundingSpec
  97. anchors.top: jobNameRow.bottom
  98. anchors.left: parent.left
  99. height: UM.Theme.getSize("jobspecs_line").height
  100. color: UM.Theme.getColor("text_scene")
  101. text: CuraApplication.getSceneBoundingBoxString
  102. }
  103. Row
  104. {
  105. id: additionalComponentsRow
  106. anchors.top: boundingSpec.top
  107. anchors.bottom: boundingSpec.bottom
  108. anchors.left: boundingSpec.right
  109. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  110. }
  111. Component.onCompleted: base.addAdditionalComponents("jobSpecsButton")
  112. Connections
  113. {
  114. target: CuraApplication
  115. function onAdditionalComponentsChanged(areaId) { base.addAdditionalComponents("jobSpecsButton") }
  116. }
  117. function addAdditionalComponents(areaId)
  118. {
  119. if (areaId == "jobSpecsButton")
  120. {
  121. for (var component in CuraApplication.additionalComponents["jobSpecsButton"])
  122. {
  123. CuraApplication.additionalComponents["jobSpecsButton"][component].parent = additionalComponentsRow
  124. }
  125. }
  126. }
  127. }