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

« back to all changes in this revision

Viewing changes to MonthView.qml

  • Committer: Frank Mertens
  • Date: 2013-03-10 21:45:05 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: frank@cyblogic.de-20130310214505-hoz29u7sh85js3jc
Allow the MonthView to be compressed to the current week.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
    readonly property var monthEnd: currentItem != null ? currentItem.monthEnd : (new Date()).monthStart().addMonths(1)
11
11
    readonly property var currentDayStart: intern.currentDayStart
12
12
 
 
13
    property bool compressed: false
 
14
    property real compressedHeight: intern.squareUnit + intern.verticalMargin * 2
 
15
 
13
16
    signal incrementCurrentDay
14
17
    signal decrementCurrentDay
15
18
 
86
89
        id: intern
87
90
 
88
91
        property int squareUnit: monthView.width / 8
 
92
        property int verticalMargin: units.gu(1)
89
93
        property int weekstartDay: Qt.locale().firstDayOfWeek
90
94
        property int monthCount: 49 // months for +-2 years
91
95
 
92
96
        property var today: (new Date()).midnight() // TODO: update at midnight
93
97
        property var currentDayStart: today
94
 
        property int monthIndex0: monthCount / 2
 
98
        property int monthIndex0: Math.floor(monthCount / 2)
95
99
        property var monthStart0: today.monthStart()
96
100
    }
97
101
 
 
102
    width: parent.width
 
103
    height: intern.squareUnit * 6 + intern.verticalMargin * 2
 
104
 
 
105
    interactive: !compressed
98
106
    clip: true
99
107
    orientation: ListView.Horizontal
100
108
    snapMode: ListView.SnapOneItem
105
113
    preferredHighlightEnd: width
106
114
 
107
115
    model: intern.monthCount
108
 
    currentIndex: intern.monthCount / 2
 
116
    currentIndex: intern.monthIndex0
109
117
 
110
118
    delegate: Item {
111
119
        id: monthItem
113
121
        property var monthStart: intern.monthStart0.addMonths(index - intern.monthIndex0)
114
122
        property var monthEnd: monthStart.addMonths(1)
115
123
        property var gridStart: monthStart.weekStart(intern.weekstartDay)
116
 
        property int currentWeekRow: (currentDayStart.getTime() - gridStart.getTime()) / Date.msPerWeek
 
124
        property int currentWeekRow: Math.floor((currentDayStart.getTime() - gridStart.getTime()) / Date.msPerWeek)
117
125
 
118
126
        width: monthView.width
119
127
        height: monthView.height
121
129
        Grid {
122
130
            id: monthGrid
123
131
 
124
 
            x: intern.squareUnit / 2
125
132
            rows: 6
126
133
            columns: 7
 
134
 
 
135
            x: intern.squareUnit / 2
 
136
            y: intern.verticalMargin
127
137
            width: intern.squareUnit * columns
128
138
            height: intern.squareUnit * rows
129
139
 
137
147
                    property bool isCurrent: dayStart.getTime() == intern.currentDayStart.getTime()
138
148
                    property int weekday: (index % 7 + intern.weekstartDay) % 7
139
149
                    property bool isSunday: weekday == 0
140
 
                    property bool isCurrentWeek: ((index / 7) | 0) == currentWeekRow
 
150
                    property int row: Math.floor(index / 7)
 
151
                    property bool isCurrentWeek: row == currentWeekRow
 
152
                    property real topMargin: (row == 0 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
 
153
                    property real bottomMargin: (row == 5 || (monthView.compressed && isCurrentWeek)) ? -intern.verticalMargin : 0
 
154
                    visible: monthView.compressed ? isCurrentWeek : true
141
155
                    width: intern.squareUnit
142
156
                    height: intern.squareUnit
143
157
                    Rectangle {
144
158
                        visible: isSunday
145
159
                        anchors.fill: parent
 
160
                        anchors.topMargin: dayItem.topMargin
 
161
                        anchors.bottomMargin: dayItem.bottomMargin
146
162
                        color: Color.warmGrey
147
163
                        opacity: 0.1
148
164
                    }
159
175
                    }
160
176
                    MouseArea {
161
177
                        anchors.fill: parent
 
178
                        anchors.topMargin: dayItem.topMargin
 
179
                        anchors.bottomMargin: dayItem.bottomMargin
162
180
                        onReleased: monthView.focusOnDay(dayStart)
163
181
                    }
164
182
                    // Component.onCompleted: console.log(dayStart, intern.currentDayStart)
166
184
            }
167
185
        }
168
186
 
169
 
        // Component.onCompleted: console.log("Created delegate for month", index, monthStart, gridStart)
 
187
        // Component.onCompleted: console.log("Created delegate for month", index, monthStart, gridStart, currentWeekRow, currentWeekRowReal)
170
188
    }
171
189
 
172
190
    Label {