27
8
property var delegate;
29
property int hourHeight: units.gu(8)
32
Component.onCompleted: {
33
bubbleOverLay.createEvents();
38
objectName: "mouseArea"
40
var selectedDate = new Date(day);
41
var hour = parseInt(mouseY / hourHeight);
42
selectedDate.setHours(hour)
43
//pageStack.push(Qt.resolvedUrl("NewEvent.qml"), {"date":selectedDate, "model":eventModel});
44
createOrganizerEvent(selectedDate);
48
intern.now = new Date();
49
if( intern.now.isSameDay( bubbleOverLay.day ) ) {
50
bubbleOverLay.showSeparator();
55
function getTimeFromYPos(y, day) {
56
var date = new Date(day);
57
var time = y / hourHeight;
58
var minutes = time % 1 ;
59
var hour = time - minutes;
60
minutes = parseInt(60 * minutes);
61
minutes = Math.floor(minutes/15) * 15;
63
date.setMinutes(minutes);
67
function createOrganizerEvent( startDate ) {
68
var event = Qt.createQmlObject("import QtOrganizer 5.0; Event {}", Qt.application,"TimeLineBase.qml");
69
event.collectionId = (model.defaultCollection().collectionId);
70
var endDate = new Date( startDate.getTime() + 3600000 );
71
event.startDateTime = startDate;
72
event.endDateTime = endDate;
73
event.displayLabel = i18n.tr("Untitled");
74
model.saveItem(event);
10
property int hourHeight: units.gu(10)
14
termStart: bubbleOverLay.day.midnight()
15
termLength: Date.msPerDay
18
bubbleOverLay.createEvents();
79
24
objectName: "separator"
80
25
width: bubbleOverLay.width
87
31
property var now : new Date();
88
property var eventMap;
89
property var unUsedEvents: new Object();
92
34
function showEventDetails(event) {
93
pageStack.push(Qt.resolvedUrl("EventDetails.qml"), {"event":event,"model":model});
98
source: "EventLayoutHelper.js"
101
layoutEvents(messageObject.schedules,messageObject.maxDepth);
105
function layoutEvents(array, depth) {
106
for(var i=0; i < array.length ; ++i) {
107
var schedule = array[i];
108
var event = intern.eventMap[schedule.id];
109
bubbleOverLay.createEvent(event , schedule.depth, depth +1);
35
pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":event});
113
38
function createEvents() {
114
if(!bubbleOverLay || bubbleOverLay == undefined || model === undefined || model === null) {
118
destroyAllChildren();
123
var startDate = new Date(day).midnight();
124
var endDate = new Date(day).endOfDay();
125
var items = model.getItems(startDate,endDate);
126
for(var i = 0; i < items.length; ++i) {
127
var event = items[i];
39
bubbleOverLay.destroyAllChildren();
41
for(var i = 0 ; i < model.count ; ++i) {
42
var event = model.get(i);
44
bubbleOverLay.createEvent(event,event.startTime.getHours());
133
var schedule = {"startDateTime": event.startDateTime, "endDateTime": event.endDateTime,"id":event.itemId };
134
allSchs.push(schedule);
135
eventMap[event.itemId] = event;
138
intern.eventMap = eventMap;
139
eventLayoutHelper.sendMessage(allSchs);
141
48
if( intern.now.isSameDay( bubbleOverLay.day ) ) {
142
bubbleOverLay.showSeparator();
49
bubbleOverLay.showSeparator(intern.now.getHours());
146
53
function destroyAllChildren() {
147
54
for( var i = children.length - 1; i >= 0; --i ) {
148
if( children[i].objectName === "mouseArea" ||
149
children[i].objectName === "weekdevider") {
152
children[i].visible = false;
153
if( children[i].objectName !== "separator") {
154
children[i].clicked.disconnect( bubbleOverLay.showEventDetails );
155
var key = children[i].objectName;
156
if (intern.unUsedEvents[key] === "undefined") {
157
intern.unUsedEvents[key] = children[i];
163
function isHashEmpty(hash) {
164
for (var prop in hash) {
171
function getAKeyFromHash(hash) {
172
for (var prop in hash) {
178
function getUnusedEventBubble() {
179
/* Recycle an item from unUsedEvents, and remove from hash */
180
var key = getAKeyFromHash(intern.unUsedEvents);
181
var unUsedBubble = intern.unUsedEvents[key];
182
delete intern.unUsedEvents[key];
187
function createEvent( event, depth, sizeOfRow ) {
189
if( isHashEmpty(intern.unUsedEvents) ) {
190
var incubator = delegate.incubateObject(bubbleOverLay);
191
if (incubator.status !== Component.Ready) {
192
incubator.onStatusChanged = function(status) {
193
if (status === Component.Ready) {
194
incubator.object.objectName = children.length;
195
assignBubbleProperties(incubator.object, event, depth, sizeOfRow);
55
if( children[i].objectName === "separator") {
56
children[i].visible = false;
199
incubator.object.objectName = children.length;
200
assignBubbleProperties(incubator.object, event, depth, sizeOfRow);
58
children[i].destroy();
203
eventBubble = getUnusedEventBubble();
204
assignBubbleProperties(eventBubble, event, depth, sizeOfRow);
208
function assignBubbleProperties(eventBubble, event, depth, sizeOfRow) {
209
var hour = event.startDateTime.getHours();
210
var yPos = (( event.startDateTime.getMinutes() * hourHeight) / 60) + hour * hourHeight
63
function createEvent( event ,hour) {
64
var eventBubble = delegate.createObject(bubbleOverLay);
66
eventBubble.clicked.connect( bubbleOverLay.showEventDetails );
68
eventBubble.event = event
70
var yPos = (( event.startTime.getMinutes() * hourHeight) / 60) + hour * hourHeight
211
71
eventBubble.y = yPos;
213
var durationMin = (event.endDateTime.getHours() - event.startDateTime.getHours()) * 60;
214
durationMin += (event.endDateTime.getMinutes() - event.startDateTime.getMinutes());
73
var durationMin = (event.endTime.getHours() - event.startTime.getHours()) * 60;
74
durationMin += (event.endTime.getMinutes() - event.startTime.getMinutes());
215
75
var height = (durationMin * hourHeight )/ 60;
216
eventBubble.height = (height > eventBubble.minimumHeight) ? height:eventBubble.minimumHeight ;
218
eventBubble.model = bubbleOverLay.model
219
eventBubble.depthInRow = depth;
220
eventBubble.sizeOfRow = sizeOfRow;
221
eventBubble.event = event
222
eventBubble.visible = true;
223
eventBubble.clicked.connect( bubbleOverLay.showEventDetails );
76
eventBubble.height = height;
226
function showSeparator() {
227
var y = ((intern.now.getMinutes() * hourHeight) / 60) + intern.now.getHours() * hourHeight;
79
function showSeparator(hour) {
80
var y = ((intern.now.getMinutes() * hourHeight) / 60) + hour * hourHeight;
229
82
separator.visible = true;