1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
import QtQuick 2.4
import Ubuntu.Components 1.3
import "./3rd-party/lunar.js" as Lunar
Item{
id: dateRootItem
property int date;
property bool isCurrentMonth;
property bool isToday;
property bool showEvent;
property bool showLunarCalendar;
property alias fontSize: dateLabel.font.pixelSize
property bool isSelected: false
Loader {
sourceComponent: (isToday && isCurrentMonth) || isSelected ? highLightComp : undefined
onSourceComponentChanged: {
width = Qt.binding( function() {
var width = dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height
return ( width / 1.3 );
});
height = Qt.binding ( function() { return width} );
anchors.centerIn = Qt.binding( function() { return dateLabel});
}
}
Label {
id: dateLabel
anchors.centerIn: parent
text: date
fontSize: root.dateLabelFontSize
color: {
if( isCurrentMonth ) {
if( isToday || isSelected ) {
"white"
} else {
"#5D5D5D"
}
} else {
if(isSelected) {
"white"
} else {
"#AEA79F"
}
}
}
}
Loader{
sourceComponent: showLunarCalendar ? reservedFiled : undefined
onSourceComponentChanged: {
if (item != undefined) {
item.reservedData = Qt.binding(function(){
var lunarDate = Lunar.calendar.solar2lunar(intern.monthStartYear,
intern.monthStartMonth + 1,
intern.monthStartDate + index)
if (lunarDate.isTerm) {
return {"lunarText": lunarDate.Term, "isTerm" :lunarDate.isTerm};
} else {
return {"lunarText": lunarDate.IDayCn, "isTerm" :lunarDate.isTerm};
}
})
}
width = Qt.binding( function() { return units.gu(0.8)})
height = Qt.binding( function() { return width })
anchors.horizontalCenter = Qt.binding( function() { return parent.horizontalCenter })
anchors.top = Qt.binding( function() { return parent.verticalCenter })
anchors.topMargin = Qt.binding( function() {
return (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height)/ 4.0 + units.gu(0.25)
});
}
}
//this component is reserved for extra information display
Component {
id: reservedFiled
Label {
id: reservedLabel
property var reservedData
onReservedDataChanged: {
text = reservedData.lunarText
if (reservedData.isTerm)
color = "red";
}
horizontalAlignment: Text.AlignHCenter
fontSize: root.subLabelFontSize
color: "#5D5D5D"
}
}
Loader{
sourceComponent: showEvent ? eventIndicatorComp : undefined
onSourceComponentChanged: {
width = Qt.binding( function() { return units.gu(0.8)})
height = Qt.binding( function() { return width })
anchors.horizontalCenter = Qt.binding( function() { return parent.horizontalCenter })
anchors.top = Qt.binding( function() { return parent.verticalCenter })
anchors.topMargin = Qt.binding( function() {
if (showLunarCalendar) {
return (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height) / 2 + units.gu(1.5)
} else {
var w = (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height)/1.3
return (w/2) + units.gu(0.1)
}
});
}
}
Component{
id: eventIndicatorComp
Rectangle {
anchors.fill: parent
radius: height/2
color: "black"
}
}
Component{
id: highLightComp
UbuntuShape{
color: {
if( isToday && !isSelected ) {
"#DD4814"
} else {
"gray"
}
}
Rectangle{
anchors.fill: parent
anchors.margins: units.gu(0.5)
color: isToday ? "#DD4814" : "darkgray"
}
}
}
MouseArea {
anchors.fill: parent
onPressAndHold: {
if( isSelected ) {
var selectedDate = new Date();
selectedDate.setFullYear(intern.monthStartYear)
selectedDate.setMonth(intern.monthStartMonth + 1)
selectedDate.setDate(date)
selectedDate.setMinutes(60, 0, 0)
pageStack.push(Qt.resolvedUrl("NewEvent.qml"), {"date":selectedDate, "model":eventModel});
}
}
onClicked: {
var selectedDate = new Date(intern.monthStartYear,
intern.monthStartMonth,
intern.monthStartDate + index, 0, 0, 0, 0)
if( isYearView ) {
//If yearView is clicked then open selected MonthView
root.monthSelected(selectedDate);
} else {
if( isSelected ) {
//If monthView is clicked then open selected DayView
root.dateSelected(selectedDate);
} else {
intern.selectedIndex = index
root.dateHighlighted(selectedDate)
}
}
}
}
}
|