~pkunal-parmar/ubuntu-calendar-app/NewDayView

« back to all changes in this revision

Viewing changes to AllDayEventComponent.qml

  • Committer: Kunal Parmar
  • Date: 2014-11-15 08:02:45 UTC
  • Revision ID: pkunal.parmar@gmail.com-20141115080245-9f093ak1owlh5tl8
new day and week view

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import "dateExt.js" as DateExt
23
23
import "ViewType.js" as ViewType
24
24
 
25
 
Item {
 
25
Row {
26
26
    id: root
27
27
 
 
28
    property var startDay: DateExt.today();
 
29
    property int type: ViewType.ViewTypeWeek
28
30
    property var allDayEvents;
29
 
    property var startDay: DateExt.today();
30
31
    property var model;
31
32
 
32
 
    property int type: ViewType.ViewTypeWeek
 
33
    width: parent.width
 
34
    height: units.gu(5)
33
35
 
34
36
    function getAllDayEvents(startDate, endDate) {
35
37
        var map = {};
60
62
 
61
63
    Repeater{
62
64
        model: type == ViewType.ViewTypeWeek ? 7 : 1
63
 
        delegate: Button {
 
65
        delegate: Item {
64
66
            id: allDayButton
65
67
 
66
68
            property var events;
67
 
            gradient: UbuntuColors.orangeGradient
68
 
 
69
 
            x: type === ViewType.ViewTypeWeek ? root.width/7*index : 0
70
 
            height: units.gu(3)
71
 
            clip: true
72
 
            width: parent.width/ (type == ViewType.ViewTypeWeek ? 7 : 1)
73
 
            visible: !allDayButton.events || allDayButton.events.length === 0 ? false : true
74
 
 
75
 
            onClicked: {
76
 
                if(!allDayButton.events || allDayButton.events.length === 0) {
77
 
                    return;
78
 
                }
79
 
 
80
 
                if(type == ViewType.ViewTypeWeek) {
81
 
                    PopupUtils.open(popoverComponent, root,{"events": allDayButton.events})
82
 
                } else {
83
 
                    if( allDayButton.events.length > 1 ) {
 
69
 
 
70
            height: units.gu(5)
 
71
            width: parent.width / (type == ViewType.ViewTypeWeek ? 7 : 1)
 
72
 
 
73
            MouseArea {
 
74
                anchors.fill: parent
 
75
                onClicked: {
 
76
                    if(!allDayButton.events || allDayButton.events.length === 0) {
 
77
                        return;
 
78
                    }
 
79
 
 
80
                    if(type == ViewType.ViewTypeWeek) {
84
81
                        PopupUtils.open(popoverComponent, root,{"events": allDayButton.events})
85
82
                    } else {
86
 
                        pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":allDayButton.events[0],"model": root.model});
 
83
                        if( allDayButton.events.length > 1 ) {
 
84
                            PopupUtils.open(popoverComponent, root,{"events": allDayButton.events})
 
85
                        } else {
 
86
                            pageStack.push(Qt.resolvedUrl("EventDetails.qml"),{"event":allDayButton.events[0],"model": root.model});
 
87
                        }
87
88
                    }
88
89
                }
89
90
            }
90
91
 
 
92
            Loader {
 
93
                id: eventLabelLoader
 
94
                anchors.fill: parent
 
95
                sourceComponent : !allDayButton.events || allDayButton.events.length === 0 ? undefined : eventComponent
 
96
            }
 
97
 
 
98
            Component{
 
99
                id: eventComponent
 
100
                Label {
 
101
                    verticalAlignment: Text.AlignVCenter
 
102
                    horizontalAlignment: Text.AlignHCenter
 
103
                }
 
104
            }
 
105
 
 
106
            Loader{
 
107
                objectName: "divider"
 
108
                height: parent.height
 
109
                width: units.gu(0.15)
 
110
                sourceComponent: root.type == ViewType.ViewTypeWeek ? dividerComponent : undefined
 
111
            }
 
112
 
 
113
            Component {
 
114
                id: dividerComponent
 
115
                Rectangle{
 
116
                    anchors.fill: parent
 
117
                    color: "#e5e2e2"
 
118
                }
 
119
            }
 
120
 
91
121
            Connections{
92
122
                target: root
93
123
                onAllDayEventsChanged:{
97
127
                    events = allDayEvents[key];
98
128
 
99
129
                    if(!events || events.length === 0) {
100
 
                        text = "";
 
130
                        //text = "";
101
131
                        return;
102
132
                    }
103
133
 
106
136
                        // on a given day. "Ev." is short form for "Events".
107
137
                        // Please keep the translation of "Ev." to 3 characters only, as the week view
108
138
                        // where it's shown has limited space
109
 
                        text =  i18n.tr("%1 ev.").arg(events.length)
 
139
                        eventLabelLoader.item.text =  i18n.tr("%1 ev.").arg(events.length)
110
140
                    } else {
111
141
                        if( events.length > 1) {
112
142
                           // TRANSLATORS: the argument refers to the number of all day events
113
 
                           text = i18n.tr("%1 all day event", "%1 all day events", events.length).arg(events.length)
 
143
                           eventLabelLoader.item.text = i18n.tr("%1 all day event", "%1 all day events", events.length).arg(events.length)
114
144
                        } else {
115
 
                            text = events[0].displayLabel;
 
145
                            eventLabelLoader.item.text = events[0].displayLabel;
116
146
                        }
117
147
                    }
118
148
                }