~pkunal-parmar/ubuntu-calendar-app/Minor-Performance

« back to all changes in this revision

Viewing changes to EventView.qml

  • Committer: mhall119
  • Date: 2013-07-24 21:24:52 UTC
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: mhall119@ubuntu.com-20130724212452-y181o9l9f4v3gm2z
Add individual contributors to debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import Ubuntu.Components 0.1
 
3
import "dateExt.js" as DateExt
 
4
 
 
5
PathView {
 
6
    id: eventView
 
7
 
 
8
    property var currentDayStart: (new Date()).midnight()
 
9
    property string eventViewType: "DiaryView.qml";
 
10
 
 
11
    signal incrementCurrentDay
 
12
    signal decrementCurrentDay
 
13
 
 
14
    signal newEvent()
 
15
 
 
16
    QtObject {
 
17
        id: intern
 
18
        property int currentIndexSaved: 0
 
19
        property int currentIndex: 0
 
20
        property var currentDayStart: (new Date()).midnight()
 
21
    }
 
22
 
 
23
    onCurrentIndexChanged: {
 
24
        var delta = currentIndex - intern.currentIndexSaved
 
25
        if (intern.currentIndexSaved == count - 1 && currentIndex == 0) delta = 1
 
26
        if (intern.currentIndexSaved == 0 && currentIndex == count - 1) delta = -1
 
27
        intern.currentIndexSaved = currentIndex
 
28
        if (delta > 0) incrementCurrentDay()
 
29
        else decrementCurrentDay()
 
30
    }
 
31
 
 
32
    onCurrentDayStartChanged: {
 
33
        if (!moving) intern.currentDayStart = currentDayStart
 
34
    }
 
35
 
 
36
    onMovementEnded: {
 
37
        intern.currentDayStart = currentDayStart
 
38
        intern.currentIndex = currentIndex
 
39
    }
 
40
 
 
41
    preferredHighlightBegin: 0.5
 
42
    preferredHighlightEnd: 0.5
 
43
    highlightRangeMode: PathView.StrictlyEnforceRange
 
44
 
 
45
    path: Path {
 
46
        startX: -eventView.width; startY: eventView.height / 2
 
47
        PathLine { relativeX: eventView.width; relativeY: 0 }
 
48
        PathLine { relativeX: eventView.width; relativeY: 0 }
 
49
        PathLine { relativeX: eventView.width; relativeY: 0 }
 
50
    }
 
51
 
 
52
    snapMode: PathView.SnapOneItem
 
53
 
 
54
    model: 3
 
55
 
 
56
    delegate: Loader {
 
57
        id: eventViewDelegate
 
58
 
 
59
        width: eventView.width
 
60
        height: eventView.height
 
61
        source: eventView.eventViewType
 
62
 
 
63
        property var dayStart: {
 
64
            if (index == intern.currentIndex) return intern.currentDayStart
 
65
            var previousIndex = intern.currentIndex > 0 ? intern.currentIndex - 1 : 2
 
66
            if (index === previousIndex) return intern.currentDayStart.addDays(-1)
 
67
            return intern.currentDayStart.addDays(1)
 
68
        }
 
69
 
 
70
        onLoaded: {
 
71
            item.newEvent.connect(eventView.newEvent);
 
72
        }
 
73
 
 
74
        Binding {
 
75
            target: item
 
76
            property: "dayStart"
 
77
            value: eventViewDelegate.dayStart
 
78
        }
 
79
 
 
80
        //share state from delegate to eventView, if state change is from current delegate
 
81
        Binding {
 
82
            target: eventView
 
83
            property: "state"
 
84
            value: eventViewDelegate.item.state;
 
85
            when: index == eventView.currentIndex
 
86
        }
 
87
 
 
88
        //share state from eventview to delegate, so that all delegate share the same state
 
89
        Binding{
 
90
            target: eventViewDelegate.item
 
91
            property: "state"
 
92
            value: eventView.state
 
93
        }
 
94
    }
 
95
}