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

« back to all changes in this revision

Viewing changes to YearViewDelegate.qml

  • Committer: Sergio Schvezov
  • Date: 2014-01-18 23:29:11 UTC
  • mto: This revision was merged to the branch mainline in revision 184.
  • Revision ID: sergio.schvezov@canonical.com-20140118232911-p3jdkkomszdl2l70
Adding cmake 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import QtQuick 2.0
2
 
import Ubuntu.Components 1.1
3
 
 
4
 
GridView{
5
 
    id: yearView
6
 
    clip: true
7
 
 
8
 
    property int scrollMonth;
9
 
    property bool isCurrentItem;
10
 
    property int year;
11
 
 
12
 
    readonly property int minCellWidth: units.gu(30)
13
 
    cellWidth: Math.floor(Math.min.apply(Math, [3, 4].map(function(n)
14
 
    { return ((width / n >= minCellWidth) ? width / n : width / 2) })))
15
 
 
16
 
    cellHeight: cellWidth * 1.4
17
 
 
18
 
    model: 12 /* months in a year */
19
 
 
20
 
    onYearChanged: {
21
 
        scrollMonth = 0;
22
 
        var today = new Date();
23
 
        if(year == today.getFullYear()) {
24
 
            scrollMonth = today.getMonth();
25
 
        }
26
 
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
27
 
    }
28
 
 
29
 
    //scroll in case content height changed
30
 
    onHeightChanged: {
31
 
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
32
 
    }
33
 
 
34
 
    Component.onCompleted: {
35
 
        yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
36
 
    }
37
 
 
38
 
    Connections{
39
 
        target: yearPathView
40
 
        onScrollUp: {
41
 
            scrollMonth -= 2;
42
 
            if(scrollMonth < 0) {
43
 
                scrollMonth = 0;
44
 
            }
45
 
            yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
46
 
        }
47
 
 
48
 
        onScrollDown: {
49
 
            scrollMonth += 2;
50
 
            var visibleMonths = yearView.height / cellHeight;
51
 
            if( scrollMonth >= (11 - visibleMonths)) {
52
 
                scrollMonth = (11 - visibleMonths);
53
 
            }
54
 
            yearView.positionViewAtIndex(scrollMonth, GridView.Beginning);
55
 
        }
56
 
    }
57
 
 
58
 
    delegate: Loader {
59
 
        width: yearView.cellWidth
60
 
        height: yearView.cellHeight
61
 
 
62
 
        sourceComponent: delegateComponent
63
 
        asynchronous: !yearView.focus
64
 
 
65
 
        Component {
66
 
            id: delegateComponent
67
 
 
68
 
            Item {
69
 
                anchors.fill: parent
70
 
                anchors.margins: units.gu(0.5)
71
 
 
72
 
                MonthComponent {
73
 
                    id: monthComponent
74
 
                    objectName: "monthComponent" + index
75
 
                    showEvents: false
76
 
                    currentMonth: new Date(yearView.year, index, 1, 0, 0, 0, 0)
77
 
 
78
 
                    isCurrentItem: yearView.focus
79
 
 
80
 
                    isYearView: true
81
 
                    anchors.fill: parent
82
 
 
83
 
                    dayLabelFontSize:"x-small"
84
 
                    dateLabelFontSize: "medium"
85
 
                    monthLabelFontSize: "medium"
86
 
                    yearLabelFontSize: "medium"
87
 
 
88
 
                    onMonthSelected: {
89
 
                        yearViewPage.monthSelected(date);
90
 
                    }
91
 
                }
92
 
            }
93
 
        }
94
 
    }
95
 
}