SettingsView.qml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import Components 1.0
  4. import ru.ded.beerlog 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: settingsService[model.name]
  22. onClicked: {
  23. inputDialog.title = model.title
  24. inputDialog.name = model.name
  25. inputDialog.control = controls[model.control]
  26. inputDialog.choiceModel = model.choiceModel
  27. inputDialog.open()
  28. }
  29. }
  30. }
  31. Dialog {
  32. id: inputDialog
  33. property string name: ""
  34. property var choiceModel: undefined
  35. property alias control: editor.sourceComponent
  36. width: root.width * 0.8
  37. anchors.centerIn: parent
  38. parent: ApplicationWindow.overlay
  39. modal: true
  40. standardButtons: Dialog.Ok | Dialog.Cancel
  41. Loader {
  42. id: editor
  43. property var value: item && item.value
  44. anchors.fill: parent
  45. }
  46. onAccepted: {
  47. settingsService[inputDialog.name] = editor.value
  48. }
  49. }
  50. Component {
  51. id: textComponent
  52. TextField {
  53. id: textField
  54. property alias value: textField.text
  55. inputMethodHints: Qt.ImhNoAutoUppercase
  56. text: settingsService[inputDialog.name] || ""
  57. }
  58. }
  59. ButtonGroup {
  60. id: group
  61. }
  62. Component {
  63. id: choiceComponent
  64. Column {
  65. property var value: group.checkedButton && group.checkedButton.valueId
  66. Repeater {
  67. model: inputDialog.choiceModel
  68. delegate: RadioDelegate {
  69. property var valueId: modelData.id
  70. text: modelData.name
  71. width: parent.width
  72. checked: settingsService[inputDialog.name] === valueId
  73. ButtonGroup.group: group
  74. }
  75. }
  76. }
  77. }
  78. }