~chris.gagnon/ubuntu-calendar-app/fix_1293489

« back to all changes in this revision

Viewing changes to MonthView.qml

  • Committer: Frank Mertens
  • Date: 2013-03-05 01:34:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: frank@cyblogic.de-20130305013458-rpsxz7p4tz9d8epw
Added methods for stepping days.

Also: introduced colorUtils.js as a central place to keep colors

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import QtQuick 2.0
2
2
import Ubuntu.Components 0.1
3
3
import "DateLib.js" as DateLib
 
4
import "colorUtils.js" as Color
4
5
 
5
6
ListView {
6
7
    id: monthView
7
8
 
8
 
    readonly property var monthStart: currentItem != null ? currentItem.monthStart : (new Date())
 
9
    readonly property var monthStart: currentItem != null ? currentItem.monthStart : (new Date()).monthStart()
 
10
    readonly property var monthEnd: currentItem != null ? currentItem.monthEnd : (new Date()).monthStart().addMonths(1)
 
11
    readonly property var currentDayStart: intern.currentDayStart
 
12
 
 
13
    signal incrementCurrentDay
 
14
    signal decrementCurrentDay
9
15
 
10
16
    signal gotoNextMonth(int month)
11
17
 
 
18
    onCurrentItemChanged: {
 
19
        if (currentItem == null) {
 
20
            intern.currentDayStart = intern.currentDayStart
 
21
            return
 
22
        }
 
23
        if (currentItem.monthStart <= intern.currentDayStart && intern.currentDayStart < currentItem.monthEnd)
 
24
            return
 
25
        if (currentItem.monthStart <= intern.today && intern.today < currentItem.monthEnd)
 
26
            intern.currentDayStart = intern.today
 
27
        else
 
28
            intern.currentDayStart = currentItem.monthStart
 
29
    }
 
30
 
 
31
    onIncrementCurrentDay: {
 
32
        var t = intern.currentDayStart.addDays(1)
 
33
        if (t < monthEnd) {
 
34
            intern.currentDayStart = t
 
35
        }
 
36
        else if (currentIndex < count - 1) {
 
37
            intern.currentDayStart = t
 
38
            currentIndex = currentIndex + 1
 
39
        }
 
40
    }
 
41
 
 
42
    onDecrementCurrentDay: {
 
43
        var t = intern.currentDayStart.addDays(-1)
 
44
        if (t >= monthStart) {
 
45
            intern.currentDayStart = t
 
46
        }
 
47
        else if (currentIndex > 0) {
 
48
            intern.currentDayStart = t
 
49
            currentIndex = currentIndex - 1
 
50
        }
 
51
    }
 
52
 
12
53
    onGotoNextMonth: {
13
54
        if (monthStart.getMonth() != month) {
14
55
            var i = intern.monthIndex0, m = intern.today.getMonth()
20
61
        }
21
62
    }
22
63
 
 
64
    focus: true
 
65
    Keys.onLeftPressed: decrementCurrentDay()
 
66
    Keys.onRightPressed: incrementCurrentDay()
 
67
 
23
68
    QtObject {
24
69
        id: intern
25
70
 
28
73
        property int monthCount: 49 // months for +-2 years
29
74
 
30
75
        property var today: (new Date()).midnight() // TODO: update at midnight
 
76
        property var currentDayStart: today
31
77
        property int monthIndex0: monthCount / 2
32
78
        property var monthStart0: today.monthStart()
33
79
    }
70
116
                    property var dayStart: gridStart.addDays(index)
71
117
                    property bool isCurrentMonth: (monthStart <= dayStart) && (dayStart < monthEnd)
72
118
                    property bool isToday: dayStart.getTime() == intern.today.getTime()
73
 
                    // property int weekday: (index % 7 + intern.weekstartDay) % 7
74
 
                    // property bool isSunday: weekday == 0
 
119
                    property bool isCurrent: dayStart.getTime() == intern.currentDayStart.getTime()
 
120
                    property int weekday: (index % 7 + intern.weekstartDay) % 7
 
121
                    property bool isSunday: weekday == 0
75
122
                    width: intern.squareUnit
76
123
                    height: intern.squareUnit
77
 
                    Text { // FIXME: Label is seriously less performant than Text
 
124
                    Rectangle {
 
125
                        visible: isSunday
 
126
                        anchors.fill: parent
 
127
                        color: Color.warmGrey
 
128
                        opacity: 0.1
 
129
                    }
 
130
                    Text {
78
131
                        anchors.centerIn: parent
79
132
                        text: dayStart.getDate()
80
133
                        font: themeDummy.font
81
 
                        color: isToday ? "#DD4814" : themeDummy.color
82
 
                            // FIXME: need to get the colors from theme engine
83
 
                        scale: isToday ? 1.5 : 1.
 
134
                        color: isToday ? Color.ubuntuOrange : themeDummy.color
 
135
                        scale: isCurrent ? 1.5 : 1.
84
136
                        opacity: isCurrentMonth ? 1. : 0.3
 
137
                        Behavior on scale {
 
138
                            NumberAnimation { duration: 100 }
 
139
                        }
85
140
                    }
86
 
                    // Component.onCompleted: console.log(dayStart, intern.today, isToday)
 
141
                    // Component.onCompleted: console.log(dayStart, intern.currentDayStart)
87
142
                }
88
143
            }
89
144
        }