~pkunal-parmar/ubuntu-calendar-app/Minor-Performance

« back to all changes in this revision

Viewing changes to MonthView.qml

  • Committer: Frank Mertens
  • Date: 2013-02-15 11:07:30 UTC
  • mfrom: (3.1.1 ubuntu-calendar-app)
  • Revision ID: frank@cyblogic.de-20130215110730-cr1xkncpvbghcyjj
Merged fast forward.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import "dateTimeUtils.js" as DateTime
4
4
 
5
5
ListView {
 
6
    id: monthView // id for internal reference
 
7
 
6
8
    // public properties
7
9
    property bool portraitMode: width < height
8
10
    property real weeksInView: 8
9
11
    property int weekStartDay: 1 // Monday, FIXME: depends on locale / user settings
10
12
 
11
 
    id: monthView // id for internal reference
12
 
 
13
13
    // private properties
14
 
    property real weekHeight: height / weeksInView | 0
15
 
    property int indexOrigin: count / 2
16
 
    property var timeOrigin: (new Date()).weekStart(weekStartDay)
17
 
    property var today: (new Date()).midnight()
 
14
    QtObject {
 
15
        id: internal
 
16
 
 
17
        property real weekHeight: monthView.height / monthView.weeksInView | 0
 
18
        property int indexOrigin: monthView.count / 2
 
19
        property var timeOrigin: (new Date()).weekStart(monthView.weekStartDay)
 
20
        property var today: (new Date()).midnight()
 
21
    }
 
22
 
 
23
    clip: true
 
24
 
 
25
    model: 1041 // weeks for about +-10y
 
26
 
 
27
    delegate: Item {
 
28
        id: weekItem
 
29
 
 
30
        property var weekOrigin: internal.timeOrigin.addDays((index - internal.indexOrigin) * 7)
 
31
 
 
32
        width: parent.width
 
33
        height: internal.weekHeight
 
34
 
 
35
        Row {
 
36
            anchors.fill: parent
 
37
            spacing: 1
 
38
 
 
39
            Repeater {
 
40
                model: 7
 
41
                delegate: Rectangle {
 
42
                    id: dayItem
 
43
 
 
44
                    property var dayOrigin: weekOrigin.addDays(index)
 
45
                    property bool isToday: internal.today.getTime() == dayOrigin.getTime()
 
46
 
 
47
                    width: weekItem.width / 7
 
48
                    height: weekItem.height - 1
 
49
                    color: isToday ? "#c94212" : dayOrigin.getMonth() % 2 ? "#c4c4c4" : "#e0e0e0"
 
50
 
 
51
                    Label {
 
52
                        anchors.centerIn: parent
 
53
                        text: dayOrigin.getDate()
 
54
                        color: isToday ? "white" : dayOrigin.getDay() == 0 ? "#c94212" : "#404040"
 
55
                    }
 
56
                }
 
57
            }
 
58
        }
 
59
    }
18
60
 
19
61
    Timer { // make sure today is updated at midnight
20
62
        interval: 1000
21
63
        repeat: true
22
64
        running: true
 
65
 
23
66
        onTriggered: {
24
67
            var newDate = (new Date()).midnight()
25
 
            if (today < newDate) today = newDate
26
 
        }
27
 
    }
28
 
 
29
 
    clip: true
30
 
 
31
 
    model: 1041 // weeks for about +-10y
32
 
 
33
 
    delegate: Component {
34
 
        Item {
35
 
            id: weekItem
36
 
            property var weekOrigin: timeOrigin.addDays((index - indexOrigin) * 7)
37
 
            width: parent.width
38
 
            height: weekHeight
39
 
            Row {
40
 
                anchors.fill: parent
41
 
                spacing: 1
42
 
                Repeater {
43
 
                    model: 7
44
 
                    delegate: Rectangle {
45
 
                        id: dayItem
46
 
                        property var dayOrigin: weekOrigin.addDays(index)
47
 
                        property bool isToday: today.getTime() == dayOrigin.getTime()
48
 
                        width: weekItem.width / 7
49
 
                        height: weekItem.height - 1
50
 
                        color: isToday ? "#c94212" : dayOrigin.getMonth() % 2 ? "#c4c4c4" : "#e0e0e0"
51
 
                        Label {
52
 
                            anchors.centerIn: parent
53
 
                            text: dayOrigin.getDate()
54
 
                            color: isToday ? "white" : dayOrigin.getDay() == 0 ? "#c94212" : "#404040"
55
 
                        }
56
 
                    }
57
 
                }
58
 
            }
59
 
        }
60
 
    }
61
 
 
62
 
    Component.onCompleted: {
63
 
        positionViewAtIndex(indexOrigin, ListView.Center)
64
 
    }
 
68
            if (internal.today < newDate) internal.today = newDate
 
69
        }
 
70
    }
 
71
 
 
72
    Component.onCompleted: positionViewAtIndex(internal.indexOrigin, ListView.Center)
65
73
}