~aurora-l/iquit/main

« back to all changes in this revision

Viewing changes to qml/Additions.qml

  • Committer: Michael Thomson
  • Date: 2020-02-22 17:14:49 UTC
  • Revision ID: aurora@icscotland.net-20200222171449-ovpkokxlymar89je
Internal changes. QML split into different files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * I Quit! is free software; you can redistribute it and/or modify
 
3
 * it under the terms of the GNU General Public License as published by
 
4
 * the Free Software Foundation; version 3.
 
5
 *
 
6
 * I Quit! is distributed in the hope that it will be useful,
 
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
9
 * GNU General Public License for more details.
 
10
 *
 
11
 * You should have received a copy of the GNU General Public License
 
12
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
13
 */
 
14
 
 
15
import QtQuick 2.4
 
16
import QtQuick.Layouts 1.1
 
17
import Ubuntu.Components 1.3
 
18
import Ubuntu.Components.Popups 1.0
 
19
import Ubuntu.Components.ListItems 1.3
 
20
import Ubuntu.Components.Pickers 1.0
 
21
 
 
22
//******************************************************ADDITIONS PAGE**************************************
 
23
Page {
 
24
    id: addPage
 
25
    visible: false
 
26
    header: PageHeader {
 
27
    title: i18n.tr("ADDITIONS")
 
28
    }
 
29
    Flickable {
 
30
        id: page_flickable6
 
31
        contentHeight: parent.height
 
32
        //contentHeight: colG1.height
 
33
        anchors {
 
34
        left: parent.left
 
35
        right: parent.right
 
36
        bottom: parent.bottom
 
37
        top: addPage.header.bottom
 
38
        }
 
39
        clip: false
 
40
        Image {
 
41
            fillMode: Image.Stretch
 
42
           anchors.fill: parent
 
43
           source: "..//assets/oops.png"
 
44
           opacity: 0.2
 
45
           }
 
46
    Column {
 
47
        id: colG1
 
48
        spacing: units.gu(2)
 
49
        anchors {
 
50
            margins: units.gu(2)
 
51
            fill: parent
 
52
        }
 
53
        Label {
 
54
            width: parent.width
 
55
            font.pixelSize: FontUtils.sizeToPixels("medium")
 
56
            text: i18n.tr("You can record any cravings you have succumbed to here. \n THIS WILL RESET THE FIRST FOUR COUNTERS ON THE PROGRESS PAGE")
 
57
            wrapMode: Text.WordWrap
 
58
        }
 
59
        Label {
 
60
            width: parent.width
 
61
            font.pixelSize: FontUtils.sizeToPixels("medium")
 
62
            text: if (additions.text == 0) {
 
63
            i18n.tr("Since quitting on ") + Qt.formatDateTime(d1,"ddd dd MMMM yyyy") + i18n.tr(", you have succeeded in your goal to completely quit. Congratulations and keep up the good work!")
 
64
                  } else {
 
65
                i18n.tr("Since quitting on ") + Qt.formatDateTime(d1,"ddd dd MMMM yyyy") + i18n.tr(", you have smoked ") + i18n.tr("%1 cigarette", "%1 cigarettes", additions.text).arg(additions.text) + i18n.tr(". The last one was on ")+ Qt.formatDateTime(d8,"ddd dd MMMM yyyy")
 
66
                  }
 
67
            wrapMode: Text.WordWrap
 
68
        }
 
69
        Text {
 
70
            id: additions
 
71
            visible: false
 
72
            text: (d7).toString()
 
73
        }
 
74
 
 
75
        TextField {
 
76
            id: succumbed
 
77
            height: units.gu(5)
 
78
            width: parent.width
 
79
            placeholderText: i18n.tr("Enter Cigarettes You Shouldn't Have Smoked")
 
80
            inputMethodHints: Qt.ImhFormattedNumbersOnly
 
81
            validator: DoubleValidator {notation: DoubleValidator.StandardNotation}
 
82
            onTextChanged: {
 
83
                if (activeFocus) {
 
84
                addText.text = (Number(additions.text) + Number(succumbed.text))
 
85
                }
 
86
            }
 
87
        }
 
88
 
 
89
        //New Section
 
90
    Row {
 
91
                id:rowG1
 
92
        width: parent.width
 
93
        spacing: units.gu(1)
 
94
        Component {
 
95
                        id: dialog
 
96
            Dialog {
 
97
                id: dialogue
 
98
                title: "Information"
 
99
                width: parent.width
 
100
                anchors.fill: parent
 
101
                text: i18n.tr("Enter the date, followed by the time")
 
102
                Button {
 
103
                                        width: colG1.width / 2 - units.gu(1)
 
104
                                        Component {
 
105
                                                id: popoverComponent3
 
106
                                                Popover {
 
107
                                                        id: popover3
 
108
                                                        DatePicker {
 
109
                                                                id: datePicker3
 
110
                                                                minimum: "2010-01-01T00:00:00"
 
111
                                                                onDateChanged: {
 
112
                                                                        pickerDate3.text = (Qt.formatDateTime(datePicker3.date, 'yyyy-MM-dd'));
 
113
                                    }
 
114
                                }
 
115
                            }
 
116
                        }
 
117
                                Button {
 
118
                                        id: popoverButton3
 
119
                                        width: parent.width
 
120
                                        color: UbuntuColors.orange
 
121
                                        anchors.centerIn: parent
 
122
                                        text: i18n.tr("Date Picker")
 
123
                                        onClicked: PopupUtils.open(popoverComponent3, popoverButton3)
 
124
                                        }
 
125
                                }
 
126
                                Button {
 
127
                                        width: colG1.width / 2 - units.gu(1)
 
128
                                        Component {
 
129
                                                id: popoverComponent4
 
130
                                                Popover {
 
131
                                                        id: popover4
 
132
                                                        width: parent.width
 
133
                                                        DatePicker {
 
134
                                                                id: datePicker4
 
135
                                                                mode: "Hours|Minutes"
 
136
                                                                onDateChanged: {
 
137
                                                                        pickerTime3.text = (Qt.formatDateTime(datePicker4.date, 'hh:mm:ss'));
 
138
                                    }
 
139
                                }
 
140
                            }
 
141
                        }
 
142
                                Button {
 
143
                                        id: popoverButton4
 
144
                                        width: parent.width
 
145
                                        color: UbuntuColors.orange
 
146
                                        anchors.centerIn: parent
 
147
                                        text: i18n.tr("Time Picker")
 
148
                                        onClicked: PopupUtils.open(popoverComponent4, popoverButton4)
 
149
                                        }
 
150
                                }
 
151
                                Button {
 
152
                                        text: "OK"
 
153
                                        color:UbuntuColors.green
 
154
                                        onClicked: PopupUtils.close(dialogue)
 
155
                                        }
 
156
                }
 
157
            }
 
158
                                Button {
 
159
                                        id: urlButton
 
160
                                        width: parent.width
 
161
                                        color:UbuntuColors.red
 
162
                                        text: i18n.tr("Click to enter date / time manually")
 
163
                                        onClicked: PopupUtils.open(dialog)
 
164
                                }
 
165
                        }
 
166
Row {
 
167
    id: rowG11
 
168
    spacing: units.gu(1)
 
169
    Text {
 
170
        id: pickerDate3
 
171
        visible: false
 
172
        text: ""
 
173
    }
 
174
    Text {
 
175
        id: pickerTime3
 
176
        visible: false
 
177
        text: ""
 
178
    }
 
179
    Text {
 
180
        id: pickerDateTime3
 
181
        visible: false
 
182
        text: if (pickerDate3.text == "")  {
 
183
                        new Date ()
 
184
                        } else {
 
185
                        pickerDate3.text + "T" + pickerTime3.text
 
186
                        }
 
187
                }
 
188
        }
 
189
// End of New Section
 
190
 
 
191
        Text {
 
192
        id: addText
 
193
    text: ""
 
194
    visible: false
 
195
        }
 
196
        Button {
 
197
        color: UbuntuColors.green
 
198
    width: parent.width
 
199
    text: i18n.tr("Save")
 
200
    onClicked: if (addText.text == "") {
 
201
    saveUnits7()
 
202
                function saveUnits7() {
 
203
                appdata7.contents = {
 
204
                "additions":""
 
205
                }
 
206
                appdata8.contents = {
 
207
                "lastdate":""
 
208
                }
 
209
        }
 
210
        } else {
 
211
        saveUnits8()
 
212
                function saveUnits8() {
 
213
                appdata7.contents = {
 
214
                "additions":addText.text
 
215
                }
 
216
                appdata8.contents = {
 
217
                "lastdate":pickerDateTime3.text
 
218
                        }
 
219
                }
 
220
        }
 
221
}
 
222
        Component {
 
223
                id: dialog2
 
224
                Dialog {
 
225
                        id: dialogue2
 
226
                        title: "Confirm Reset"
 
227
                        width: parent.width
 
228
                        anchors.fill: parent
 
229
                        text: i18n.tr("Are you certain that you wish to reset ALL counters? This will set your start date to now, and clear any 'additional' cigarettes you may have smoked")
 
230
            Button {
 
231
                                text: i18n.tr("Yes")
 
232
                                color: UbuntuColors.green
 
233
                                onClicked: {
 
234
                                saveUnits2()
 
235
                                        function saveUnits2() {
 
236
                                        appdata1.contents = {
 
237
                                        "stopdate":pickerDateTime3.text
 
238
                                        }
 
239
                                        appdata7.contents = {
 
240
                                        "additions":""
 
241
                                        }
 
242
                                        appdata8.contents = {
 
243
                                        "lastdate":""
 
244
                                        }
 
245
                                        PopupUtils.close(dialogue2)
 
246
                                        }
 
247
                                        onClicked: page0.pageStack.removePages(Qt.resolvedUrl("Additions.qml"), page0)
 
248
                                        }
 
249
                                }
 
250
                        Button {
 
251
                                text: i18n.tr("No")
 
252
                                color: UbuntuColors.red
 
253
                                onClicked: PopupUtils.close(dialogue2)
 
254
                                }
 
255
                        }
 
256
                }
 
257
                        Button {
 
258
                id: resetButton
 
259
                width: parent.width
 
260
                color: UbuntuColors.red
 
261
                text: i18n.tr("Click to reset all counters")
 
262
                onClicked: PopupUtils.open(dialog2)
 
263
                                }           
 
264
                        Label {
 
265
                                width: parent.width
 
266
                                font.pixelSize: FontUtils.sizeToPixels("medium")
 
267
                                text: i18n.tr("If you are finding it difficult, why not try some of the online resources listed in the ") + i18n.tr("<a href='Advice.qml'>Advice Page?</a>") + i18n.tr(" Alternatively, sign up to one of the no-smoking groups that are being run.")
 
268
                                wrapMode: Text.WordWrap
 
269
                                onLinkActivated: page0.pageStack.addPageToNextColumn (page0, Qt.resolvedUrl("Advice.qml"))
 
270
                        }
 
271
                }
 
272
        }
 
273
}
 
274
//******************************************************END OF ADDITIONS PAGE*******************************