main.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import QtQuick 2.9
  2. import QtQuick.Controls 2.2
  3. import Qt.labs.settings 1.0
  4. ApplicationWindow {
  5. id: window
  6. visible: true
  7. width: 640
  8. height: 480
  9. title: qsTr("Stack")
  10. Settings {
  11. id: settings
  12. property string serviceUrl: ""
  13. }
  14. LightsModel {
  15. id: lightsModel
  16. serviceUrl: settings.serviceUrl
  17. onError: stackView.showError(text)
  18. }
  19. header: ToolBar {
  20. contentHeight: 36
  21. MenuBackButton {
  22. id: menuButton
  23. anchors.verticalCenter: parent.verticalCenter
  24. anchors.left: parent.left
  25. anchors.leftMargin: 8
  26. width: 24
  27. height: 24
  28. state: stackView.depth > 1 ? "back" : "menu"
  29. onClicked: {
  30. drawer.open()
  31. }
  32. onBack: {
  33. stackView.pop()
  34. }
  35. }
  36. Label {
  37. text: stackView.currentItem.title
  38. anchors.centerIn: parent
  39. }
  40. }
  41. Drawer {
  42. id: drawer
  43. width: window.width * 0.66
  44. height: window.height
  45. Column {
  46. anchors.fill: parent
  47. Row {
  48. width: parent.width
  49. height: 100
  50. Image {
  51. anchors.top: parent.top
  52. anchors.bottom: parent.bottom
  53. anchors.margins: 10
  54. source: "lamp.png"
  55. }
  56. Label {
  57. anchors.verticalCenter: parent.verticalCenter
  58. font.pointSize: 20
  59. text: qsTr("nooLight v0.1")
  60. }
  61. }
  62. ItemDelegate {
  63. text: qsTr("Service")
  64. width: parent.width
  65. onClicked: {
  66. stackView.openPage("ServiceForm.qml")
  67. }
  68. }
  69. ItemDelegate {
  70. text: qsTr("Settings")
  71. width: parent.width
  72. onClicked: {
  73. stackView.openPage("SettingsForm.qml")
  74. }
  75. }
  76. }
  77. }
  78. StackView {
  79. id: stackView
  80. initialItem: "HomeForm.qml"
  81. anchors.fill: parent
  82. function openPage(page) {
  83. if (depth > 1) {
  84. pop()
  85. }
  86. push(page)
  87. drawer.close()
  88. }
  89. function showError(text) {
  90. ToolTip.show(text, 1000)
  91. }
  92. }
  93. onClosing: {
  94. if (stackView.depth > 1) {
  95. close.accepted = false
  96. stackView.pop()
  97. }
  98. }
  99. }