~pkunal-parmar/ubuntu-calendar-app/ICalImport

« back to all changes in this revision

Viewing changes to YearView.qml

  • Committer: Tarmac
  • Author(s): Olivier Tilloy
  • Date: 2013-09-03 15:28:32 UTC
  • mfrom: (98.2.2 fix-ap-test-assumption)
  • Revision ID: tarmac-20130903152832-p8fp3lnggz6w39w3
Do not assume there will always be a label with the given text.

Approved by Ubuntu Phone Apps Jenkins Bot, Kunal Parmar.

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
 
 
22
 
import "dateExt.js" as DateExt
23
 
Page {
24
 
    id: yearViewPage
25
 
    objectName: "yearViewPage"
26
 
 
27
 
    property int currentYear: DateExt.today().getFullYear();
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
 
3
 
 
4
PathViewBase {
 
5
    id: root
 
6
 
 
7
    anchors.fill: parent
 
8
    property var year: getDateFromYear(intern.now.getFullYear()-1);
 
9
 
28
10
    signal monthSelected(var date);
29
11
 
30
 
    Keys.forwardTo: [yearPathView]
31
 
 
32
 
    Action {
33
 
        id: calendarTodayAction
34
 
        objectName:"todaybutton"
35
 
        iconName: "calendar-today"
36
 
        text: i18n.tr("Today")
37
 
        onTriggered: {
38
 
            currentYear = new Date().getFullYear()
39
 
        }
40
 
    }
41
 
 
42
 
    head {
43
 
        actions: [
44
 
            calendarTodayAction,
45
 
            commonHeaderActions.newEventAction,
46
 
            commonHeaderActions.showCalendarAction,
47
 
            commonHeaderActions.reloadAction,
48
 
            commonHeaderActions.syncCalendarAction
49
 
        ]
50
 
        contents: Label {
51
 
            id:year
52
 
            objectName:"yearLabel"
53
 
            fontSize: "x-large"
54
 
            text: i18n.tr("Year %1").arg(currentYear)
55
 
        }
56
 
    }
57
 
 
58
 
    PathViewBase {
59
 
        id: yearPathView
60
 
        objectName: "yearPathView"
61
 
 
62
 
        anchors.fill: parent
63
 
 
64
 
        onNextItemHighlighted: {
65
 
            currentYear = currentYear + 1;
66
 
        }
67
 
 
68
 
        onPreviousItemHighlighted: {
69
 
            currentYear = currentYear - 1;
70
 
        }
71
 
 
72
 
        delegate: Loader {
 
12
    onNextItemHighlighted: {
 
13
        year = getDateFromYear(year.getFullYear() + 1);
 
14
    }
 
15
 
 
16
    onPreviousItemHighlighted: {
 
17
        year = getDateFromYear(year.getFullYear() - 1);
 
18
    }
 
19
 
 
20
    function getDateFromYear(year) {
 
21
        return new Date(year,0,1,0,0,0,0);
 
22
    }
 
23
 
 
24
    QtObject{
 
25
        id: intern
 
26
        property var now: new Date()
 
27
        property int weekstartDay: Qt.locale().firstDayOfWeek
 
28
    }
 
29
 
 
30
    delegate: Item{
 
31
        id: yearView
 
32
 
 
33
        property var year: {
 
34
            if (index === root.currentIndex) {
 
35
                return root.year;
 
36
            }
 
37
            var previousIndex = root.currentIndex > 0 ? root.currentIndex - 1 : 2
 
38
 
 
39
            if ( index === previousIndex ) {
 
40
                return getDateFromYear(root.year.getFullYear()-1);
 
41
            }
 
42
 
 
43
            return getDateFromYear(root.year.getFullYear()+ 1);
 
44
        }
 
45
 
 
46
        width: parent.width
 
47
        height: parent.height
 
48
 
 
49
        Label{
 
50
            id: yearLabel
 
51
            text: year.getFullYear()
 
52
            fontSize: "large"
 
53
            anchors.horizontalCenter: parent.horizontalCenter
 
54
            font.bold: true
 
55
        }
 
56
 
 
57
        Grid{
 
58
            id: yearGrid
 
59
            rows: 4
 
60
            columns: 3
 
61
 
73
62
            width: parent.width
74
63
            height: parent.height
75
 
            anchors.top: parent.top
76
 
 
77
 
            asynchronous: index !== yearPathView.currentIndex
78
 
            sourceComponent: delegateComponent
79
 
 
80
 
            Component{
81
 
                id: delegateComponent
82
 
 
83
 
                YearViewDelegate{
84
 
                    focus: index == yearPathView.currentIndex
85
 
 
86
 
                    scrollMonth: 0;
87
 
                    isCurrentItem: index == yearPathView.currentIndex
88
 
                    year: (yearViewPage.currentYear + yearPathView.indexType(index))
89
 
 
90
 
                    anchors.fill: parent
 
64
            anchors.top: yearLabel.bottom
 
65
            spacing: units.gu(2.5)
 
66
 
 
67
            Repeater{
 
68
                model: yearGrid.rows * yearGrid.columns
 
69
                delegate: MonthComponent{
 
70
                    date: new Date(year.getFullYear(),index,1,0,0,0,0)
 
71
 
 
72
                    onMonthSelected: {
 
73
                        root.monthSelected(date);
 
74
                    }
91
75
                }
92
76
            }
93
77
        }