From b0646ff112e885d50505bbcd3a30718bb0616f05 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Thu, 30 Mar 2023 11:01:39 +0200 Subject: [PATCH] MainMenu component was added --- beerlog_ru_RU.ts | 14 +++++++--- qml/Components/MainMenu.qml | 49 +++++++++++++++++++++++++++++++++++ qml/main.qml | 51 ++++++++++++++----------------------- qml/qml.qrc | 1 + 4 files changed, 80 insertions(+), 35 deletions(-) create mode 100644 qml/Components/MainMenu.qml diff --git a/beerlog_ru_RU.ts b/beerlog_ru_RU.ts index fa29e97..50e128e 100644 --- a/beerlog_ru_RU.ts +++ b/beerlog_ru_RU.ts @@ -1,6 +1,14 @@ + + MainMenu + + + BeerLog v0.1 + + + main @@ -9,18 +17,18 @@ - + BeerLog v0.1 BeerLog v1.0.0 - + Settings Настройки - + Quit Выход diff --git a/qml/Components/MainMenu.qml b/qml/Components/MainMenu.qml new file mode 100644 index 0000000..b962e26 --- /dev/null +++ b/qml/Components/MainMenu.qml @@ -0,0 +1,49 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Drawer { + property alias logo: logoImage.source + property alias appName: appNameLabel.text + property alias model: menuRepeater.model + + signal actionSelected(var action) + + width: parent.width * 0.66 + height: parent.height + + Column { + anchors.fill: parent + + Row { + width: parent.width + height: 100 + + Image { + id: logoImage + + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.margins: 10 + } + + Label { + id: appNameLabel + + anchors.verticalCenter: parent.verticalCenter + font.pointSize: 20 + text: qsTr("BeerLog v0.1") + } + } + + Repeater { + id: menuRepeater + + delegate: ItemDelegate { + width: parent.width + + text: model.title + onClicked: actionSelected(model.action) + } + } + } +} diff --git a/qml/main.qml b/qml/main.qml index 4add4b5..c650d47 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -18,7 +18,7 @@ ApplicationWindow { anchors.fill: parent MenuBackButton { state: "menu"//stackView.depth > 1 ? "back" : "menu" - onClicked: drawer.open() + onClicked: mainMenu.open() onBack: { state = "menu" } @@ -51,44 +51,31 @@ ApplicationWindow { } } - Drawer { - id: drawer + MainMenu { + id: mainMenu + + readonly property var actions: { + "settings": () => { stackView.openPage("SettingsForm.qml") }, + "quit": () => { Qt.quit() } + } width: parent.width * 0.66 height: parent.height - Column { - anchors.fill: parent + logo: "qrc:/logo.png" + appName: qsTr("BeerLog v0.1") - Row { - width: parent.width - height: 100 - - Image { - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.margins: 10 - source: "logo.png" - } - - Label { - anchors.verticalCenter: parent.verticalCenter - font.pointSize: 20 - text: qsTr("BeerLog v0.1") - } + model: ListModel { + ListElement { + title: qsTr("Settings") + action: "settings" } - - ItemDelegate { - text: qsTr("Settings") - width: parent.width - onClicked: stackView.openPage("SettingsForm.qml") - } - - ItemDelegate { - text: qsTr("Quit") - width: parent.width - onClicked: Qt.quit() + ListElement { + title: qsTr("Quit") + action: "quit" } } + + onActionSelected: (action) => actions[action]() } } diff --git a/qml/qml.qrc b/qml/qml.qrc index 40b775b..e3bd633 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -5,5 +5,6 @@ qtquickcontrols2.conf logo.png beerlog_ru_RU.qm + Components/MainMenu.qml