summaryrefslogtreecommitdiff
path: root/rockwork/HealthSettingsDialog.qml
blob: 94e5d22e0e5a7c9dce86300a10a67cf9b3576e59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import QtQuick 2.4
import QtQuick.Layouts 1.1
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
import Ubuntu.Components.ListItems 1.3

Dialog {
    id: root
    title: i18n.tr("Health settings")

    property var healthParams: null

    signal accepted();

    RowLayout {
        Label {
            text: i18n.tr("Health app enabled")
            Layout.fillWidth: true
        }
        Switch {
            id: enabledSwitch
            checked: healthParams["enabled"]
        }
    }

    ItemSelector {
        id: genderSelector
        model: [i18n.tr("Female"), i18n.tr("Male")]
        selectedIndex: root.healthParams["gender"] === "female" ? 0 : 1
    }

    RowLayout {
        Label {
            text: i18n.tr("Age")
            Layout.fillWidth: true
        }
        TextField {
            id: ageField
            inputMethodHints: Qt.ImhDigitsOnly
            text: healthParams["age"]
            Layout.preferredWidth: units.gu(10)
        }
    }

    RowLayout {
        Label {
            text: i18n.tr("Height (cm)")
            Layout.fillWidth: true
        }
        TextField {
            id: heightField
            inputMethodHints: Qt.ImhDigitsOnly
            text: healthParams["height"]
            Layout.preferredWidth: units.gu(10)
        }
    }

    RowLayout {
        Label {
            text: i18n.tr("Weight")
            Layout.fillWidth: true
        }
        TextField {
            id: weightField
            inputMethodHints: Qt.ImhDigitsOnly
            text: healthParams["weight"]
            Layout.preferredWidth: units.gu(10)
        }
    }

    RowLayout {
        Label {
            text: i18n.tr("I want to be more active")
            Layout.fillWidth: true
        }
        Switch {
            id: moreActiveSwitch
            checked: healthParams["moreActive"]
        }
    }

    RowLayout {
        Label {
            text: i18n.tr("I want to sleep more")
            Layout.fillWidth: true
        }
        Switch {
            id: sleepMoreSwitch
            checked: healthParams["sleepMore"]
        }
    }


    Button {
        text: i18n.tr("OK")
        color: UbuntuColors.green
        onClicked: {
            root.healthParams["enabled"] = enabledSwitch.checked;
            root.healthParams["gender"] = genderSelector.selectedIndex == 0 ? "female" : "male"
            root.healthParams["age"] = ageField.text;
            root.healthParams["height"] = heightField.text;
            root.healthParams["weight"] = weightField.text;
            root.healthParams["moreActive"] = moreActiveSwitch.checked;
            root.healthParams["sleepMore"] = sleepMoreSwitch.checked;
            root.accepted();
            PopupUtils.close(root);
        }
    }
    Button {
        text: i18n.tr("Cancel")
        color: UbuntuColors.red
        onClicked: PopupUtils.close(root)
    }
}