main.qml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import QtQuick 2.9
  2. import QtQuick.Controls 2.2
  3. import Qt.labs.settings 1.0
  4. import ru.ded.components 1.0
  5. ApplicationWindow {
  6. id: window
  7. visible: true
  8. width: 640
  9. height: 480
  10. title: qsTr("Stack")
  11. Settings {
  12. id: settings
  13. property string serviceUrl: ""
  14. }
  15. LightsModel {
  16. id: lightsModel
  17. serviceUrl: settings.serviceUrl
  18. onError: (text) => stackView.showError(text)
  19. }
  20. header: ToolBar {
  21. contentHeight: 36
  22. MenuBackButton {
  23. id: menuButton
  24. anchors.verticalCenter: parent.verticalCenter
  25. anchors.left: parent.left
  26. anchors.leftMargin: 8
  27. state: stackView.depth > 1 ? "back" : "menu"
  28. onClicked: {
  29. mainMenu.open()
  30. }
  31. onBack: {
  32. stackView.pop()
  33. }
  34. }
  35. Label {
  36. text: stackView.currentItem.title
  37. anchors.centerIn: parent
  38. }
  39. }
  40. MainMenu {
  41. id: mainMenu
  42. readonly property var actions: {
  43. "service": () => { stackView.openPage("ServiceForm.qml") },
  44. "settings": () => { stackView.openPage("SettingsForm.qml") },
  45. "quit": () => { Qt.quit() }
  46. }
  47. logo: "/images/lamp.png"
  48. appName: qsTr("nooLight v1.0")
  49. model: ListModel {
  50. ListElement {
  51. title: qsTr("Service")
  52. action: "service"
  53. }
  54. ListElement {
  55. title: qsTr("Settings")
  56. action: "settings"
  57. }
  58. ListElement {
  59. title: qsTr("Quit")
  60. action: "quit"
  61. }
  62. }
  63. onActionSelected: (action) => actions[action]()
  64. }
  65. StackView {
  66. id: stackView
  67. initialItem: "HomeForm.qml"
  68. anchors.fill: parent
  69. function openPage(page) {
  70. if (depth > 1) {
  71. pop()
  72. }
  73. push(page)
  74. mainMenu.close()
  75. }
  76. function showError(text) {
  77. ToolTip.show(text, 1000)
  78. }
  79. }
  80. onClosing: {
  81. if (stackView.depth > 1) {
  82. close.accepted = false
  83. stackView.pop()
  84. }
  85. }
  86. }