~andrewsomething/+junk/stackbrowser

« back to all changes in this revision

Viewing changes to QuestionView.qml

  • Committer: Andrew Starr-Bochicchio
  • Date: 2013-09-04 21:43:49 UTC
  • Revision ID: a.starr.b@gmail.com-20130904214349-pc208uzp6az7kdrq
Get the basic question view together.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import Ubuntu.Components 0.1
3
3
import Ubuntu.Components.ListItems 0.1 as ListItem
4
4
 
5
 
Item {
 
5
ListView {
 
6
    id: questionList
6
7
    anchors.fill: parent
7
 
    function reload() {
8
 
        questionFeed.reload()
9
 
    }
10
 
 
11
 
//    Rectangle {
12
 
//        id: stackLogo
13
 
//        anchors {
14
 
//            right: parent.right
15
 
//            left: parent.left
16
 
//        }
17
 
//        height: units.gu(10)
18
 
//        Image {
19
 
//            anchors.fill: parent
20
 
//            fillMode: Image.PreserveAspectFit
21
 
//            source: Qt.resolvedUrl(logo)
22
 
//        }
23
 
//    }
24
 
 
25
 
    ListView {
26
 
        id: questionList
 
8
    anchors.margins: units.gu(2)
 
9
 
 
10
    model: StackListModel {
 
11
         id: questionFeed
 
12
         path: "questions/" + questionViewer.question
 
13
         query: "$.items[*]"
 
14
         args: "filter=!--btTK8(xvrs&sort=votes"
 
15
         site: stackView.site
 
16
     }
 
17
    delegate: Column {
 
18
        id: questionItemDelegate
27
19
        width: parent.width
28
 
        anchors.bottom: parent.bottom
29
 
        anchors.bottomMargin: units.gu(2)
30
 
        anchors.top: parent.top
31
 
        anchors.topMargin: units.gu(2)
32
 
        //contentHeight: parent.width * count
33
 
 
34
 
        model: StackListModel {
35
 
             id: questionFeed
36
 
             path: "questions/" + questionViewer.question
37
 
             query: "$.items[*]"
38
 
             args: "filter=!6JmlAA.G22_g3"//withbody"
39
 
             site: stackView.site
40
 
         }
41
 
        delegate: Column {
42
 
            id: questionItemDelegate
43
 
            width: parent.width
44
 
                    Label {
45
 
                        text: model.title
46
 
                        width: parent.width - units.gu(4)
 
20
        anchors.centerIn: parent
 
21
 
 
22
        Item {
 
23
            id: question_header
 
24
            width: parent.width - units.gu(2)
 
25
            height: units.gu(12)
 
26
 
 
27
            UbuntuShape{
 
28
                id: question_score
 
29
                color: model.accepted_answer_id ? "green" : "gray"
 
30
                anchors.margins: units.gu(2)
 
31
 
 
32
                Label{
 
33
                    anchors.centerIn: parent
 
34
                    fontSize: "x-large"
 
35
                    text: model.score
 
36
                    color: "white"
 
37
                }
 
38
            }
 
39
 
 
40
            Label {
 
41
                text: model.title
 
42
                width: parent.width - question_score.width
 
43
                anchors.left: question_score.right
 
44
                anchors.margins: units.gu(2)
 
45
                fontSize: "large"
 
46
                wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
47
            }
 
48
        }
 
49
 
 
50
        Row {
 
51
            width: parent.width - units.gu(4)
 
52
 
 
53
            UbuntuShape{
 
54
                color: "white"
 
55
                width: parent.width
 
56
                height: question_body.paintedHeight
 
57
                anchors.margins: units.gu(2)
 
58
 
 
59
                Label {
 
60
                    id: question_body
 
61
                    text: model.body
 
62
                    width: parent.width - units.gu(2)
 
63
                    wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
64
                }
 
65
            }
 
66
        }
 
67
 
 
68
        Label {
 
69
            text: "Asked by: <b>" + model.owner['display_name'] + "</b> (Reputation: <b>" + model.owner['reputation'] + "</b>)"
 
70
            height: units.gu(4)
 
71
        }
 
72
 
 
73
        ListItem.Divider {
 
74
            anchors.topMargin: units.gu(2)
 
75
        }
 
76
 
 
77
        Label {
 
78
            text: "Answers"
 
79
            height: units.gu(6)
 
80
            fontSize: "x-large"
 
81
        }
 
82
 
 
83
        Component {
 
84
            id: answererComponent
 
85
 
 
86
            Item {
 
87
                property var owner: ''
 
88
                property var rep: ''
 
89
                property var score: ''
 
90
                property bool accepted:undefined
 
91
                width: parent.width - units.gu(4)
 
92
                height: units.gu(6)
 
93
 
 
94
                UbuntuShape{
 
95
                    id: answer_score
 
96
                    color: accepted ? "green" : "gray"
 
97
                    anchors.margins: units.gu(2)
 
98
                    height: units.gu(5)
 
99
                    width: units.gu(5)
 
100
 
 
101
                    Label{
 
102
                        anchors.centerIn: parent
47
103
                        fontSize: "large"
48
 
                        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
104
                        text: score
 
105
                        color: "white"
49
106
                    }
 
107
                }
 
108
 
 
109
                Label {
 
110
                    id: answerer
 
111
                    text: "           by: <b>" + owner + "</b> (Reputation: <b>" + rep + "</b>)"
 
112
                    anchors.left: answer_score.right
 
113
                    anchors.verticalCenter: answer_score.verticalCenter
 
114
                    wrapMode: Text.WrapAtWordBoundaryOrAnywhere
 
115
                }
 
116
            }
 
117
        }
 
118
 
 
119
        Component {
 
120
            id: answerBodyComponent
 
121
 
 
122
            Item {
 
123
                property var body: ''
 
124
 
 
125
                width: parent.width - units.gu(4)
 
126
                height: answer_body.paintedHeight + units.gu(5)
 
127
 
 
128
                UbuntuShape{
 
129
                    color: "white"
 
130
                    width: parent.width
 
131
                    height: answer_body.paintedHeight
 
132
                    radius: "small"
 
133
                    anchors.margins: units.gu(2)
 
134
 
50
135
                    Label {
51
 
                        text: model.body
 
136
                        id: answer_body
 
137
                        text: body
52
138
                        width: parent.width - units.gu(4)
53
139
                        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
54
140
                    }
55
 
//                    Label {
56
 
//                        text: model.answers[0]["body"]
57
 
//                        width: parent.width - units.gu(4)
58
 
//                        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
59
 
//                    }
60
 
            }
 
141
                }
 
142
            }
 
143
        }
 
144
 
 
145
        Component.onCompleted: {
 
146
            if (model.answer_count > 0 && model.answers){
 
147
                for (var i=0; i<model.answer_count; i++){
 
148
                    var answerer = answererComponent.createObject(questionItemDelegate)
 
149
                    var answer = answerBodyComponent.createObject(questionItemDelegate)
 
150
                    answer.body = model.answers.get(i).body
 
151
                    answerer.accepted = model.answers.get(i)["is_accepted"]
 
152
                    answerer.score = model.answers.get(i)["score"]
 
153
                    answerer.owner = model.answers.get(i).owner['display_name']
 
154
                    answerer.rep = model.answers.get(i).owner['reputation']
 
155
                }
 
156
            }
 
157
        }
61
158
    }
62
159
}
63