166 lines
3.6 KiB
QML
166 lines
3.6 KiB
QML
import QtQuick 2.15
|
|
import QtQuick.Window 2.15
|
|
import QtQuick.Controls 2.15
|
|
import QtQuick.Layouts 1.15
|
|
import QtWebSockets
|
|
|
|
import ru.ded.beerlog 1.0
|
|
import Components 1.0
|
|
|
|
ApplicationWindow {
|
|
width: 640
|
|
height: 480
|
|
visible: true
|
|
title: qsTr("Beer Log")
|
|
|
|
header: ToolBar {
|
|
RowLayout {
|
|
anchors.fill: parent
|
|
|
|
MenuBackButton {
|
|
state: stackView.depth > 1 ? "back" : "menu"
|
|
onClicked: mainMenu.open()
|
|
onBack: stackView.pop()
|
|
}
|
|
|
|
Label {
|
|
text: stackView.currentItem.title || usersModel.selectedUserName
|
|
Layout.fillWidth: true
|
|
Layout.minimumWidth: 100
|
|
horizontalAlignment: Qt.AlignCenter
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
enabled: stackView.depth === 1
|
|
onClicked: usersMenu.open()
|
|
}
|
|
}
|
|
}
|
|
|
|
Menu {
|
|
id: usersMenu
|
|
|
|
UsersViewModel {
|
|
id: usersModel
|
|
}
|
|
|
|
Repeater {
|
|
model: usersModel.users
|
|
|
|
MenuItem {
|
|
text: modelData.name
|
|
|
|
onClicked: {
|
|
usersModel.selectedUser = modelData.id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Menu {
|
|
id: storesMenu
|
|
|
|
StoresViewModel {
|
|
id: storesModel
|
|
}
|
|
|
|
Repeater {
|
|
model: storesModel.stores
|
|
|
|
MenuItem {
|
|
text: modelData.name
|
|
|
|
onClicked: {
|
|
storesModel.selectedStore = modelData.id
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
MainMenu {
|
|
id: mainMenu
|
|
|
|
readonly property var actions: {
|
|
"orders": () => { stackView.openPage("Views/OrdersView.qml") },
|
|
"settings": () => { stackView.openPage("Views/SettingsView.qml") },
|
|
"quit": () => { Qt.quit() }
|
|
}
|
|
|
|
logo: "qrc:/logo.png"
|
|
appName: qsTr("BeerLog v0.1")
|
|
connected: beerService.connected
|
|
|
|
model: ListModel {
|
|
ListElement {
|
|
title: qsTr("Orders")
|
|
action: "orders"
|
|
}
|
|
ListElement {
|
|
title: qsTr("Settings")
|
|
action: "settings"
|
|
}
|
|
ListElement {
|
|
title: qsTr("Quit")
|
|
action: "quit"
|
|
}
|
|
}
|
|
|
|
onActionSelected: (action) => actions[action]()
|
|
}
|
|
|
|
StackView {
|
|
id: stackView
|
|
initialItem: "Views/ProductsView.qml"
|
|
anchors.fill: parent
|
|
|
|
function openPage(page) {
|
|
if (depth > 1) {
|
|
pop()
|
|
}
|
|
|
|
push(page)
|
|
mainMenu.close()
|
|
}
|
|
|
|
function showError(text) {
|
|
ToolTip.show(text, 1000)
|
|
}
|
|
}
|
|
|
|
Dialog {
|
|
id: quitDialog
|
|
|
|
property bool quitAccepted: false
|
|
|
|
anchors.centerIn: parent
|
|
parent: Overlay.overlay
|
|
|
|
modal: true
|
|
title: qsTr("Quit")
|
|
standardButtons: Dialog.Yes | Dialog.No
|
|
|
|
Label {
|
|
text: qsTr("Realy quit the application?")
|
|
}
|
|
|
|
onAccepted: {
|
|
quitAccepted = true
|
|
Qt.quit()
|
|
}
|
|
}
|
|
|
|
onClosing: (close) => {
|
|
if (stackView.depth > 1) {
|
|
close.accepted = false
|
|
stackView.pop()
|
|
return
|
|
}
|
|
|
|
if (!quitDialog.quitAccepted) {
|
|
close.accepted = false
|
|
quitDialog.open()
|
|
}
|
|
}
|
|
}
|