Debian Codegraph @

src/qml/CustomPickers/1.0/FiveMinutesModel.qml

raw
1 /*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19
20 PickerModelBase {
21 property int from
22 circular: count >= 12
23
24 function reset() {
25 resetting = true;
26
27 clear();
28 from = minimum.getMinutes();
29 var distance = (!maximum.isValid() || (minimum.daysTo(maximum) > 1) || (minimum.minutesTo(maximum) >= 60)) ? 60 : minimum.minutesTo(maximum);
30 for (var i = 0; i < distance; i+=5) {
31 append({"minute": (from + i) % 60});
32 }
33
34 resetting = false;
35 }
36
37 function resetLimits(label, margin) {
38 label.text = "99";
39 narrowFormatLimit = shortFormatLimit = longFormatLimit = label.paintedWidth + 2 * margin;
40 }
41
42 function indexOf() {
43 var index = (date.getMinutes() / 5 - from);
44 if (index >= count) {
45 index = -1;
46 }
47
48 return index;
49 }
50
51 function dateFromIndex(index) {
52 if (index < 0 || index >= count) {
53 return date;
54 }
55 var newDate = new Date(date);
56 newDate.setMinutes(index * 5+ from);
57 return newDate;
58 }
59
60 function text(value) {
61 return (value !== undefined) ? ("00" + value).slice(-2) : "";
62 }
63 }