main.qml 2.2 KB

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