RenameDialog.qml 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Window 2.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. UM.Dialog
  9. {
  10. id: base
  11. buttonSpacing: UM.Theme.getSize("default_margin").width
  12. property string object: ""
  13. property alias newName: nameField.text
  14. property bool validName: true
  15. property string validationError
  16. property string dialogTitle: catalog.i18nc("@title:window", "Rename")
  17. property string explanation: catalog.i18nc("@info", "Please provide a new name.")
  18. title: dialogTitle
  19. backgroundColor: UM.Theme.getColor("main_background")
  20. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  21. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  22. width: minimumWidth
  23. height: minimumHeight
  24. property variant catalog: UM.I18nCatalog { name: "cura" }
  25. signal textChanged(string text)
  26. signal selectText()
  27. onSelectText:
  28. {
  29. nameField.selectAll();
  30. nameField.focus = true;
  31. }
  32. Column
  33. {
  34. anchors.fill: parent
  35. UM.Label
  36. {
  37. text: base.explanation + "\n" //Newline to make some space using system theming.
  38. width: parent.width
  39. wrapMode: Text.WordWrap
  40. }
  41. Cura.TextField
  42. {
  43. id: nameField
  44. width: parent.width
  45. text: base.object
  46. maximumLength: 40
  47. selectByMouse: true
  48. onTextChanged: base.textChanged(text)
  49. }
  50. UM.Label
  51. {
  52. visible: !base.validName
  53. text: base.validationError
  54. }
  55. }
  56. rightButtons: [
  57. Cura.SecondaryButton
  58. {
  59. id: cancelButton
  60. text: catalog.i18nc("@action:button","Cancel")
  61. onClicked: base.reject()
  62. },
  63. Cura.PrimaryButton
  64. {
  65. id: okButton
  66. text: catalog.i18nc("@action:button", "OK")
  67. onClicked: base.accept()
  68. enabled: base.validName
  69. }
  70. ]
  71. }