summaryrefslogtreecommitdiffstats
path: root/examples/declarative/parallax/qml/ParallaxView.qml
blob: e869a215fb89fa79602c277d57de5250b12c7220 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import Qt 4.7

Item {
    id: root

    property alias background: background.source
    default property alias content: visualModel.children
    property int currentIndex: 0

    Image {
        id: background
        fillMode: Image.TileHorizontally
        x: -list.contentX / 2
        width: Math.max(list.contentWidth, parent.width)
    }

    ListView {
        id: list

        currentIndex: root.currentIndex
        onCurrentIndexChanged: root.currentIndex = currentIndex

        orientation: Qt.Horizontal
        boundsBehavior: Flickable.DragOverBounds
        anchors.fill: parent
        model: VisualItemModel { id: visualModel }

        highlightRangeMode: ListView.StrictlyEnforceRange
        snapMode: ListView.SnapOneItem
    }

    ListView {
        id: selector

        Rectangle {
            color: "#60FFFFFF"
            x: -10; y: -10; radius: 10; z: -1
            width: parent.width + 20; height: parent.height + 20
        }
        currentIndex: root.currentIndex
        onCurrentIndexChanged: root.currentIndex = currentIndex

        height: 50
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        width: Math.min(count * 50, parent.width - 20)
        interactive: width == parent.width - 20
        orientation: Qt.Horizontal

        delegate: Item {
            width: 50; height: 50
            id: delegateRoot

            Image {
                id: image
                source: modelData.icon
                smooth: true
                scale: 0.8
            }

            MouseArea {
                anchors.fill: parent
                onClicked: { root.currentIndex = index }
            }

            states: State {
                name: "Selected"
                when: delegateRoot.ListView.isCurrentItem == true
                PropertyChanges {
                    target: image
                    scale: 1
                    y: -5
                }
            }
            transitions: Transition {
                NumberAnimation {
                    properties: "scale,y"
                }
             }
        }
        model: visualModel.children
    }
}