Merge branch 'develop'
[lichviet] / qml / DatePicker / component / Reel.qml
1 import QtQuick 1.0
2
3 Rectangle {
4     id: reel    
5
6     property alias interactive: path.interactive
7     property int index: 0
8     property bool moving: false
9     property ListModel model    
10     property Component delegate
11     property int itemsShown: 4
12     property bool autoClose: true
13     property alias closingDelay: clippingTimer.interval
14     property int closingTimeout: 800
15
16     function open() { focus = true; clip = false }
17     function close() { clip = true }
18
19     function shiftZ(obj, delta) {
20         if (typeof obj.z != 'undefined') obj.z += delta
21         if (obj.parent) shiftZ(obj.parent, delta) // Set z recursively to parent
22     }
23
24     width: 100
25     height: 100
26     color: "transparent"
27     clip: true
28     // Close reel when the focus is lost
29     onFocusChanged: if (!focus) close()
30     // Bring to front if not clipped
31
32
33     onIndexChanged: path.currentIndex = reel.index
34
35     PathView {
36         id: path
37         width: parent.width
38         height: (pathItemCount-1)*parent.height
39         pathItemCount: parent.itemsShown+1
40         clip: true
41         anchors.centerIn: parent
42         model: parent.model
43         delegate: reel.delegate
44
45         preferredHighlightBegin: 0.5
46         preferredHighlightEnd: 0.5
47         highlightRangeMode: PathView.StrictlyEnforceRange
48         focus: false
49
50         path: Path {
51             startX: path.x+path.width/2; startY: 1-reel.height/2
52             PathLine {x: path.x+path.width/2; y: path.height+reel.height/2-1}
53         }
54         onMovementStarted: {}
55         onMovementEnded: {
56             reel.index = path.currentIndex;
57             parent.mouseoff()
58         }
59
60         Timer {
61             id: clippingTimer
62             repeat: false; interval: reel.closingTimeout;
63             triggeredOnStart: false; onTriggered: reel.close()
64         }        
65     }
66 }