SettingsView.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import ru.ded.beerlog 1.0
  4. import ru.ded.components 1.0
  5. Page {
  6. id: root
  7. title: qsTr("Settings")
  8. property var controls: {
  9. "text": textComponent,
  10. "choice": choiceComponent
  11. }
  12. SettingsViewModel {
  13. id: settingsModel
  14. }
  15. ListView {
  16. anchors.fill: parent
  17. model: settingsModel
  18. delegate: SubtitledItemDelegate {
  19. width: parent.width
  20. text: model.title
  21. subtitle: model.subtitle || ""
  22. function valueAccepted() {
  23. model.value = editor.value
  24. }
  25. function disconnectDialog() {
  26. inputDialog.accepted.disconnect(valueAccepted)
  27. }
  28. onClicked: {
  29. inputDialog.title = model.title
  30. inputDialog.control = controls[model.control]
  31. inputDialog.initialValue = model.value
  32. inputDialog.choiceModel = model.choiceModel
  33. inputDialog.accepted.connect(valueAccepted)
  34. inputDialog.closed.connect(disconnectDialog)
  35. inputDialog.open()
  36. }
  37. }
  38. }
  39. Dialog {
  40. id: inputDialog
  41. property var choiceModel: undefined
  42. property var initialValue: undefined
  43. property alias control: editor.sourceComponent
  44. width: root.width * 0.8
  45. anchors.centerIn: parent
  46. parent: ApplicationWindow.overlay
  47. modal: true
  48. standardButtons: Dialog.Ok | Dialog.Cancel
  49. Loader {
  50. id: editor
  51. property var value: item && item.value
  52. anchors.fill: parent
  53. }
  54. }
  55. Component {
  56. id: textComponent
  57. TextField {
  58. id: textField
  59. property string value: text
  60. inputMethodHints: Qt.ImhNoAutoUppercase
  61. text: inputDialog.initialValue || ""
  62. }
  63. }
  64. ButtonGroup {
  65. id: group
  66. }
  67. Component {
  68. id: choiceComponent
  69. Column {
  70. property var value: group.checkedButton && group.checkedButton.valueId
  71. Repeater {
  72. model: inputDialog.choiceModel
  73. delegate: RadioDelegate {
  74. property var valueId: modelData.id
  75. text: modelData.name
  76. width: parent.width
  77. checked: inputDialog.initialValue === valueId
  78. ButtonGroup.group: group
  79. }
  80. }
  81. }
  82. }
  83. }