summaryrefslogtreecommitdiffstats
path: root/examples/declarative/xmldata/daringfireball.qml
blob: a1df80948e233ed42754de5f2991a9274ded841a (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
import Qt 4.7

Rectangle {
    color: "white"
    width: 600; height: 600

    XmlListModel {
        id: feedModel
        source: "http://daringfireball.net/index.xml"
        query: "/feed/entry"
        namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
        XmlRole { name: "title"; query: "title/string()" }
        XmlRole { name: "tagline"; query: "author/name/string()" }
        XmlRole { name: "content"; query: "content/string()" }
    }

    Component {
        id: feedDelegate
        Item {
            height: childrenRect.height + 20
            Text {
                id: titleText
                x: 10
                text: title; font.bold: true
            }
            Text {
                anchors { left: titleText.right; leftMargin: 10 }
                text: 'by ' + tagline
                font.italic: true
            }
            Text {
                x: 10
                width: 580
                anchors.top: titleText.bottom
                text: content
                wrapMode: Text.WordWrap

                onLinkActivated: { console.log('link clicked: ' + link) }
            }
        }
    }

    ListView {
        anchors.fill: parent
        model: feedModel
        delegate: feedDelegate
    }
}