2
* Copyright (C) 2013-2014 Canonical Ltd
4
* This file is part of Ubuntu Calendar App
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.
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.
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/>.
20
import QtQuick.Layouts 1.1
21
import Ubuntu.Components 1.1
22
import Ubuntu.Components.Popups 1.0
23
import QtOrganizer 5.0
25
import "dateExt.js" as DateExt
26
import "ViewType.js" as ViewType
31
property var keyboardEventProvider;
33
property date startDay: DateExt.today();
34
property int weekNumber: startDay.weekNumber();
35
property bool isActive: false
36
property alias contentY: timeLineView.contentY
37
property alias contentInteractive: timeLineView.interactive
39
property int type: ViewType.ViewTypeWeek
42
property int scrollHour;
44
property EventListModel mainModel;
46
signal dateSelected(var date);
48
function scrollToCurrentTime() {
49
var currentTime = new Date();
50
scrollHour = currentTime.getHours();
52
timeLineView.contentY = scrollHour * units.gu(8);
53
if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
54
timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
58
function scrollTocurrentDate() {
59
if ( type != ViewType.ViewTypeWeek ){
63
var today = DateExt.today();
64
var startOfWeek = today.weekStart(Qt.locale().firstDayOfWeek);
65
var weekDay = today.getDay();
66
if( startOfWeek.isSameDay(startDay) && weekDay > 2) {
67
timeLineView.contentX = (weekDay * timeLineView.delegateWidth);
68
if( timeLineView.contentX > (timeLineView.contentWidth - timeLineView.width) ) {
69
timeLineView.contentX = timeLineView.contentWidth - timeLineView.width
72
timeLineView.contentX = 0;
77
target: keyboardEventProvider
88
var visibleHour = root.height / units.gu(8);
89
if( scrollHour > (25 -visibleHour)) {
90
scrollHour = 25 - visibleHour;
96
function scrollToHour() {
97
timeLineView.contentY = scrollHour * units.gu(8);
98
if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
99
timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
104
interval: 200; running: true; repeat: false
106
mainModel = modelComponent.createObject();
107
activityLoader.running = Qt.binding( function (){ return mainModel.isLoading;});
115
startPeriod: startDay.midnight();
116
endPeriod: type == ViewType.ViewTypeWeek ? startPeriod.addDays(7).endOfDay(): startPeriod.endOfDay()
117
filter: eventModel.filter
124
objectName : "activityIndicator"
125
anchors.centerIn: parent
134
objectName: "viewHeader"
135
startDay: root.startDay
136
contentX: timeLineView.contentX
140
root.dateSelected(date);
148
height: parent.height - header.height
151
contentY: timeLineView.contentY
156
height: parent.height
161
objectName: "timelineview"
163
height: parent.height
164
width: parent.width - units.gu(6)
166
boundsBehavior: Flickable.StopAtBounds
168
property int delegateWidth: {
169
if( type == ViewType.ViewTypeWeek ) {
170
width/3 - units.gu(1) /*partial visible area*/
176
contentHeight: units.gu(8) * 24
178
if( type == ViewType.ViewTypeWeek ) {
193
model: type == ViewType.ViewTypeWeek ? 7 : 1
195
delegate: TimeLineBase {
196
property int idx: index
197
anchors.top: parent.top
199
if( type == ViewType.ViewTypeWeek ) {
205
height: parent.height
207
day: startDay.addDays(index)
220
objectName: "mouseArea"
223
function modifyEventForDrag(drag) {
224
var event = drag.source.event;
225
var diff = event.endDateTime.getTime() - event.startDateTime.getTime();
227
var startDate = getTimeFromYPos(drag.y, day);
228
var endDate = new Date( startDate.getTime() + diff );
230
event.startDateTime = startDate;
231
event.endDateTime = endDate;
237
var event = dropArea.modifyEventForDrag(drop);
238
model.saveItem(event);
242
dropArea.modifyEventForDrag(drag)
243
var eventBubble = drag.source;
244
eventBubble.assingnBgColor();
245
eventBubble.setDetails();
247
if( eventBubble.y + eventBubble.height + units.gu(8) > timeLineView.contentY + timeLineView.height ) {
248
var diff = Math.abs((eventBubble.y + eventBubble.height + units.gu(8)) -
249
(timeLineView.height + timeLineView.contentY));
250
timeLineView.contentY += diff
252
if(timeLineView.contentY >= timeLineView.contentHeight - timeLineView.height) {
253
timeLineView.contentY = timeLineView.contentHeight - timeLineView.height
257
if(eventBubble.y - units.gu(8) < timeLineView.contentY ) {
258
var diff = Math.abs((eventBubble.y - units.gu(8)) - timeLineView.contentY);
259
timeLineView.contentY -= diff
261
if(timeLineView.contentY <= 0) {
262
timeLineView.contentY = 0;
269
objectName: "weekdevider"
270
height: parent.height
271
width: units.gu(0.15)
272
sourceComponent: type == ViewType.ViewTypeWeek ? weekDividerComponent : undefined
276
id: weekDividerComponent
284
onStartPeriodChanged:{
285
destroyAllChildren();
298
type: root.type == ViewType.ViewTypeWeek ? narrowType : wideType
299
flickable: root.isActive ? timeLineView : null