main.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import QtQuick 2.15
  2. import QtQuick.Window 2.15
  3. import QtQuick.Controls 2.15
  4. import QtQuick.Layouts 1.15
  5. import QtWebSockets
  6. import ru.ded.beerlog 1.0
  7. import ru.ded.components 1.0
  8. ApplicationWindow {
  9. width: 640
  10. height: 480
  11. visible: true
  12. title: qsTr("Beer Log")
  13. header: ToolBar {
  14. RowLayout {
  15. anchors.fill: parent
  16. MenuBackButton {
  17. state: stackView.depth > 1 ? "back" : "menu"
  18. onClicked: mainMenu.open()
  19. onBack: stackView.pop()
  20. }
  21. Label {
  22. text: stackView.currentItem.title || usersModel.selectedUserName
  23. Layout.fillWidth: true
  24. Layout.minimumWidth: 100
  25. horizontalAlignment: Qt.AlignCenter
  26. MouseArea {
  27. anchors.fill: parent
  28. enabled: stackView.depth === 1
  29. onClicked: usersMenu.open()
  30. }
  31. }
  32. }
  33. Menu {
  34. id: usersMenu
  35. UsersViewModel {
  36. id: usersModel
  37. }
  38. Repeater {
  39. model: usersModel.users
  40. MenuItem {
  41. text: modelData.name
  42. onClicked: {
  43. usersModel.selectedUser = modelData.id
  44. }
  45. }
  46. }
  47. }
  48. Menu {
  49. id: storesMenu
  50. StoresViewModel {
  51. id: storesModel
  52. }
  53. Repeater {
  54. model: storesModel.stores
  55. MenuItem {
  56. text: modelData.name
  57. onClicked: {
  58. storesModel.selectedStore = modelData.id
  59. }
  60. }
  61. }
  62. }
  63. }
  64. MainMenu {
  65. id: mainMenu
  66. readonly property var actions: {
  67. "orders": () => { stackView.openPage("Views/OrdersView.qml") },
  68. "rests": () => { stackView.openPage("Views/RestsView.qml") },
  69. "settings": () => { stackView.openPage("Views/SettingsView.qml") },
  70. "benchmark": () => { stackView.openPage("Views/BenchmarkView.qml") },
  71. "quit": () => { Qt.quit() }
  72. }
  73. logo: "qrc:/logo.png"
  74. appName: qsTr("BeerLog v0.1")
  75. additional: Label {
  76. text: beerService.connected ? qsTr("Online") : qsTr("Offline")
  77. color: beerService.connected ? "green" : "red"
  78. }
  79. model: ListModel {
  80. ListElement {
  81. title: qsTr("Orders")
  82. action: "orders"
  83. }
  84. ListElement {
  85. title: qsTr("Rests")
  86. action: "rests"
  87. }
  88. ListElement {
  89. title: qsTr("Settings")
  90. action: "settings"
  91. }
  92. ListElement {
  93. title: qsTr("Benchmark")
  94. action: "benchmark"
  95. }
  96. ListElement {
  97. title: qsTr("Quit")
  98. action: "quit"
  99. }
  100. }
  101. onActionSelected: (action) => actions[action]()
  102. }
  103. StackView {
  104. id: stackView
  105. initialItem: "Views/ProductsView.qml"
  106. anchors.fill: parent
  107. function openPage(page) {
  108. if (depth > 1) {
  109. pop()
  110. }
  111. push(page)
  112. mainMenu.close()
  113. }
  114. function showError(text) {
  115. ToolTip.show(text, 1000)
  116. }
  117. }
  118. Dialog {
  119. id: quitDialog
  120. property bool quitAccepted: false
  121. anchors.centerIn: parent
  122. parent: Overlay.overlay
  123. modal: true
  124. title: qsTr("Quit")
  125. standardButtons: Dialog.Yes | Dialog.No
  126. Label {
  127. text: qsTr("Realy quit the application?")
  128. }
  129. onAccepted: {
  130. quitAccepted = true
  131. Qt.quit()
  132. }
  133. }
  134. onClosing: (close) => {
  135. if (stackView.depth > 1) {
  136. close.accepted = false
  137. stackView.pop()
  138. return
  139. }
  140. if (!quitDialog.quitAccepted) {
  141. close.accepted = false
  142. quitDialog.open()
  143. }
  144. }
  145. }