RenameDialog.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 string objectPlaceholder: ""
  14. property alias newName: nameField.text
  15. property bool validName: true
  16. property string validationError
  17. property string dialogTitle: catalog.i18nc("@title:window", "Rename")
  18. property string explanation: catalog.i18nc("@info", "Please provide a new name.")
  19. property string okButtonText: catalog.i18nc("@action:button", "OK")
  20. // Extra Information for the user about the current rename can go here, can be left alone if not needed.
  21. // For example; An icon and a text-field and a tertiary button providing a link.
  22. property list<Item> extraInfo
  23. title: dialogTitle
  24. backgroundColor: UM.Theme.getColor("main_background")
  25. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  26. minimumHeight: UM.Theme.getSize("small_popup_dialog").height + extraInfoHolder.height
  27. width: minimumWidth
  28. height: minimumHeight
  29. property variant catalog: UM.I18nCatalog { name: "cura" }
  30. signal textChanged(string text)
  31. signal selectText()
  32. onSelectText:
  33. {
  34. nameField.selectAll();
  35. nameField.focus = true;
  36. }
  37. Column
  38. {
  39. anchors.fill: parent
  40. UM.Label
  41. {
  42. text: base.explanation + "\n" //Newline to make some space using system theming.
  43. width: parent.width
  44. wrapMode: Text.WordWrap
  45. }
  46. Cura.TextField
  47. {
  48. id: nameField
  49. width: parent.width
  50. text: base.object
  51. placeholderText: base.objectPlaceholder
  52. placeholderTextColor: UM.Theme.getColor("text_field_text_disabled")
  53. maximumLength: 40
  54. selectByMouse: true
  55. onTextChanged: base.textChanged(text)
  56. }
  57. // spacer
  58. Item
  59. {
  60. height: UM.Theme.getSize("wide_margin").height
  61. width: height
  62. }
  63. Row
  64. {
  65. id: extraInfoHolder
  66. anchors
  67. {
  68. left: parent.left
  69. right: parent.right
  70. margins: UM.Theme.getSize("default_margin").height
  71. }
  72. spacing: UM.Theme.getSize("default_margin").height
  73. children: extraInfo
  74. }
  75. UM.Label
  76. {
  77. visible: !base.validName
  78. text: base.validationError
  79. }
  80. }
  81. leftButtons:
  82. [
  83. Cura.TertiaryButton
  84. {
  85. id: cancelButton
  86. text: catalog.i18nc("@action:button","Cancel")
  87. onClicked: base.reject()
  88. }
  89. ]
  90. rightButtons:
  91. [
  92. Cura.PrimaryButton
  93. {
  94. id: okButton
  95. text: base.okButtonText
  96. onClicked: base.accept()
  97. enabled: base.validName
  98. }
  99. ]
  100. }