VisualContainer.qml 12.5 KB
Newer Older
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
1
import QtQuick 2.2
2
import Sailfish.Silica 1.0
Dusko Angirevic's avatar
Dusko Angirevic committed
3
import "../../lib/API.js" as Logic
4 5

BackgroundItem {
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
6

7 8 9 10
    id: delegate
    signal send (string notice)
    signal navigateTo(string link)
    width: parent.width
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
11
    height: mnu.height +  miniHeader.height + (typeof attachments !== "undefined" && attachments.count ? media.height + Theme.paddingLarge + Theme.paddingMedium: Theme.paddingLarge) + lblContent.height + Theme.paddingLarge + (ministatus.visible ? ministatus.height : 0)
12 13 14 15 16 17 18 19 20 21
    Rectangle {
        x: 0;
        y: 0;
        visible: status_visibility == 'direct'
        width: parent.width
        height: parent.height
        opacity: 0.3
        color: Theme.highlightBackgroundColor;
    }

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
    MiniStatus {
        id: ministatus
        anchors {
            leftMargin: Theme.horizontalPageMargin
            rightMargin: Theme.horizontalPageMargin
            top: parent.top
            topMargin: Theme.paddingMedium
        }
    }
    Image {
        id: avatar
        anchors {
            top: ministatus.visible ? ministatus.bottom : parent.top
            topMargin: ministatus.visible ? Theme.paddingMedium : Theme.paddingLarge
            left: parent.left
            leftMargin: Theme.horizontalPageMargin
        }
Dusko Angirevic's avatar
Dusko Angirevic committed
39 40
        opacity: status === Image.Ready ? 1.0 : 0.0
        Behavior on opacity { FadeAnimator {} }
41 42 43 44 45 46
        asynchronous: true
        width: Theme.iconSizeMedium
        height: width
        smooth: true
        source: account_avatar
        visible: true
Dusko Angirevic's avatar
Dusko Angirevic committed
47 48 49 50 51 52 53
        onStatusChanged: {
            if (avatar.status === Image.Error)
                source = "image://theme/icon-m-person?" + (pressed
                 ? Theme.highlightColor
                 : Theme.primaryColor)
        }

54 55 56 57
        MouseArea {
            anchors.fill: parent
            onClicked: {
                pageStack.push(Qt.resolvedUrl("../Profile.qml"), {
58 59 60 61
                                   "displayname": model.account_username,
                                   "username": model.account_acct,
                                   "user_id": model.account_id,
                                   "profileImage": model.account_avatar
62 63 64
                               })
            }

Dusko Angirevic's avatar
Dusko Angirevic committed
65
        }
Dusko Angirevic's avatar
Dusko Angirevic committed
66

Dusko Angirevic's avatar
Dusko Angirevic committed
67 68 69 70 71 72 73 74 75 76 77
        Image {
            id: iconTR
            anchors {
                top: avatar.bottom
                topMargin: Theme.paddingMedium
                left: avatar.left
            }
            visible: typeof status_reblogged !== "undefined" && status_reblogged
            width: Theme.iconSizeExtraSmall
            height: width
            source: "image://theme/icon-s-retweet"
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        }
        Rectangle {
            color: Theme.highlightDimmerColor
            width: Theme.iconSizeSmall
            height: width
            visible: typeof status_reblog !== "undefined" && status_reblog
            anchors {
                bottom: parent.bottom
                bottomMargin: -width/3
                left: parent.left
                leftMargin: -width/3
            }
            Image {
                asynchronous: true
                width: Theme.iconSizeSmall
                height: width
                smooth: true
Dusko Angirevic's avatar
Dusko Angirevic committed
95 96
                opacity: status === Image.Ready ? 1.0 : 0.0
                Behavior on opacity { FadeAnimator {} }
97
                source: typeof reblog_account_avatar !== "undefined" ? reblog_account_avatar : ''
98 99 100 101 102 103 104 105 106 107 108 109
                visible: typeof status_reblog !== "undefined" && status_reblog
            }
        }
    }
    MiniHeader {
        id: miniHeader
        anchors {
            top: avatar.top
            left: avatar.right
            right: parent.right
        }
    }
Dusko Angirevic's avatar
Dusko Angirevic committed
110
    Text  {
111 112 113 114 115 116 117 118 119 120
        id: lblContent
        anchors {
            left: miniHeader.left
            leftMargin: Theme.paddingMedium
            right: miniHeader.right
            rightMargin: Theme.horizontalPageMargin
            top: miniHeader.bottom
            topMargin: Theme.paddingSmall
            bottomMargin: Theme.paddingLarge
        }
Dusko Angirevic's avatar
Dusko Angirevic committed
121
        height: content.length ? (contentWarningLabel.paintedHeight > paintedHeight ? contentWarningLabel.paintedHeight : paintedHeight) : 0
122
        onLinkActivated: {
Dusko Angirevic's avatar
Dusko Angirevic committed
123
            var test = link.split("/")
124
            console.log(link)
Dusko Angirevic's avatar
Dusko Angirevic committed
125 126
            console.log(JSON.stringify(test))
            console.log(JSON.stringify(test.length))
127

Dusko Angirevic's avatar
Dusko Angirevic committed
128
            if (test.length === 5 && (test[3] === "tags" || test[3] === "tag") ) {
129 130 131 132 133 134 135
                pageStack.pop(pageStack.find(function(page) {
                    var check = page.isFirstPage === true;
                    if (check)
                        page.onLinkActivated(link)
                    return check;
                }));
                send(link)
Dusko Angirevic's avatar
Dusko Angirevic committed
136 137 138
            } else if (test.length === 4 && test[3][0] === "@" ) {
                pageStack.push(Qt.resolvedUrl("../Profile.qml"), {
                                   "name": "",
Dusko Angirevic's avatar
Dusko Angirevic committed
139
                                   "username": test[3].substring(1)+"@"+test[2],
Dusko Angirevic's avatar
Dusko Angirevic committed
140 141
                                   "profileImage": ""
                               })
142
            } else {
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
143
                pageStack.push(Qt.resolvedUrl("../Browser.qml"), {"href" : link})
144 145
            }
        }
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
146
        text: content.replace(new RegExp("<a ", 'g'), '<a style="text-decoration: none; color:'+(pressed ?  Theme.secondaryColor : Theme.highlightColor)+'" ')
147
        linkColor : Theme.highlightColor
Haelwenn's avatar
Haelwenn committed
148
        wrapMode: Text.Wrap
Haelwenn's avatar
Haelwenn committed
149
        textFormat: Text.RichText
150
        font.pixelSize: Theme.fontSizeSmall
Dusko Angirevic's avatar
Dusko Angirevic committed
151
        color: (pressed ? Theme.highlightColor : (!highlight ? Theme.primaryColor : Theme.secondaryColor))
Dusko Angirevic's avatar
Dusko Angirevic committed
152 153 154 155 156 157
        Rectangle {
            anchors.fill: parent
            radius: 2
            color: Theme.highlightDimmerColor
            visible: status_spoiler_text.length > 0
            Label {
Dusko Angirevic's avatar
Dusko Angirevic committed
158
                id: contentWarningLabel
Dusko Angirevic's avatar
Dusko Angirevic committed
159 160
                font.pixelSize: Theme.fontSizeExtraSmall
                horizontalAlignment: Text.AlignHCenter
Dusko Angirevic's avatar
Dusko Angirevic committed
161 162 163 164 165 166 167 168 169 170 171
                anchors {
                    topMargin: Theme.paddingSmall
                    left: parent.left
                    leftMargin: Theme.paddingMedium
                    centerIn: parent
                    right: parent.right
                    rightMargin: Theme.paddingMedium
                    bottomMargin: Theme.paddingSmall
                }
                width: parent.width
                truncationMode: TruncationMode.Fade
Dusko Angirevic's avatar
Dusko Angirevic committed
172
                color: Theme.highlightColor
Haelwenn's avatar
Haelwenn committed
173
                wrapMode: Text.Wrap
Dusko Angirevic's avatar
Dusko Angirevic committed
174 175 176 177 178 179 180 181
                text: model.status_spoiler_text
            }
            MouseArea {
                anchors.fill: parent
                onClicked: parent.visible = false;
            }

        }
182
    }
Dusko Angirevic's avatar
Dusko Angirevic committed
183
    MediaBlock {
184 185
        id: media
        anchors {
Dusko Angirevic's avatar
Dusko Angirevic committed
186 187
            left: lblContent.left
            right: lblContent.right
188 189 190 191
            top: lblContent.bottom
            topMargin: Theme.paddingSmall
            bottomMargin: Theme.paddingLarge
        }
Dusko Angirevic's avatar
Dusko Angirevic committed
192
        model: typeof attachments !== "undefined" ? attachments : Qt.createQmlObject('import QtQuick 2.0; ListModel {   }', Qt.application, 'InternalQmlObject');
Dusko Angirevic's avatar
Dusko Angirevic committed
193
        height: 100
194
    }
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
195 196
    ContextMenu {
        id: mnu
Dusko Angirevic's avatar
Dusko Angirevic committed
197
        MenuItem {
Dusko Angirevic's avatar
Dusko Angirevic committed
198 199
            enabled: model.type !== "follow"
            text: typeof model.reblogged !== "undefined" && model.reblogged ? qsTr("Unboost") : qsTr("Boost")
Dusko Angirevic's avatar
Dusko Angirevic committed
200
            onClicked: {
Dusko Angirevic's avatar
Dusko Angirevic committed
201
                var status = typeof model.reblogged !== "undefined" && model.reblogged
Dusko Angirevic's avatar
Dusko Angirevic committed
202 203 204 205
                worker.sendMessage({
                                       "conf"   : Logic.conf,
                                       "params" : [],
                                       "method" : "POST",
Dusko Angirevic's avatar
Dusko Angirevic committed
206 207
                                       "bgAction": true,
                                       "action" : "statuses/"+model.status_id+"/" + (status ? "unreblog" : "reblog")
Dusko Angirevic's avatar
Dusko Angirevic committed
208
                                   })
Dusko Angirevic's avatar
Dusko Angirevic committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
                model.reblogs_count = !status ? model.reblogs_count+1 : (model.reblogs_count > 0 ? model.reblogs_count-1 : model.reblogs_count);
                model.reblogged = !model.reblogged
            }
            Image {
                id: icRT
                anchors {
                    leftMargin: Theme.horizontalPageMargin
                    left: parent.left
                    verticalCenter: parent.verticalCenter
                }
                width: Theme.iconSizeExtraSmall
                height: width
                source: "image://theme/icon-s-retweet?" + (!model.reblogged ? Theme.highlightColor : Theme.primaryColor)
            }
            Label {
                anchors {
                    left: icRT.right
                    leftMargin: Theme.paddingMedium
                    verticalCenter: parent.verticalCenter
                }
                text: reblogs_count
                font.pixelSize: Theme.fontSizeExtraSmall
                color: !model.reblogged ? Theme.highlightColor : Theme.primaryColor
Dusko Angirevic's avatar
Dusko Angirevic committed
232 233 234
            }
        }
        MenuItem {
Dusko Angirevic's avatar
Dusko Angirevic committed
235 236
            enabled: model.type !== "follow"
            text: typeof model.favourited !== "undefined" && model.favourited ? qsTr("Unfavorite") : qsTr("Favorite")
Dusko Angirevic's avatar
Dusko Angirevic committed
237
            onClicked: {
Dusko Angirevic's avatar
Dusko Angirevic committed
238
                var status = typeof model.favourited !== "undefined" && model.favourited
Dusko Angirevic's avatar
Dusko Angirevic committed
239 240 241 242
                worker.sendMessage({
                                       "conf"   : Logic.conf,
                                       "params" : [],
                                       "method" : "POST",
Dusko Angirevic's avatar
Dusko Angirevic committed
243 244
                                       "bgAction": true,
                                       "action" : "statuses/"+model.status_id+"/" + (status ? "unfavourite" : "favourite")
Dusko Angirevic's avatar
Dusko Angirevic committed
245
                                   })
Dusko Angirevic's avatar
Dusko Angirevic committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
                model.favourites_count = !status ? model.favourites_count+1 : (model.favourites_count > 0 ? model.favourites_count-1 : model.favourites_count);
                model.favourited = !model.favourited
            }
            Image {
                id: icFA
                anchors {
                    leftMargin: Theme.horizontalPageMargin
                    left: parent.left
                    verticalCenter: parent.verticalCenter
                }
                width: Theme.iconSizeExtraSmall
                height: width
                source: "image://theme/icon-s-favorite?" + (!model.favourited ? Theme.highlightColor : Theme.primaryColor)
            }
            Label {
                anchors {
                    left: icFA.right
                    leftMargin: Theme.paddingMedium
                    verticalCenter: parent.verticalCenter
                }
                text: favourites_count
                font.pixelSize: Theme.fontSizeExtraSmall
                color: !model.favourited ? Theme.highlightColor : Theme.primaryColor
Dusko Angirevic's avatar
Dusko Angirevic committed
269 270
            }
        }
Haelwenn's avatar
Haelwenn committed
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
        MenuItem {
            enabled: model.type !== "follow"
            text: typeof model.bookmarked !== "undefined" && model.bookmarked ? qsTr("Unbookmark") : qsTr("Bookmark")
            onClicked: {
                var status = typeof model.bookmarked !== "undefined" && model.bookmarked
                worker.sendMessage({
                                       "conf"   : Logic.conf,
                                       "params" : [],
                                       "method" : "POST",
                                       "bgAction": true,
                                       "action" : "statuses/"+model.status_id+"/" + (status ? "unbookmark" : "bookmark")
                                   })
                model.bookmarked = !model.bookmarked
            }
            Image {
                anchors {
                    leftMargin: Theme.horizontalPageMargin
                    left: parent.left
                    verticalCenter: parent.verticalCenter
                }
                width: Theme.iconSizeExtraSmall
                height: width
                source: "image://theme/icon-s-asterisk?" + (!model.bookmarked ? Theme.highlightColor : Theme.primaryColor)
            }
        }
Dusko Angirevic's avatar
Dusko Angirevic committed
296
    }
297 298 299 300 301




    onClicked: {
302
        var m = Qt.createQmlObject('import QtQuick 2.0; ListModel {   }', Qt.application, 'InternalQmlObject');
Dusko Angirevic's avatar
Dusko Angirevic committed
303 304
        if (typeof mdl !== "undefined")
            m.append(mdl.get(index))
305
        pageStack.push(Qt.resolvedUrl("../Conversation.qml"), {
306
                           toot_id: status_id,
307
                           title: account_display_name,
308
                           description: '@'+account_acct,
309
                           avatar: account_avatar,
310
                           mdl: m,
311 312 313
                           type: "reply"
                       })
    }
Dusko Angirevic's avatar
Dusko Angirevic committed
314
    onPressAndHold: {
Dusko Angirevic's avatar
Dusko Angirevic committed
315
        console.log(JSON.stringify(mdl.get(index)))
Dusko Angirevic's avatar
0.1.6  
Dusko Angirevic committed
316 317 318 319
        mnu.show(delegate)
    }
    onDoubleClicked: {
        console.log("double click")
Dusko Angirevic's avatar
Dusko Angirevic committed
320
    }
321

322
}