Make sure we update the calendar on date change

This introduces new property on MonthView - "today". This property is
updated by dataengine (or can be a timer too, but we already get signals
from dataengine every 30 seconds to update the clock) and is never
updated by the code itself.

Furthermore, the DayDelegate is now bound to it, so when "today"
changes, the selection rectangle in the calendar should also change.

And finally, the selected item in the grid is cleared if MonthView's
date property is cleared (which is second part of this patch, to the
applet itself).

REVIEW: 118277
This commit is contained in:
Martin Klapetek 2014-05-26 13:40:47 +02:00
parent efdf1ca917
commit 9f0765b002
3 changed files with 11 additions and 2 deletions

View File

@ -27,7 +27,7 @@ Item {
height: root.cellHeight
property real borderOpacity: daysCalendar.borderOpacity
property bool today: isToday(new Date(yearNumber, monthNumber - 1, dayNumber))
property bool today: root.today.toDateString() == new Date(yearNumber, monthNumber - 1, dayNumber).toDateString() // for some reason the comparison doesn't work without toDateString()
onHeightChanged: {
// this is needed here as the text is first rendered, counting with the default root.cellHeight

View File

@ -92,6 +92,14 @@ Item {
property bool containsEventItems: false // FIXME
property bool containsTodoItems: false // FIXME
property QtObject selectedDate: root.date
onSelectedDateChanged: {
// clear the selection if the root.date is null
if (calendarDays.selectedDate == null) {
calendarDays.selectedItem = null;
}
}
Repeater {
id: days
model: monthCalendar.days

View File

@ -52,6 +52,7 @@ Item {
property Item selectedItem
property int week;
property int firstDay: new Date(showDate.getFullYear(), showDate.getMonth(), 1).getDay()
property date today
anchors.margins: borderWidth
@ -98,7 +99,7 @@ Item {
days: 7
weeks: 6
firstDayOfWeek: Qt.locale().firstDayOfWeek
startDate: today();
startDate: today;
}
DaysCalendar {