~renatofilho/ubuntu-calendar-app/optimize

« back to all changes in this revision

Viewing changes to DayView.qml

  • Committer: Renato Araujo Oliveira Filho
  • Date: 2016-01-25 17:40:22 UTC
  • Revision ID: renato.filho@canonical.com-20160125174022-yry5mjrs0ghyhivz
Optimize views.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
 */
18
18
 
19
 
import QtQuick 2.3
20
 
import Ubuntu.Components 1.1
 
19
import QtQuick 2.4
 
20
import Ubuntu.Components 1.3
21
21
import "dateExt.js" as DateExt
22
22
import "ViewType.js" as ViewType
23
23
 
25
25
    id: dayViewPage
26
26
    objectName: "dayViewPage"
27
27
 
28
 
    property var currentDay: new Date()
29
 
    property bool isCurrentPage: false
 
28
    property var anchorDate: new Date()
 
29
    readonly property var currentDate: dayViewPath.currentItem.startDay
30
30
 
31
31
    signal dateSelected(var date);
32
32
 
39
39
        iconName: "calendar-today"
40
40
        text: i18n.tr("Today")
41
41
        onTriggered: {
42
 
            currentDay = new Date()
 
42
            dayViewPath.scrollToBegginer()
 
43
            anchorDate = new Date()
43
44
        }
44
45
    }
45
46
 
57
58
            id:monthYear
58
59
            objectName:"monthYearLabel"
59
60
            fontSize: "x-large"
60
 
            text: currentDay.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy"))
 
61
            text: currentDate.toLocaleString(Qt.locale(),i18n.tr("MMMM yyyy"))
61
62
            font.capitalization: Font.Capitalize
62
63
        }
63
64
    }
66
67
        id: dayViewPath
67
68
        objectName: "dayViewPath"
68
69
 
69
 
        property var startDay: currentDay
70
70
        //This is used to scroll all view together when currentItem scrolls
71
71
        property var childContentY;
72
72
 
73
73
        anchors.fill: parent
74
74
 
75
 
        onNextItemHighlighted: {
76
 
            //next day
77
 
            currentDay = currentDay.addDays(1);
78
 
        }
79
 
 
80
 
        onPreviousItemHighlighted: {
81
 
            //previous day
82
 
            currentDay = currentDay.addDays(-1);
83
 
        }
84
 
 
85
 
        delegate: Loader {
 
75
        delegate: TimeLineBaseComponent {
 
76
            id: timeLineView
 
77
            objectName: "DayComponent-"+index
 
78
 
86
79
            width: parent.width
87
80
            height: parent.height
88
 
            asynchronous: !dayViewPath.isCurrentItem
89
 
            sourceComponent: delegateComponent
90
 
 
91
 
            Component {
92
 
                id: delegateComponent
93
 
 
94
 
                TimeLineBaseComponent {
95
 
                    id: timeLineView
96
 
                    objectName: "DayComponent-"+index
97
 
 
98
 
                    type: ViewType.ViewTypeDay
99
 
                    anchors.fill: parent
100
 
 
101
 
                    isActive: parent.PathView.isCurrentItem
102
 
                    contentInteractive: parent.PathView.isCurrentItem
103
 
                    startDay: dayViewPath.startDay.addDays(dayViewPath.indexType(index))
104
 
                    keyboardEventProvider: dayViewPath
105
 
 
106
 
                    Component.onCompleted: {
107
 
                        if(dayViewPage.isCurrentPage){
108
 
                            timeLineView.scrollToCurrentTime();
109
 
                        }
110
 
                    }
111
 
 
112
 
                    Connections{
113
 
                        target: dayViewPage
114
 
                        onIsCurrentPageChanged:{
115
 
                            if(dayViewPage.isCurrentPage){
116
 
                                timeLineView.scrollToCurrentTime();
117
 
                            }
118
 
                        }
119
 
                    }
120
 
 
121
 
                    //get contentY value from PathView, if its not current Item
122
 
                    Binding{
123
 
                        target: timeLineView
124
 
                        property: "contentY"
125
 
                        value: dayViewPath.childContentY;
126
 
                        when: !parent.PathView.isCurrentItem
127
 
                    }
128
 
 
129
 
                    //set PathView's contentY property, if its current item
130
 
                    Binding{
131
 
                        target: dayViewPath
132
 
                        property: "childContentY"
133
 
                        value: contentY
134
 
                        when: parent.PathView.isCurrentItem
135
 
                    }
136
 
                }
 
81
 
 
82
            type: ViewType.ViewTypeDay
 
83
            isActive: PathView.isCurrentItem
 
84
            contentInteractive: PathView.isCurrentItem
 
85
            startDay: anchorDate.addDays(dayViewPath.loopCurrentIndex + dayViewPath.indexType(index))
 
86
            keyboardEventProvider: dayViewPath
 
87
 
 
88
            Component.onCompleted: {
 
89
                if(dayViewPage.active){
 
90
                    timeLineView.scrollToCurrentTime();
 
91
                }
 
92
            }
 
93
 
 
94
            Connections{
 
95
                target: dayViewPage
 
96
                onActiveChanged: {
 
97
                    if(dayViewPage.active){
 
98
                        timeLineView.scrollToCurrentTime();
 
99
                    }
 
100
                }
 
101
            }
 
102
 
 
103
            //get contentY value from PathView, if its not current Item
 
104
            Binding{
 
105
                target: timeLineView
 
106
                property: "contentY"
 
107
                value: dayViewPath.childContentY;
 
108
                when: !parent.PathView.isCurrentItem
 
109
            }
 
110
 
 
111
            //set PathView's contentY property, if its current item
 
112
            Binding{
 
113
                target: dayViewPath
 
114
                property: "childContentY"
 
115
                value: contentY
 
116
                when: parent.PathView.isCurrentItem
137
117
            }
138
118
        }
139
119
    }