summaryrefslogtreecommitdiffstats
path: root/examples/declarative/loader/Browser.qml
blob: 280273b9021f8aaffcf16f037d8c4a5dae13b200 (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
Rect {
    id: Root
    width: parent.width
    height: parent.height
    FolderListModel {
        id: folders
        nameFilters: [ "*.qml" ]
//        folder: "E:"
    }

    Component {
        id: FolderDelegate
        Rect {
            id: Wrapper
            width: Root.width
            height: NameText.height
            Text {
                id: NameText
                text: fileName
                font.bold: true
                font.size: 12
            }
            MouseRegion {
                id: Mouse
                anchors.fill: parent
                onClicked: {
                    if (folders.isFolder(index)) {
                        folders.folder = filePath;
                    } else {
                        qmlLauncher.launch(filePath);
                    }
                }
            }
            states: [
                State {
                    name: "pressed"
                    when: Mouse.pressed
                    SetProperties { target: Wrapper; color: "#bbbbbb" }
                }
            ]
        }
    }

    Script {
        function up(path) {
            var pos = path.toString().lastIndexOf("/");
            return path.toString().substring(0, pos);
        }
    }

    Rect {
        id: UpButton
        width: 30
        height: UpText.height
        color: "grey"
        MouseRegion { anchors.fill: parent; onClicked: folders.folder = up(folders.folder) }
        Text { id: UpText; text: "Up" }
    }

    Text { anchors.left: UpButton.right; text: folders.folder }

    ListView {
        anchors.top: UpButton.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        model: folders
        delegate: FolderDelegate
        clip: true
    }
}