Răsfoiți Sursa

Переход на использование модуля с компонентами

Denis V. Dedkov 1 an în urmă
părinte
comite
53659cea38
4 a modificat fișierele cu 36 adăugiri și 131 ștergeri
  1. 9 1
      CMakeLists.txt
  2. 0 79
      MenuBackButton.qml
  3. 27 50
      main.qml
  4. 0 1
      qml.qrc

+ 9 - 1
CMakeLists.txt

@@ -24,6 +24,14 @@ if (ANDROID)
         ${CMAKE_CURRENT_SOURCE_DIR}/android)
 endif()
 
+include(FetchContent)
+FetchContent_Declare(
+  components
+  GIT_REPOSITORY https://gogs.dended.keenetic.pro/ded/components.git
+  GIT_TAG master
+)
+
+FetchContent_MakeAvailable(components)
 
 # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
 # If you are developing for iOS or macOS you should consider setting an
@@ -37,7 +45,7 @@ set_target_properties(appnooLight PROPERTIES
 )
 
 target_link_libraries(appnooLight
-    PRIVATE Qt6::Quick
+    PRIVATE Qt6::Quick componentsplugin
 )
 
 include(GNUInstallDirs)

+ 0 - 79
MenuBackButton.qml

@@ -1,79 +0,0 @@
-import QtQuick 2.0
-
-Item {
-    id: root
-    signal clicked()
-    signal back()
-
-    SystemPalette {
-        id: palette
-    }
-
-    MouseArea {
-        id: ma
-
-        anchors.fill: parent
-        anchors.margins: -8
-    }
-
-    Rectangle {
-        id: bar1
-        x: 0
-        y: root.height / 6
-        width: root.height
-        height: root.height / 9
-        antialiasing: true
-
-        color: palette.button
-    }
-
-    Rectangle {
-        id: bar2
-        x: 0
-        y: root.height / 2 - height / 2
-        width: root.height
-        height: root.height / 9
-        antialiasing: true
-
-        color: palette.button
-    }
-
-    Rectangle {
-        id: bar3
-        x: 0
-        y: root.height / 2 + height * 2
-        width: root.height
-        height: root.height / 9
-        antialiasing: true
-
-        color: palette.button
-    }
-
-    property int animationDuration: 450
-
-    state: "menu"
-    states: [
-        State {
-            name: "menu"
-            PropertyChanges { target: ma; onClicked: root.clicked() }
-        },
-
-        State {
-            name: "back"
-            PropertyChanges { target: root; rotation: 180 }
-            PropertyChanges { target: bar1; rotation: 45; width: root.height / 3 * 2; x: root.height / 2; y: root.height / 4 }
-            PropertyChanges { target: bar2; width: root.height / 6 * 5 + 1; x: root.height / 9 }
-            PropertyChanges { target: bar3; rotation: -45; width: root.height / 3 * 2; x: root.height / 2; y: root.height / 3 * 2 }
-            PropertyChanges { target: ma; onClicked: root.back() }
-        }
-    ]
-
-    transitions: [
-        Transition {
-            RotationAnimation { target: root; direction: RotationAnimation.Clockwise; duration: animationDuration; easing.type: Easing.InOutQuad }
-            PropertyAnimation { target: bar1; properties: "rotation, width, x, y"; duration: animationDuration; easing.type: Easing.InOutQuad }
-            PropertyAnimation { target: bar2; properties: "rotation, width, x, y"; duration: animationDuration; easing.type: Easing.InOutQuad }
-            PropertyAnimation { target: bar3; properties: "rotation, width, x, y"; duration: animationDuration; easing.type: Easing.InOutQuad }
-        }
-    ]
-}

+ 27 - 50
main.qml

@@ -2,6 +2,8 @@ import QtQuick 2.9
 import QtQuick.Controls 2.2
 import Qt.labs.settings 1.0
 
+import ru.ded.components 1.0
+
 ApplicationWindow {
     id: window
 
@@ -34,13 +36,10 @@ ApplicationWindow {
             anchors.left: parent.left
             anchors.leftMargin: 8
 
-            width: 24
-            height: 24
-
             state: stackView.depth > 1 ? "back" : "menu"
 
             onClicked: {
-                drawer.open()
+                mainMenu.open()
             }
 
             onBack: {
@@ -54,56 +53,34 @@ ApplicationWindow {
         }
     }
 
-    Drawer {
-        id: drawer
-        width: window.width * 0.66
-        height: window.height
-
-        Column {
-            anchors.fill: parent
-
-            Row {
-                width: parent.width
-                height: 100
-
-                Image {
-                    anchors.top: parent.top
-                    anchors.bottom: parent.bottom
-                    anchors.margins: 10
-                    source: "lamp.png"
-                }
-
-                Label {
-                    anchors.verticalCenter: parent.verticalCenter
-                    font.pointSize: 20
-                    text: qsTr("nooLight v0.1")
-                }
-            }
+    MainMenu {
+        id: mainMenu
 
-            ItemDelegate {
-                text: qsTr("Service")
-                width: parent.width
-                onClicked: {
-                    stackView.openPage("ServiceForm.qml")
-                }
-            }
+        readonly property var actions: {
+            "service": () => { stackView.openPage("ServiceForm.qml") },
+            "settings": () => { stackView.openPage("SettingsForm.qml") },
+            "quit": () => { Qt.quit() }
+        }
 
-            ItemDelegate {
-                text: qsTr("Settings")
-                width: parent.width
-                onClicked: {
-                    stackView.openPage("SettingsForm.qml")
-                }
-            }
+        logo: "qrc:/lamp.png"
+        appName: qsTr("nooLight v1.0")
 
-            ItemDelegate {
-                text: qsTr("Quit")
-                width: parent.width
-                onClicked: {
-                    Qt.quit()
-                }
+        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 {
@@ -117,7 +94,7 @@ ApplicationWindow {
             }
 
             push(page)
-            drawer.close()
+            mainMenu.close()
         }
 
         function showError(text) {

+ 0 - 1
qml.qrc

@@ -4,7 +4,6 @@
         <file>qtquickcontrols2.conf</file>
         <file>HomeForm.qml</file>
         <file>SettingsForm.qml</file>
-        <file>MenuBackButton.qml</file>
         <file>SubtitledItemDelegate.qml</file>
         <file>LightsModel.qml</file>
         <file>LightGroup.qml</file>