~pkunal-parmar/ubuntu-calendar-app/Minor-Performance

« back to all changes in this revision

Viewing changes to AgendaView.qml

  • Committer: Kunal Parmar
  • Date: 2013-06-01 11:53:11 UTC
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: pkunal.parmar@gmail.com-20130601115311-hfou3qrtoxjs92th
Typo flickble->flickable fixed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-2014 Canonical Ltd
3
 
 *
4
 
 * This file is part of Ubuntu Calendar App
5
 
 *
6
 
 * Ubuntu Calendar App is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License version 3 as
8
 
 * published by the Free Software Foundation.
9
 
 *
10
 
 * Ubuntu Calendar App is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
import QtQuick 2.3
20
 
import QtOrganizer 5.0
21
 
import Ubuntu.Components 1.1
22
 
import "dateExt.js" as DateExt
23
 
 
24
 
Page{
25
 
    id: root
26
 
    objectName: "AgendaView"
27
 
 
28
 
    property var currentDay: new Date()
29
 
 
30
 
    signal dateSelected(var date);
31
 
 
32
 
    Keys.forwardTo: [eventList]
33
 
 
34
 
    function goToBeginning() {
35
 
        eventList.positionViewAtBeginning();
36
 
    }
37
 
 
38
 
    function hasEnabledCalendars() {
39
 
        var enabled_calendars = eventListModel.getCollections().filter( function( item ) {
40
 
            return item.extendedMetaData( "collection-selected" );
41
 
        } );
42
 
 
43
 
        return !!enabled_calendars.length;
44
 
    }
45
 
 
46
 
    Action {
47
 
        id: calendarTodayAction
48
 
        objectName:"todaybutton"
49
 
        iconName: "calendar-today"
50
 
        text: i18n.tr("Today")
51
 
        onTriggered: {
52
 
            currentDay = new Date()
53
 
            goToBeginning()
54
 
        }
55
 
    }
56
 
 
57
 
    head.actions: [
58
 
        calendarTodayAction,
59
 
        commonHeaderActions.newEventAction,
60
 
        commonHeaderActions.showCalendarAction,
61
 
        commonHeaderActions.reloadAction
62
 
    ]
63
 
 
64
 
    EventListModel {
65
 
        id: eventListModel
66
 
        startPeriod: currentDay.midnight();
67
 
        endPeriod: currentDay.addDays(30).endOfDay()
68
 
        filter: eventModel.filter
69
 
 
70
 
        sortOrders: [
71
 
            SortOrder{
72
 
                blankPolicy: SortOrder.BlanksFirst
73
 
                detail: Detail.EventTime
74
 
                field: EventTime.FieldStartDateTime
75
 
                direction: Qt.AscendingOrder
76
 
            }
77
 
        ]
78
 
    }
79
 
 
80
 
    ActivityIndicator {
81
 
        visible: running
82
 
        running: eventListModel.isLoading
83
 
        anchors.centerIn: parent
84
 
        z:2
85
 
    }
86
 
 
87
 
    Label {
88
 
        id: noEventsOrCalendarsLabel
89
 
        text: {
90
 
            var default_title = i18n.tr( "No upcoming events" );
91
 
 
92
 
            if ( !root.hasEnabledCalendars() ) {
93
 
                default_title = i18n.tr("You have no calendars enabled")
94
 
            }
95
 
 
96
 
            return default_title;
97
 
        }
98
 
        visible: !root.hasEnabledCalendars() || !eventListModel.itemCount
99
 
        anchors.centerIn: parent
100
 
    }
101
 
 
102
 
    Button {
103
 
        text: i18n.tr( "Enable calendars" )
104
 
        visible: !root.hasEnabledCalendars()
105
 
        anchors.top: noEventsOrCalendarsLabel.bottom
106
 
        anchors.horizontalCenter: noEventsOrCalendarsLabel.horizontalCenter
107
 
        anchors.topMargin: units.gu( 1.5 )
108
 
        color: UbuntuColors.orange
109
 
 
110
 
        onClicked: {
111
 
            pageStack.push(Qt.resolvedUrl("CalendarChoicePopup.qml"),{"model":eventModel});
112
 
            pageStack.currentPage.collectionUpdated.connect(eventModel.delayedApplyFilter);
113
 
        }
114
 
    }
115
 
 
116
 
    ListView{
117
 
        id: eventList
118
 
        model: eventListModel
119
 
        anchors.fill: parent
120
 
        visible: eventListModel.itemCount > 0
121
 
 
122
 
        delegate: listDelegate
123
 
    }
124
 
 
125
 
    Scrollbar{
126
 
        flickableItem: eventList
127
 
        align: Qt.AlignTrailing
128
 
    }
129
 
 
130
 
    Component{
131
 
        id: listDelegate
132
 
 
133
 
        Item {
134
 
            id: root
135
 
            property var event: eventListModel.items[index];
136
 
 
137
 
            width: parent.width
138
 
            height: container.height
139
 
 
140
 
            onEventChanged: {
141
 
                setDetails();
142
 
            }
143
 
 
144
 
            function setDetails() {
145
 
                if(event === null || event === undefined) {
146
 
                    return;
147
 
                }
148
 
 
149
 
                headerContainer.visible = false;
150
 
                if( index == 0 ) {
151
 
                    headerContainer.visible = true;
152
 
                } else {
153
 
                    var prevEvent = eventListModel.items[index-1];
154
 
                    if( prevEvent.startDateTime.midnight() < event.startDateTime.midnight()) {
155
 
                        headerContainer.visible = true;
156
 
                    }
157
 
                }
158
 
 
159
 
                var date = event.startDateTime.toLocaleDateString()
160
 
                var startTime = event.startDateTime.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
161
 
                var endTime = event.endDateTime.toLocaleTimeString(Qt.locale(), Locale.ShortFormat)
162
 
 
163
 
                // TRANSLATORS: the first argument (%1) refers to a start time for an event,
164
 
                // while the second one (%2) refers to the end time
165
 
                var timeString = i18n.tr("%1 - %2").arg(startTime).arg(endTime)
166
 
 
167
 
                header.text = date
168
 
                timeLabel.text = timeString
169
 
                header.color = event.startDateTime.toLocaleDateString() === new Date().toLocaleDateString() ? UbuntuColors.orange : UbuntuColors.darkGrey
170
 
                detailsContainer.color = eventListModel.collection(event.collectionId).color
171
 
 
172
 
                if( event.displayLabel) {
173
 
                    titleLabel.text = event.displayLabel;
174
 
                }
175
 
            }
176
 
 
177
 
            Column {
178
 
                id: container
179
 
 
180
 
                width: parent.width
181
 
                height: detailsContainer.height + headerContainer.height +
182
 
                        (headerContainer.visible ? units.gu(2) : units.gu(0.5))
183
 
 
184
 
                spacing: headerContainer.visible ? units.gu(1) : 0
185
 
 
186
 
                anchors.top: parent.top
187
 
                anchors.topMargin: headerContainer.visible ? units.gu(1.5) : units.gu(1)
188
 
 
189
 
                DayHeaderBackground{
190
 
                    id: headerContainer
191
 
 
192
 
                    height: visible ? header.height + units.gu(1) : 0
193
 
                    width: parent.width
194
 
 
195
 
                    Label{
196
 
                        id: header
197
 
 
198
 
                        fontSize: "small"
199
 
                        width: parent.width
200
 
                        elide: Text.ElideRight
201
 
 
202
 
                        anchors {
203
 
                            left: parent.left
204
 
                            leftMargin: units.gu(1)
205
 
                            verticalCenter: parent.verticalCenter
206
 
                        }
207
 
                    }
208
 
 
209
 
                    MouseArea{
210
 
                        anchors.fill: parent
211
 
                        onClicked: {
212
 
                            dateSelected(event.startDateTime);
213
 
                        }
214
 
                    }
215
 
                }
216
 
 
217
 
                UbuntuShape{
218
 
                    id: detailsContainer
219
 
 
220
 
                    anchors {
221
 
                        left: parent.left
222
 
                        right: parent.right
223
 
                        margins: units.gu(2)
224
 
                    }
225
 
 
226
 
                    height: detailsColumn.height + units.gu(1)
227
 
                    borderSource: "radius_ide.sci"
228
 
 
229
 
                    states: [
230
 
                        State {
231
 
                            name: "selected"
232
 
                            when: mouseArea.pressed
233
 
 
234
 
                            PropertyChanges {
235
 
                                target: detailsContainer
236
 
                                borderSource: "radius_pressed.sci"
237
 
                            }
238
 
                        }
239
 
                    ]
240
 
 
241
 
                    Column{
242
 
                        id: detailsColumn
243
 
 
244
 
                        anchors {
245
 
                            top: parent.top
246
 
                            left: parent.left
247
 
                            right: parent.right
248
 
                            margins: units.gu(0.5)
249
 
                        }
250
 
 
251
 
                        Label{
252
 
                            id: timeLabel
253
 
                            color:"White"
254
 
                            font.bold: true
255
 
                            fontSize: "small"
256
 
                            width: parent.width
257
 
                        }
258
 
 
259
 
                        Label{
260
 
                            id: titleLabel
261
 
 
262
 
                            color:"White"
263
 
                            fontSize: "small"
264
 
                            width: parent.width
265
 
                            maximumLineCount: 2
266
 
                            elide: Text.ElideRight
267
 
                            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
268
 
 
269
 
                            Behavior on color {
270
 
                                ColorAnimation {
271
 
                                    duration: 50
272
 
                                }
273
 
                            }
274
 
                        }
275
 
                    }
276
 
 
277
 
                    MouseArea{
278
 
                        id: mouseArea
279
 
                        anchors.fill: parent
280
 
                        onClicked: {
281
 
                            pageStack.push(Qt.resolvedUrl("EventDetails.qml"), {"event":event,"model":eventListModel});
282
 
                        }
283
 
                    }
284
 
                }
285
 
            }
286
 
        }
287
 
    }
288
 
}