~mihirsoni/ubuntu-calendar-app/dateSelectNewEventTest

« back to all changes in this revision

Viewing changes to DayView.qml

  • Committer: Kunal Parmar
  • Date: 2014-10-20 15:20:21 UTC
  • mto: This revision was merged to the branch mainline in revision 510.
  • Revision ID: pkunal.parmar@gmail.com-20141020152021-e2fv7dqqu4zv4g2y
defect resolved

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 Ubuntu.Components 1.1
 
21
import "dateExt.js" as DateExt
 
22
import "ViewType.js" as ViewType
 
23
 
 
24
Page{
 
25
    id: dayViewPage
 
26
    objectName: "dayViewPage"
 
27
 
 
28
    property var currentDay: new Date()
 
29
    property bool isCurrentPage: false
 
30
 
 
31
    Keys.forwardTo: [dayViewPath]
 
32
    flickable: null
 
33
 
 
34
    Action {
 
35
        id: calendarTodayAction
 
36
        objectName:"todaybutton"
 
37
        iconName: "calendar-today"
 
38
        text: i18n.tr("Today")
 
39
        onTriggered: {
 
40
            currentDay = new Date()
 
41
        }
 
42
    }
 
43
 
 
44
    head {
 
45
        actions: [
 
46
            calendarTodayAction,
 
47
            commonHeaderActions.newEventAction,
 
48
            commonHeaderActions.showCalendarAction,
 
49
            commonHeaderActions.reloadAction
 
50
        ]
 
51
 
 
52
        contents: Label {
 
53
            id:monthYear
 
54
            objectName:"monthYearLabel"
 
55
            fontSize: "x-large"
 
56
            text: i18n.tr(currentDay.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy")))
 
57
            font.capitalization: Font.Capitalize
 
58
        }
 
59
    }
 
60
 
 
61
    Column {
 
62
        anchors.fill: parent
 
63
        anchors.topMargin: units.gu(1)
 
64
        spacing: units.gu(1)
 
65
 
 
66
        TimeLineHeader{
 
67
            id: dayHeader
 
68
            objectName: "dayHeader"
 
69
            type: ViewType.ViewTypeDay
 
70
            currentDay: dayViewPage.currentDay
 
71
 
 
72
            onCurrentDayChanged: {
 
73
                date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
 
74
            }
 
75
 
 
76
            function nextDay() {
 
77
                if(currentDay >= date.addDays(7)) {
 
78
                    date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
 
79
                    dayHeader.incrementCurrentIndex();
 
80
                }
 
81
            }
 
82
 
 
83
            function previousDay() {
 
84
                if( currentDay < date) {
 
85
                    date = dayViewPage.currentDay.weekStart(Qt.locale().firstDayOfWeek);
 
86
                    dayHeader.decrementCurrentIndex();
 
87
                }
 
88
            }
 
89
        }
 
90
 
 
91
        PathViewBase{
 
92
            id: dayViewPath
 
93
            objectName: "dayViewPath"
 
94
 
 
95
            property var startDay: currentDay
 
96
            //This is used to scroll all view together when currentItem scrolls
 
97
            property var childContentY;
 
98
 
 
99
            width: parent.width
 
100
            height: dayViewPage.height - dayViewPath.y
 
101
 
 
102
            onNextItemHighlighted: {
 
103
                //next day
 
104
                currentDay = currentDay.addDays(1);
 
105
                dayHeader.nextDay();
 
106
            }
 
107
 
 
108
            onPreviousItemHighlighted: {
 
109
                //previous day
 
110
                currentDay = currentDay.addDays(-1);
 
111
                dayHeader.previousDay();
 
112
            }
 
113
 
 
114
            delegate: TimeLineBaseComponent {
 
115
                id: timeLineView
 
116
                objectName: "DayComponent-"+index
 
117
 
 
118
                type: ViewType.ViewTypeDay
 
119
 
 
120
                width: parent.width
 
121
                height: parent.height
 
122
                z: index == dayViewPath.currentIndex ? 2 : 1
 
123
                isActive: true
 
124
 
 
125
                Connections{
 
126
                    target: dayViewPage
 
127
                    onIsCurrentPageChanged:{
 
128
                        if(dayViewPage.isCurrentPage){
 
129
                            timeLineView.scrollToCurrentTime();
 
130
                        }
 
131
                    }
 
132
                }
 
133
 
 
134
                //get contentY value from PathView, if its not current Item
 
135
                Binding{
 
136
                    target: timeLineView
 
137
                    property: "contentY"
 
138
                    value: dayViewPath.childContentY;
 
139
                    when: !timeLineView.PathView.isCurrentItem
 
140
                }
 
141
 
 
142
                //set PathView's contentY property, if its current item
 
143
                Binding{
 
144
                    target: dayViewPath
 
145
                    property: "childContentY"
 
146
                    value: contentY
 
147
                    when: timeLineView.PathView.isCurrentItem
 
148
                }
 
149
 
 
150
                contentInteractive: timeLineView.PathView.isCurrentItem
 
151
 
 
152
                startDay: dayViewPath.startDay.addDays(dayViewPath.indexType(index))
 
153
            }
 
154
        }
 
155
    }
 
156
}