~nikwen/ubuntu-calendar-app/fix-standalone-month-name-i18n

« back to all changes in this revision

Viewing changes to MonthView.qml

  • Committer: Niklas Wenzel
  • Date: 2016-04-06 20:19:13 UTC
  • mfrom: (734.1.82 trunk)
  • Revision ID: nikwen.developer@gmail.com-20160406201913-epdb53uij14ueri1
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
import QtQuick 2.4
19
19
import Ubuntu.Components 1.3
 
20
 
20
21
import "dateExt.js" as DateExt
21
22
import "colorUtils.js" as Color
22
23
import "./3rd-party/lunar.js" as Lunar
23
24
 
24
 
Page {
 
25
PageWithBottomEdge {
25
26
    id: monthViewPage
26
27
    objectName: "monthViewPage"
27
28
 
28
 
    property var currentMonth: DateExt.today();
 
29
    property var anchorDate: DateExt.today();
 
30
    readonly property var firstDayOfAnchorDate: new Date(anchorDate.getFullYear(),
 
31
                                                         anchorDate.getMonth(),
 
32
                                                         1,
 
33
                                                         0, 0, 0)
 
34
    readonly property var currentDate: monthViewPath.currentItem.indexDate
 
35
 
29
36
    property var selectedDay;
 
37
    property var highlightedDate;
 
38
    property bool displayLunarCalendar: false
30
39
 
31
40
    signal dateSelected(var date);
32
 
    signal dateHighlighted(var date);
33
41
 
34
42
    Keys.forwardTo: [monthViewPath]
 
43
    createEventAt: highlightedDate ? highlightedDate : currentDate
 
44
    onAnchorDateChanged: monthViewPath.scrollToBegginer()
35
45
 
36
46
    Action {
37
47
        id: calendarTodayAction
39
49
        iconName: "calendar-today"
40
50
        text: i18n.tr("Today")
41
51
        onTriggered: {
42
 
            currentMonth = new Date().midnight()
 
52
            anchorDate = new Date().midnight()
43
53
        }
44
54
    }
45
55
 
49
59
        leadingActionBar.actions: tabs.tabsAction
50
60
        trailingActionBar.actions: [
51
61
            calendarTodayAction,
52
 
            commonHeaderActions.newEventAction,
53
62
            commonHeaderActions.showCalendarAction,
54
63
            commonHeaderActions.reloadAction,
55
64
            commonHeaderActions.syncCalendarAction,
56
65
            commonHeaderActions.settingsAction
57
66
        ]
58
 
 
59
 
        // TRANSLATORS: This string is used in the header of the month, week and day views.
60
 
        // %1 is going to be replaced by the month name, %2 by the year.
61
 
        title: i18n.tr("%1 %2").arg(Qt.locale().standaloneMonthName(currentMonth.getMonth(), Locale.LongFormat)).arg(currentMonth.getFullYear())
62
 
 
 
67
        title: {
 
68
            if (displayLunarCalendar) {
 
69
                var year = currentDate.getFullYear()
 
70
                var month = currentDate.getMonth()
 
71
                var day = Math.floor(Date.daysInMonth(year, month) / 2.0)
 
72
                var lunarDate = Lunar.calendar.solar2lunar(year, month + 1, day)
 
73
                return i18n.tr("%1 %2").arg(lunarDate .IMonthCn).arg(lunarDate.gzYear)
 
74
            } else {
 
75
               // TRANSLATORS: This string is used in the header of the month, week and day views.
 
76
               // %1 is going to be replaced by the month name, %2 by the year.
 
77
               return i18n.tr("%1 %2").arg(Qt.locale().standaloneMonthName(currentDate.getMonth(), Locale.LongFormat)).arg(currentDate.getFullYear())
 
78
            }
 
79
        }
63
80
        flickable: null
64
81
    }
65
82
 
67
84
        id: monthViewPath
68
85
        objectName: "monthViewPath"
69
86
 
70
 
        property var startMonth: currentMonth;
71
 
 
72
87
        anchors {
73
88
            fill: parent
74
89
            topMargin: header.height
75
 
        }
76
 
 
77
 
        onNextItemHighlighted: {
78
 
            nextMonth();
79
 
        }
80
 
 
81
 
        onPreviousItemHighlighted: {
82
 
            previousMonth();
83
 
        }
84
 
 
85
 
        function nextMonth() {
86
 
            currentMonth = addMonth(currentMonth, 1);
87
 
        }
88
 
 
89
 
        function previousMonth() {
90
 
            currentMonth = addMonth(currentMonth, -1);
91
 
        }
92
 
 
93
 
        function addMonth(date,month) {
94
 
            return  new Date(date.getFullYear(), date.getMonth() + month, 1, 0, 0, 0);
95
 
        }
96
 
 
97
 
        delegate: Loader {
 
90
            bottomMargin: monthViewPage.bottomEdgeHeight
 
91
        }
 
92
 
 
93
        delegate: MonthWithEventsComponent {
 
94
            property var indexDate: firstDayOfAnchorDate.addMonths(monthViewPath.loopCurrentIndex + monthViewPath.indexType(index))
 
95
 
 
96
            currentMonth: indexDate.getMonth()
 
97
            currentYear: indexDate.getFullYear()
 
98
            displayLunarCalendar: monthViewPage.displayLunarCalendar
 
99
 
 
100
            autoUpdate: monthViewPage.tabSelected
 
101
            modelFilter: eventModel.filter
98
102
            width: parent.width - units.gu(4)
99
103
            height: parent.height
100
 
 
101
 
            sourceComponent: delegateComponent
102
 
            asynchronous: index !== monthViewPath.currentIndex
103
 
 
104
 
            Component {
105
 
                id: delegateComponent
106
 
 
107
 
                MonthComponent {
108
 
                    isCurrentItem: index === monthViewPath.currentIndex
109
 
 
110
 
                    showEvents: true
111
 
 
112
 
                    displayWeekNumber: mainView.displayWeekNumber
113
 
                    displayLunarCalendar: mainView.displayLunarCalendar
114
 
                    anchors.fill: parent
115
 
 
116
 
                    currentMonth: monthViewPath.addMonth(monthViewPath.startMonth,
117
 
                                                         monthViewPath.indexType(index));
118
 
 
119
 
                    selectedDay: monthViewPage.selectedDay
120
 
                    isYearView: false
121
 
 
122
 
                    onDateSelected: {
123
 
                        monthViewPage.dateSelected(date);
124
 
                    }
125
 
 
126
 
                    onDateHighlighted: {
127
 
                        monthViewPage.dateHighlighted(date);
128
 
                    }
129
 
                }
 
104
            isCurrentItem: PathView.isCurrentItem
 
105
            isActive: !monthViewPath.moving && !monthViewPath.flicking
 
106
            displayWeekNumber: mainView.displayWeekNumber
 
107
            highlightedDate: monthViewPage.highlightedDate
 
108
            isYearView: false
 
109
 
 
110
            onDateSelected: {
 
111
                monthViewPage.dateSelected(date);
 
112
            }
 
113
            onDateHighlighted: {
 
114
                monthViewPage.highlightedDate = date
130
115
            }
131
116
        }
132
117
    }
133
 
 
134
 
    Component.onCompleted: {
135
 
        pageHeader.title = Qt.binding(function(){
136
 
            if(mainView.displayLunarCalendar){
137
 
                var year = currentMonth.getFullYear()
138
 
                var month = currentMonth.getMonth()
139
 
                var day = Math.floor(Date.daysInMonth(year, month) / 2.0)
140
 
                var lunarDate = Lunar.calendar.solar2lunar( year, month + 1, day)
141
 
                return i18n.tr("%1 %2").arg(lunarDate .IMonthCn).arg(lunarDate.gzYear)
142
 
            } else {
143
 
                // TRANSLATORS: this is a time formatting string,
144
 
                // see http://qt-project.org/doc/qt-5/qml-qtqml-date.html#details for valid expressions.
145
 
                // It's used in the header of the month and week views
146
 
                var monthName = currentMonth.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy"))
147
 
                return monthName[0].toUpperCase() + monthName.substr(1, monthName.length - 1)
148
 
            }
149
 
        })
150
 
    }
151
118
}