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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*
* Copyright (C) 2013-2014 Canonical Ltd
*
* This file is part of Ubuntu Calendar App
*
* Ubuntu Calendar App is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Ubuntu Calendar App is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.3
import Ubuntu.Components 1.1
import Ubuntu.Components.Popups 1.0
import "dateExt.js" as DateExt
import "ViewType.js" as ViewType
Row {
id: root
property var startDay: DateExt.today();
property int type: ViewType.ViewTypeWeek
property var allDayEvents;
property var model;
width: parent.width
height: units.gu(5)
function getAllDayEvents(startDate, endDate) {
var map = {};
var items = model.getItems(startDate,endDate);
for(var i = 0 ; i < items.length ; ++i) {
var event = items[(i)];
if( event && event.allDay ) {
for(var d = event.startDateTime; d <= event.endDateTime; d = d.addDays(1)) {
var key = Qt.formatDateTime(d, "dd-MMM-yyyy");
if( !(key in map)) {
map[key] = [];
}
map[key].push(event);
}
}
}
return map;
}
function createAllDayEvents() {
if(!startDay || startDay === undefined) {
return;
}
var sd = startDay.midnight();
var ed = sd.addDays( (type == ViewType.ViewTypeDay) ? 1 : 7);
allDayEvents = getAllDayEvents(sd,ed);
}
Repeater{
model: type == ViewType.ViewTypeWeek ? 7 : 1
delegate: Item {
id: allDayButton
property var events;
height: units.gu(5)
width: parent.width / (type == ViewType.ViewTypeWeek ? 7 : 1)
MouseArea {
anchors.fill: parent
onClicked: {
if(!allDayButton.events || allDayButton.events.length === 0) {
return;
}
if(type == ViewType.ViewTypeWeek) {
PopupUtils.open(popoverComponent, root,{"events": allDayButton.events})
} else {
if( allDayButton.events.length > 1 ) {
PopupUtils.open(popoverComponent, root,{"events": allDayButton.events})
} else {
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":allDayButton.events[0],"model": root.model});
}
}
}
}
Loader {
id: eventLabelLoader
anchors.fill: parent
sourceComponent : !allDayButton.events || allDayButton.events.length === 0 ? undefined : eventComponent
}
Loader{
objectName: "divider"
height: parent.height
width: units.gu(0.15)
sourceComponent: root.type == ViewType.ViewTypeWeek ? dividerComponent : undefined
}
Connections{
target: root
onAllDayEventsChanged:{
var sd = startDay.midnight();
sd = sd.addDays(index);
var key = Qt.formatDateTime(sd, "dd-MMM-yyyy");
events = allDayEvents[key];
if(!events || events.length === 0) {
return;
}
if(type == ViewType.ViewTypeWeek) {
// TRANSLATORS: the first parameter refers to the number of all-day events
// on a given day. "Ev." is short form for "Events".
// Please keep the translation of "Ev." to 3 characters only, as the week view
// where it's shown has limited space
eventLabelLoader.item.text = i18n.tr("%1 ev.").arg(events.length)
} else {
if( events.length > 1) {
// TRANSLATORS: the argument refers to the number of all day events
eventLabelLoader.item.text = i18n.tr("%1 all day event", "%1 all day events", events.length).arg(events.length)
} else {
eventLabelLoader.item.text = events[0].displayLabel;
}
}
}
}
}
}
Component{
id: eventComponent
Label {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
Component {
id: dividerComponent
SimpleDivider{
anchors.fill: parent
}
}
Component {
id: popoverComponent
Popover {
id: popover
property var events;
ListView{
id: allDayEventsList
property var delegateHight: units.gu(4);
property int maxEventToDisplay: 3;
clip: true
visible: true
width: parent.width
height: ( delegateHight * (events.length > maxEventToDisplay ? maxEventToDisplay : events.length) ) + units.gu(1)
model: popover.events
anchors {
top: parent.top; topMargin: units.gu(1); bottomMargin: units.gu(1)
}
delegate: Label{
text: modelData.displayLabel;
anchors.horizontalCenter: parent.horizontalCenter
color: "black"
height: allDayEventsList.delegateHight
MouseArea{
anchors.fill: parent
onClicked: {
popover.hide();
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":modelData,"model": root.model});
}
}
}
}
}
}
}
|