summaryrefslogtreecommitdiffstats
path: root/examples/declarative/loader/Browser.qml
blob: 96c2a760a85cf4ab5474f8f9e73ef10992f1400c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import Qt 4.6

Rect {
    id: Root
    width: parent.width
    height: parent.height
    color: activePalette.base
    FolderListModel {
        id: folders
        nameFilters: [ "*.qml" ]
//        folder: "E:"
    }

    Palette { id: activePalette; colorGroup: "Active" }

    Component {
        id: FolderDelegate
        Rect {
            id: Wrapper
            width: Root.width
            height: 32
            color: activePalette.base
            Rect {
                id: Highlight; visible: false
                anchors.fill: parent
                gradient: Gradient {
                    GradientStop { id: t1; position: 0.0; color: activePalette.highlight }
                    GradientStop { id: t2; position: 1.0; color: activePalette.lighter(activePalette.highlight) }
                }
            }
            Item {
                width: 32; height: 32
                Image { source: "images/fileopen.png"; anchors.centerIn: parent; visible: folders.isFolder(index)}
            }
            Text {
                id: NameText
                anchors.fill: parent; vAlign: "AlignVCenter"
                text: fileName; anchors.leftMargin: 32
                font.size: 10
                color: activePalette.windowText
            }
            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: Highlight; visible: true }
                    SetProperties { target: NameText; color: activePalette.highlightedText }
                }
            ]
        }
    }

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

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

    Rect {
        id: TitleBar
        width: parent.width
        height: 32
        color: activePalette.button; border.color: activePalette.mid

        Rect {
            id: UpButton
            width: 30
            height: TitleBar.height
            border.color: activePalette.mid; color: "transparent"
            MouseRegion { anchors.fill: parent; onClicked: folders.folder = up(folders.folder) }
            Image { anchors.centerIn: parent; source: "images/up.png" }
        }

        Text {
            anchors.left: UpButton.right; anchors.right: parent.right; height: parent.height
            anchors.leftMargin: 4; anchors.rightMargin: 4
            text: folders.folder; color: activePalette.buttonText
            elide: "ElideLeft"; hAlign: "AlignRight"; vAlign: "AlignVCenter"
        }
    }
}