RenameDialog.qml 2.9 KB

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