~popey/ubuntu-clock-app/fix-1288885

« back to all changes in this revision

Viewing changes to alarm/AlarmList.qml

  • Committer: Tarmac
  • Author(s): Nekhelesh Ramananthan
  • Date: 2014-02-19 22:26:29 UTC
  • mfrom: (341.1.28 converge-clock-tab)
  • Revision ID: tarmac-20140219222629-survzj72fczfibov
Implement tablet designs of the clock tab. Fixes: https://bugs.launchpad.net/bugs/1174575.

Approved by Ubuntu Phone Apps Jenkins Bot, David Planella.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
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 General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Nekhelesh Ramananthan <krnekhelesh@gmail.com>
 
17
 */
 
18
 
 
19
import QtQuick 2.0
 
20
import Ubuntu.Components 0.1
 
21
import Ubuntu.Components.ListItems 0.1 as ListItem
 
22
import "../common/ClockUtils.js" as Utils
 
23
 
 
24
Column {
 
25
    id: listAlarm
 
26
 
 
27
    // Property to determine the size of the alarms listview height
 
28
    property int maxItemsVisible
 
29
 
 
30
    // Property to store the model of the saved alarm list
 
31
    property alias model: listSavedAlarm.model
 
32
 
 
33
    // Property to help with the dynamic positioning of the alarm list
 
34
    property alias headerHeight: savedAlarmHeader.height
 
35
    property alias dividerHeight: divider.height
 
36
 
 
37
    visible: listSavedAlarm.count !== 0
 
38
 
 
39
    ListItem.ThinDivider { id: divider }
 
40
 
 
41
    ListItem.Header {
 
42
        id: savedAlarmHeader
 
43
        Label {
 
44
            text: i18n.tr("Alarms")
 
45
            anchors { verticalCenter: parent.verticalCenter; left: parent.left; leftMargin: units.gu(2) }
 
46
            color: Theme.palette.normal.baseText
 
47
            fontSize: "medium"
 
48
        }
 
49
    }
 
50
 
 
51
    ListView {
 
52
        id: listSavedAlarm
 
53
        objectName: "listSavedAlarm"
 
54
        
 
55
        clip: true
 
56
        anchors { left: parent.left; right: parent.right }
 
57
        height: listAlarm.maxItemsVisible * units.gu(6)
 
58
        currentIndex: -1
 
59
        
 
60
        delegate: ListItem.Base {
 
61
            objectName: "alarm" + index
 
62
            Label {
 
63
                id: alarmTime
 
64
                objectName: "listAlarmTime" + index
 
65
                fontSize: "large";
 
66
                text: Utils.convertTime(date.getHours(), date.getMinutes(), 0, appSetting.contents.timeFormat)
 
67
                anchors { verticalCenter: parent.verticalCenter; right: alarmStatus.left; rightMargin: units.gu(2) }
 
68
                color: Theme.palette.normal.baseText
 
69
            }
 
70
            
 
71
            Label {
 
72
                id: alarmLabel
 
73
                objectName: "listAlarmLabel" + index
 
74
                fontSize: "large";
 
75
                text: message
 
76
                elide: Text.ElideRight
 
77
                anchors {
 
78
                    left: parent.left;
 
79
                    right: alarmTime.left
 
80
                    rightMargin: units.gu(2)
 
81
                    leftMargin: units.gu(1);
 
82
                    verticalCenter: alarmTime.top;
 
83
                    verticalCenterOffset: units.gu(0.4)
 
84
                }
 
85
                color: Theme.palette.normal.baseText
 
86
            }
 
87
            
 
88
            Label {
 
89
                id: alarmSubtitle
 
90
                objectName: "listAlarmSubtitle" + index
 
91
                fontSize: "small";
 
92
                text: format_day_string(daysOfWeek, type)
 
93
                anchors { left: alarmLabel.left; top: alarmLabel.bottom }
 
94
                color: Theme.palette.normal.backgroundText
 
95
            }
 
96
            
 
97
            Switch {
 
98
                id: alarmStatus
 
99
                objectName: "listAlarmStatus" + index
 
100
                checked: model.enabled
 
101
                anchors { right: parent.right; verticalCenter: alarmTime.verticalCenter }
 
102
                onClicked: {
 
103
                    var alarm = alarmModel.get(index);
 
104
                    alarm.enabled = checked
 
105
                    alarm.save();
 
106
                }
 
107
            }
 
108
            
 
109
            selected: listSavedAlarm.currentIndex == index
 
110
            removable: true
 
111
            confirmRemoval: true
 
112
            
 
113
            onItemRemoved: {
 
114
                var alarm = alarmModel.get(index)
 
115
                alarm.cancel()
 
116
            }
 
117
            
 
118
            onClicked: pagestack.push(Qt.resolvedUrl("AddAlarmPage.qml"), {"isNewAlarm": false, "alarmIndex": index})
 
119
        }
 
120
    }
 
121
}