Files
nooLight/resources/qml/main.qml

112 lines
2.2 KiB
QML

import QtQuick 2.9
import QtQuick.Controls 2.2
import Qt.labs.settings 1.0
import ru.ded.components 1.0
ApplicationWindow {
id: window
visible: true
width: 640
height: 480
title: qsTr("Stack")
Settings {
id: settings
property string serviceUrl: ""
}
LightsModel {
id: lightsModel
serviceUrl: settings.serviceUrl
onError: (text) => stackView.showError(text)
}
header: ToolBar {
contentHeight: 36
MenuBackButton {
id: menuButton
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
anchors.leftMargin: 8
state: stackView.depth > 1 ? "back" : "menu"
onClicked: {
mainMenu.open()
}
onBack: {
stackView.pop()
}
}
Label {
text: stackView.currentItem.title
anchors.centerIn: parent
}
}
MainMenu {
id: mainMenu
readonly property var actions: {
"service": () => { stackView.openPage("ServiceForm.qml") },
"settings": () => { stackView.openPage("SettingsForm.qml") },
"quit": () => { Qt.quit() }
}
logo: "/images/lamp.png"
appName: qsTr("nooLight v1.0")
model: ListModel {
ListElement {
title: qsTr("Service")
action: "service"
}
ListElement {
title: qsTr("Settings")
action: "settings"
}
ListElement {
title: qsTr("Quit")
action: "quit"
}
}
onActionSelected: (action) => actions[action]()
}
StackView {
id: stackView
initialItem: "HomeForm.qml"
anchors.fill: parent
function openPage(page) {
if (depth > 1) {
pop()
}
push(page)
mainMenu.close()
}
function showError(text) {
ToolTip.show(text, 1000)
}
}
onClosing: {
if (stackView.depth > 1) {
close.accepted = false
stackView.pop()
}
}
}