400.1.1
by mihirsoni-123
Added copyright header comments in all the pages |
1 |
/*
|
400.1.2
by mihirsoni-123
updated copyright year |
2 |
* Copyright (C) 2013-2014 Canonical Ltd
|
400.1.1
by mihirsoni-123
Added copyright header comments in all the pages |
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 |
*/
|
|
191.4.2
by Kunal Parmar
adding new files |
18 |
import QtQuick 2.0 |
422.5.1
by Akiva Avraham
Upgraded component library imports |
19 |
import Ubuntu.Components 1.1 |
20 |
import Ubuntu.Components.Popups 1.0 |
|
191.4.2
by Kunal Parmar
adding new files |
21 |
|
22 |
import "dateExt.js" as DateExt |
|
23 |
import "ViewType.js" as ViewType |
|
24 |
||
25 |
Rectangle{ |
|
26 |
id: root
|
|
27 |
||
28 |
property var allDayEvents; |
|
29 |
property var startDay: DateExt.today(); |
|
233.1.1
by Kunal Parmar
EventView performance improvement |
30 |
property var model; |
191.4.2
by Kunal Parmar
adding new files |
31 |
|
32 |
property int type: ViewType.ViewTypeWeek |
|
33 |
||
34 |
height: units.gu(6) |
|
35 |
width: parent.width |
|
279.2.1
by Alan Pope
start moving to new colours |
36 |
color: "#C8C8C8" |
191.4.2
by Kunal Parmar
adding new files |
37 |
|
38 |
function getAllDayEvents(startDate, endDate) { |
|
39 |
var map = {}; |
|
233.1.1
by Kunal Parmar
EventView performance improvement |
40 |
var items = model.getItems(startDate,endDate); |
41 |
for(var i = 0 ; i < items.length ; ++i) { |
|
42 |
var event = items[(i)]; |
|
191.4.2
by Kunal Parmar
adding new files |
43 |
if( event && event.allDay ) { |
191.4.3
by Kunal Parmar
Review comment |
44 |
var key = Qt.formatDateTime(event.startDateTime, "dd-MMM-yyyy"); |
191.4.2
by Kunal Parmar
adding new files |
45 |
if( !(key in map)) { |
46 |
map[key] = []; |
|
47 |
}
|
|
48 |
map[key].push(event); |
|
49 |
}
|
|
50 |
}
|
|
51 |
return map; |
|
52 |
}
|
|
53 |
||
54 |
function createAllDayEvents() { |
|
199.1.11
by Kunal Parmar
Some warning removed |
55 |
if(!startDay || startDay === undefined) { |
56 |
return; |
|
57 |
}
|
|
191.4.2
by Kunal Parmar
adding new files |
58 |
var sd = startDay.midnight(); |
59 |
var ed = sd.addDays( (type == ViewType.ViewTypeDay) ? 1 : 7); |
|
60 |
allDayEvents = getAllDayEvents(sd,ed); |
|
61 |
}
|
|
62 |
||
63 |
Row { |
|
64 |
width: parent.width |
|
65 |
anchors.verticalCenter: parent.verticalCenter |
|
66 |
||
67 |
Repeater{ |
|
68 |
model: type == ViewType.ViewTypeWeek ? 7 : 1 |
|
69 |
delegate: Label{ |
|
70 |
id: allDayLabel
|
|
71 |
||
72 |
property var events; |
|
73 |
||
74 |
clip: true |
|
75 |
width: parent.width/ (type == ViewType.ViewTypeWeek ? 7 : 1) |
|
76 |
horizontalAlignment: Text.AlignHCenter |
|
77 |
||
78 |
MouseArea{ |
|
79 |
anchors.fill: parent |
|
80 |
onClicked: { |
|
81 |
if(!allDayLabel.events || allDayLabel.events.length === 0) { |
|
82 |
return; |
|
83 |
}
|
|
84 |
||
85 |
if(type == ViewType.ViewTypeWeek) { |
|
86 |
PopupUtils.open(popoverComponent, root,{"events": allDayLabel.events}) |
|
87 |
} else { |
|
88 |
if( allDayLabel.events.length > 1 ) { |
|
89 |
PopupUtils.open(popoverComponent, root,{"events": allDayLabel.events}) |
|
90 |
} else { |
|
261.1.1
by Kunal Parmar
Event Details fix |
91 |
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":allDayLabel.events[0],"model": root.model}); |
191.4.2
by Kunal Parmar
adding new files |
92 |
}
|
93 |
}
|
|
94 |
}
|
|
95 |
}
|
|
96 |
||
97 |
Connections{ |
|
98 |
target: root |
|
99 |
onAllDayEventsChanged:{ |
|
100 |
var sd = startDay.midnight(); |
|
101 |
sd = sd.addDays(index); |
|
102 |
var key = Qt.formatDateTime(sd, "dd-MMM-yyyy"); |
|
103 |
events = allDayEvents[key]; |
|
104 |
||
105 |
if(!events || events.length === 0) { |
|
106 |
text = ""; |
|
107 |
return; |
|
108 |
}
|
|
109 |
||
110 |
if(type == ViewType.ViewTypeWeek) { |
|
301.2.2
by Mihir Soni
Added Translators comment |
111 |
// TRANSLATORS: the first parameter refers to the number of all-day events
|
112 |
// on a given day. "Ev." is short form for "Events".
|
|
113 |
// Please keep the translation of "Ev." to 3 characters only, as the week view
|
|
114 |
// where it's shown has limited space
|
|
301.2.1
by Mihir Soni
Modified the weekview all day event |
115 |
text = i18n.tr("%1 Ev.").arg(events.length) |
191.4.2
by Kunal Parmar
adding new files |
116 |
} else { |
117 |
if( events.length > 1) { |
|
118 |
text = i18n.tr("%1 All day events").arg(events.length) |
|
119 |
} else { |
|
120 |
text = events[0].displayLabel; |
|
121 |
}
|
|
122 |
}
|
|
123 |
}
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
}
|
|
128 |
||
129 |
Component { |
|
130 |
id: popoverComponent
|
|
131 |
||
132 |
Popover { |
|
133 |
id: popover
|
|
134 |
||
135 |
property var events; |
|
136 |
||
137 |
ListView{ |
|
138 |
id: allDayEventsList
|
|
139 |
||
140 |
property var delegateHight: units.gu(4); |
|
141 |
property int maxEventToDisplay: 3; |
|
142 |
||
143 |
clip: true |
|
144 |
visible: true |
|
145 |
width: parent.width |
|
146 |
height: ( delegateHight * (events.length > maxEventToDisplay ? maxEventToDisplay : events.length) ) + units.gu(1) |
|
147 |
model: popover.events |
|
148 |
anchors { |
|
149 |
top: parent.top; topMargin: units.gu(1); bottomMargin: units.gu(1) |
|
150 |
}
|
|
151 |
||
152 |
delegate: Label{ |
|
153 |
text: modelData.displayLabel; |
|
154 |
anchors.horizontalCenter: parent.horizontalCenter |
|
155 |
color: "black" |
|
156 |
height: allDayEventsList.delegateHight |
|
157 |
||
158 |
MouseArea{ |
|
159 |
anchors.fill: parent |
|
160 |
onClicked: { |
|
161 |
popover.hide(); |
|
261.1.1
by Kunal Parmar
Event Details fix |
162 |
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":modelData,"model": root.model}); |
191.4.2
by Kunal Parmar
adding new files |
163 |
}
|
164 |
}
|
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
}
|
|
169 |
}
|