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

« back to all changes in this revision

Viewing changes to EventView.qml

  • Committer: Frank Mertens
  • Date: 2013-03-22 01:32:02 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: frank@cyblogic.de-20130322013202-19s6th508vgo971t
Added more complex test case in preparation for integration of the diary view.

To run the tests and load the test data run 'qmlscene calendarTest.qml' once.

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
 
 
10
    signal incrementCurrentDay
 
11
    signal decrementCurrentDay
 
12
 
 
13
    readonly property real visibleHeight: parent.height - y
 
14
 
 
15
    QtObject {
 
16
        id: intern
 
17
        property int currentIndexSaved: 0
 
18
        property int currentIndex: 0
 
19
        property var currentDayStart: (new Date()).midnight()
 
20
    }
 
21
 
 
22
    onCurrentIndexChanged: {
 
23
        var delta = currentIndex - intern.currentIndexSaved
 
24
        if (intern.currentIndexSaved == count - 1 && currentIndex == 0) delta = 1
 
25
        if (intern.currentIndexSaved == 0 && currentIndex == count - 1) delta = -1
 
26
        intern.currentIndexSaved = currentIndex
 
27
        if (delta > 0) incrementCurrentDay()
 
28
        else decrementCurrentDay()
 
29
    }
 
30
 
 
31
    onCurrentDayStartChanged: {
 
32
        if (!moving) intern.currentDayStart = currentDayStart
 
33
    }
 
34
 
 
35
    onMovementEnded: {
 
36
        intern.currentDayStart = currentDayStart
 
37
        intern.currentIndex = currentIndex
 
38
    }
 
39
 
 
40
    preferredHighlightBegin: 0.5
 
41
    preferredHighlightEnd: 0.5
 
42
    highlightRangeMode: PathView.StrictlyEnforceRange
 
43
 
 
44
    path: Path {
 
45
        startX: -eventView.width; startY: eventView.height / 2
 
46
        PathLine { relativeX: eventView.width; relativeY: 0  }
 
47
        PathLine { relativeX: eventView.width; relativeY: 0 }
 
48
        PathLine { relativeX: eventView.width; relativeY: 0 }
 
49
    }
 
50
 
 
51
    snapMode: PathView.SnapOneItem
 
52
 
 
53
    model: 3
 
54
 
 
55
    delegate: DiaryView {
 
56
        dayStart: {
 
57
            if (index == intern.currentIndex) return intern.currentDayStart
 
58
            var previousIndex = intern.currentIndex > 0 ? intern.currentIndex - 1 : 2
 
59
            if (index == previousIndex) return intern.currentDayStart.addDays(-1)
 
60
            return intern.currentDayStart.addDays(1)
 
61
        }
 
62
        width: eventView.width
 
63
        height: eventView.height
 
64
    }
 
65
}