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

« back to all changes in this revision

Viewing changes to YearView.qml

  • Committer: Tarmac
  • Author(s): nskaggs
  • Date: 2014-03-20 14:56:32 UTC
  • mfrom: (212.1.7 revert-212)
  • Revision ID: tarmac-20140320145632-hul9eb00eot702ed
Revert rev 212. Fixes: https://bugs.launchpad.net/bugs/1294181.

Approved by Timo Jyrinki, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
import "dateExt.js" as DateExt
5
5
 
6
 
Page {
 
6
PathViewBase {
7
7
    id: root
8
8
    objectName: "YearView"
 
9
 
9
10
    property var currentYear: DateExt.today();
 
11
 
10
12
    signal monthSelected(var date);
11
13
 
12
 
    PathViewBase {
13
 
        id: pathView
14
 
 
15
 
        anchors.fill: parent
16
 
 
17
 
        onNextItemHighlighted: {
18
 
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
19
 
        }
20
 
 
21
 
        onPreviousItemHighlighted: {
22
 
            root.currentYear = pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
23
 
        }
24
 
 
25
 
        function getDateFromYear(year) {
26
 
            return new Date(year,0,1,0,0,0,0);
27
 
        }
28
 
 
29
 
        delegate: GridView{
30
 
            id: yearView
31
 
            clip: true
32
 
 
33
 
            property bool isCurrentItem: index == pathView.currentIndex
34
 
            property var year: getYear();
35
 
 
36
 
            function getYear() {
37
 
                switch( pathView.indexType(index)) {
38
 
                case 0:
39
 
                    return root.currentYear;
40
 
                case -1:
41
 
                    return pathView.getDateFromYear(root.currentYear.getFullYear() - 1);
42
 
                case 1:
43
 
                    return pathView.getDateFromYear(root.currentYear.getFullYear() + 1);
44
 
                }
 
14
    anchors.fill: parent
 
15
 
 
16
    onNextItemHighlighted: {
 
17
        currentYear = getDateFromYear(currentYear.getFullYear() + 1);
 
18
    }
 
19
 
 
20
    onPreviousItemHighlighted: {
 
21
        currentYear = getDateFromYear(currentYear.getFullYear() - 1);
 
22
    }
 
23
 
 
24
    function getDateFromYear(year) {
 
25
        return new Date(year,0,1,0,0,0,0);
 
26
    }
 
27
 
 
28
    delegate: GridView{
 
29
        id: yearView
 
30
        clip: true
 
31
 
 
32
        property bool isCurrentItem: index == root.currentIndex
 
33
        property var year: getYear();
 
34
 
 
35
        function getYear() {
 
36
            switch( root.indexType(index)) {
 
37
            case 0:
 
38
                return currentYear;
 
39
            case -1:
 
40
                return getDateFromYear(currentYear.getFullYear() - 1);
 
41
            case 1:
 
42
                return getDateFromYear(currentYear.getFullYear() + 1);
45
43
            }
46
 
 
47
 
            width: parent.width
48
 
            height: parent.height
49
 
            anchors.top: parent.top
50
 
 
51
 
            readonly property int minCellWidth: units.gu(30)
52
 
            cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
 
44
        }
 
45
 
 
46
        width: parent.width
 
47
        height: parent.height
 
48
        anchors.top: parent.top
 
49
 
 
50
        readonly property int minCellWidth: units.gu(30)
 
51
        cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
53
52
            { return ((width / n >= minCellWidth) ? width / n : width / 2) })))
54
53
 
55
 
            cellHeight: cellWidth * 1.4
56
 
 
57
 
            model: 12 /* months in a year */
58
 
            delegate: Item {
59
 
                width: yearView.cellWidth
60
 
                height: yearView.cellHeight
61
 
 
62
 
                MonthComponent{
63
 
                    id: monthComponent
64
 
                    monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
 
54
        cellHeight: cellWidth * 1.4
 
55
 
 
56
        model: 12 /* months in a year */
 
57
        delegate: Item {
 
58
            width: yearView.cellWidth
 
59
            height: yearView.cellHeight
 
60
 
 
61
            MonthComponent{
 
62
                id: monthComponent
 
63
                monthDate: new Date(yearView.year.getFullYear(),index,1,0,0,0,0)
 
64
                anchors.fill: parent
 
65
                anchors.margins: units.gu(0.5)
 
66
 
 
67
                dayLabelFontSize:"x-small"
 
68
                dateLabelFontSize: "medium"
 
69
                monthLabelFontSize: "medium"
 
70
                yearLabelFontSize: "small"
 
71
 
 
72
                MouseArea{
65
73
                    anchors.fill: parent
66
 
                    anchors.margins: units.gu(0.5)
67
 
 
68
 
                    dayLabelFontSize:"x-small"
69
 
                    dateLabelFontSize: "medium"
70
 
                    monthLabelFontSize: "medium"
71
 
                    yearLabelFontSize: "small"
72
 
 
73
 
                    MouseArea{
74
 
                        anchors.fill: parent
75
 
                        onClicked: {
76
 
                            root.monthSelected(monthComponent.monthDate);
77
 
                        }
 
74
                    onClicked: {
 
75
                        root.monthSelected(monthComponent.monthDate);
78
76
                    }
79
77
                }
80
78
            }