소스 검색

Добавил форму настроек

Denis V. Dedkov 7 년 전
부모
커밋
34637319ba
3개의 변경된 파일58개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 1
      HomeForm.qml
  2. 49 3
      SettingsForm.qml
  3. 8 0
      main.qml

+ 1 - 1
HomeForm.qml

@@ -5,7 +5,7 @@ Page {
     title: qsTr("Home")
 
     Label {
-        text: qsTr("You are on the home page.")
+        text: qsTr("You are on the home page. " + settings.serviceUrl)
         anchors.centerIn: parent
     }
 }

+ 49 - 3
SettingsForm.qml

@@ -2,10 +2,56 @@ import QtQuick 2.0
 import QtQuick.Controls 2.2
 
 Page {
+    id: root
+
     title: qsTr("Settings")
 
-    Label {
-        text: qsTr("You are on Settings Page")
-        anchors.centerIn: parent
+    ListModel {
+        id: settingsModel
+
+        ListElement {
+            name: "serviceUrl"
+            title: qsTr("NooLite service URL:")
+            inputHint: Qt.ImhUrlCharactersOnly
+        }
+    }
+
+    ListView {
+        model: settingsModel
+
+        anchors.fill: parent
+        anchors.margins: 8
+
+        delegate: Item {
+            id: settingsItem
+
+            width: parent.width
+            height: childrenRect.height
+
+            Label {
+                id: titleLabel
+
+                anchors.left: settingsItem.left
+                anchors.verticalCenter: valueField.verticalCenter
+
+                text: model.title
+            }
+
+            TextField {
+                id: valueField
+
+                anchors.right: settingsItem.right
+                anchors.left: titleLabel.right
+                anchors.leftMargin: 8
+
+                inputMethodHints: model.inputHint
+
+                text: settings[model.name]
+
+                onTextChanged: {
+                    settings[model.name] = text
+                }
+            }
+        }
     }
 }

+ 8 - 0
main.qml

@@ -1,13 +1,21 @@
 import QtQuick 2.9
 import QtQuick.Controls 2.2
+import Qt.labs.settings 1.0
 
 ApplicationWindow {
     id: window
+
     visible: true
     width: 640
     height: 480
     title: qsTr("Stack")
 
+    Settings {
+        id: settings
+
+        property string serviceUrl: ""
+    }
+
     header: ToolBar {
         contentHeight: 36