~artmello/ubuntu-calendar-app/ubuntu-calendar-app-fix_1556946

« back to all changes in this revision

Viewing changes to MonthComponentDateDelegate.qml

Add lunar calendar support. Fixes: https://bugs.launchpad.net/bugs/1513099.

Approved by Jenkins Bot, Alan Pope .

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import QtQuick 2.4
2
2
import Ubuntu.Components 1.3
 
3
import "./3rd-party/lunar.js" as Lunar
3
4
 
4
5
Item{
5
6
    id: dateRootItem
8
9
    property bool isCurrentMonth;
9
10
    property bool isToday;
10
11
    property bool showEvent;
 
12
    property bool showLunarCalendar;
11
13
    property alias fontSize: dateLabel.font.pixelSize
12
14
 
13
15
    property bool isSelected: false
48
50
    }
49
51
 
50
52
    Loader{
 
53
        sourceComponent: showLunarCalendar ? reservedFiled : undefined
 
54
        onSourceComponentChanged: {
 
55
            if (item != undefined) {
 
56
                item.reservedData = Qt.binding(function(){
 
57
                    var lunarDate = Lunar.calendar.solar2lunar(intern.monthStartYear,
 
58
                                                               intern.monthStartMonth + 1,
 
59
                                                               intern.monthStartDate + index)
 
60
                    if (lunarDate.isTerm) {
 
61
                        return {"lunarText": lunarDate.Term, "isTerm" :lunarDate.isTerm};
 
62
                    } else {
 
63
                        return {"lunarText": lunarDate.IDayCn, "isTerm" :lunarDate.isTerm};
 
64
                    }
 
65
                })
 
66
            }
 
67
 
 
68
            width = Qt.binding( function() { return units.gu(0.8)})
 
69
            height = Qt.binding( function() { return width })
 
70
            anchors.horizontalCenter = Qt.binding( function() { return  parent.horizontalCenter })
 
71
            anchors.top = Qt.binding( function() { return parent.verticalCenter })
 
72
            anchors.topMargin = Qt.binding( function() {
 
73
                return (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height)/ 4.0 + units.gu(0.25)
 
74
            });
 
75
        }
 
76
    }
 
77
 
 
78
    //this component is reserved for extra information display
 
79
    Component {
 
80
        id: reservedFiled
 
81
        Label {
 
82
            id: reservedLabel
 
83
            property var reservedData
 
84
            onReservedDataChanged: {
 
85
                text = reservedData.lunarText
 
86
                if (reservedData.isTerm)
 
87
                    color = "red";
 
88
            }
 
89
 
 
90
            horizontalAlignment: Text.AlignHCenter
 
91
            fontSize: root.subLabelFontSize
 
92
            color: "#5D5D5D"
 
93
        }
 
94
    }
 
95
 
 
96
    Loader{        
51
97
        sourceComponent: showEvent ? eventIndicatorComp : undefined
52
98
        onSourceComponentChanged: {
53
99
            width = Qt.binding( function() { return units.gu(0.8)})
55
101
            anchors.horizontalCenter = Qt.binding( function() { return  parent.horizontalCenter })
56
102
            anchors.top = Qt.binding( function() { return parent.verticalCenter })
57
103
            anchors.topMargin = Qt.binding( function() {
58
 
                var w = (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height)/1.3
59
 
                return (w/2) + units.gu(0.1)
 
104
                if (showLunarCalendar) {
 
105
                    return (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height) / 2 + units.gu(1.5)
 
106
                } else {
 
107
                    var w = (dateRootItem.height > dateRootItem.width ? dateRootItem.width :dateRootItem.height)/1.3
 
108
                    return (w/2) + units.gu(0.1)
 
109
                }
60
110
            });
61
111
        }
62
112
    }