-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCarousel.qml
38 lines (32 loc) · 983 Bytes
/
Carousel.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import QtQuick 2.0
// A carousel is a PathView that goes horizontally and keeps its
// current item in the center.
PathView {
id: root
property int itemWidth // set this on the calling site
readonly property int pathWidth: pathItemCount * itemWidth
signal itemSelected
// Handle keys
Keys.onLeftPressed: decrementCurrentIndex()
Keys.onRightPressed: incrementCurrentIndex()
Keys.onPressed: {
if (api.keys.isAccept(event)) {
event.accepted = true;
itemSelected();
}
}
// Center the current item
snapMode: PathView.SnapOneItem
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
// Create and position the path
pathItemCount: Math.ceil(width / itemWidth) + 2
path: Path {
startX: (root.width - root.pathWidth) / 2
startY: root.height / 2
PathLine {
x: root.path.startX + root.pathWidth
y: root.path.startY
}
}
}