Kaynağa Gözat

MainMenu component was added

Denis V. Dedkov 2 yıl önce
ebeveyn
işleme
b0646ff112
4 değiştirilmiş dosya ile 80 ekleme ve 35 silme
  1. 11 3
      beerlog_ru_RU.ts
  2. 49 0
      qml/Components/MainMenu.qml
  3. 19 32
      qml/main.qml
  4. 1 0
      qml/qml.qrc

+ 11 - 3
beerlog_ru_RU.ts

@@ -1,6 +1,14 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!DOCTYPE TS>
 <TS version="2.1" language="ru_RU">
+<context>
+    <name>MainMenu</name>
+    <message>
+        <location filename="qml/Components/MainMenu.qml" line="34"/>
+        <source>BeerLog v0.1</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
 <context>
     <name>main</name>
     <message>
@@ -9,18 +17,18 @@
         <translation></translation>
     </message>
     <message>
-        <location filename="qml/main.qml" line="77"/>
+        <location filename="qml/main.qml" line="66"/>
         <source>BeerLog v0.1</source>
         <oldsource>BeerLog v1.0.0</oldsource>
         <translation></translation>
     </message>
     <message>
-        <location filename="qml/main.qml" line="82"/>
+        <location filename="qml/main.qml" line="70"/>
         <source>Settings</source>
         <translation>Настройки</translation>
     </message>
     <message>
-        <location filename="qml/main.qml" line="88"/>
+        <location filename="qml/main.qml" line="74"/>
         <source>Quit</source>
         <translation>Выход</translation>
     </message>

+ 49 - 0
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)
+            }
+        }
+    }
+}

+ 19 - 32
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
-
-            Row {
-                width: parent.width
-                height: 100
-
-                Image {
-                    anchors.top: parent.top
-                    anchors.bottom: parent.bottom
-                    anchors.margins: 10
-                    source: "logo.png"
-                }
+        logo: "qrc:/logo.png"
+        appName: qsTr("BeerLog v0.1")
 
-                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]()
     }
 }

+ 1 - 0
qml/qml.qrc

@@ -5,5 +5,6 @@
         <file>qtquickcontrols2.conf</file>
         <file>logo.png</file>
         <file>beerlog_ru_RU.qm</file>
+        <file>Components/MainMenu.qml</file>
     </qresource>
 </RCC>