harbour-tooter/qml/pages/components/VisualContainer.qml

398 lines
15 KiB
QML
Raw Normal View History

import QtQuick 2.2
import Sailfish.Silica 1.0
2017-07-04 02:07:39 +03:00
import "../../lib/API.js" as Logic
BackgroundItem {
id: delegate
2020-06-04 12:17:06 +03:00
signal send (string notice)
signal navigateTo(string link)
2020-06-04 12:17:06 +03:00
width: parent.width
height: if (myList.type === "notifications" && ( model.type === "favourite" || model.type === "reblog" )) {
mnu.height + miniHeader.height + Theme.paddingLarge + lblContent.height + Theme.paddingLarge + (miniStatus.visible ? miniStatus.height : 0)
} else 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) + (iconDirectMsg.visible ? iconDirectMsg.height : 0)
2020-06-10 11:17:51 +03:00
Rectangle {
2020-06-04 20:44:12 +03:00
id: bgDirect
2020-06-04 12:17:06 +03:00
x: 0
y: 0
2020-06-10 11:17:51 +03:00
visible: status_visibility === "direct"
width: parent.width
height: parent.height
opacity: 0.3
2020-06-10 12:44:58 +03:00
gradient: Gradient {
2020-06-11 15:11:39 +03:00
GradientStop { position: -1.5; color: "transparent" }
GradientStop { position: 0.6; color: Theme.highlightBackgroundColor }
2020-06-10 12:44:58 +03:00
}
}
Rectangle {
id: bgNotifications
x: 0
y: 0
visible: myList.type === "notifications" && ( model.type === "favourite" || model.type === "reblog" )
width: parent.width
height: parent.height
opacity: 0.5
gradient: Gradient {
2020-06-11 15:11:39 +03:00
GradientStop { position: -0.5; color: "transparent" }
GradientStop { position: 0.4; color: Theme.highlightDimmerColor }
}
}
MiniStatus {
id: miniStatus
anchors {
leftMargin: Theme.horizontalPageMargin
rightMargin: Theme.horizontalPageMargin
top: parent.top
topMargin: Theme.paddingMedium
}
}
Image {
id: avatar
2020-06-04 12:17:06 +03:00
visible: true
opacity: status === Image.Ready ? 1.0 : 0.0
Behavior on opacity { FadeAnimator {} }
asynchronous: true
smooth: true
source: account_avatar
width: Theme.iconSizeMedium
height: width
anchors {
top: miniStatus.visible ? miniStatus.bottom : parent.top
topMargin: miniStatus.visible ? Theme.paddingMedium : Theme.paddingLarge
left: parent.left
leftMargin: Theme.horizontalPageMargin
}
2017-07-20 13:14:16 +03:00
onStatusChanged: {
if (avatar.status === Image.Error)
source = "../../images/icon-m-profile.svg?" + (pressed
2020-06-11 15:11:39 +03:00
? Theme.highlightColor
: Theme.primaryColor)
2017-07-20 13:14:16 +03:00
}
MouseArea {
anchors.fill: parent
onClicked: {
pageStack.push(Qt.resolvedUrl("../ProfilePage.qml"), {
"display_name": model.account_display_name,
"username": model.account_acct,
"user_id": model.account_id,
"profileImage": model.account_avatar,
"profileBackground": model.account_header
})
}
2017-07-04 02:07:39 +03:00
}
Rectangle {
visible: myList.type === "notifications" && ( model.type === "favourite" || model.type === "reblog" )
opacity: 0.5
color: Theme.highlightDimmerColor
anchors.fill: avatar
}
2017-07-04 02:07:39 +03:00
Image {
id: iconTR
2020-06-04 12:17:06 +03:00
visible: typeof status_reblogged !== "undefined" && status_reblogged
width: Theme.iconSizeExtraSmall
height: width
source: "image://theme/icon-s-retweet"
2017-07-04 02:07:39 +03:00
anchors {
top: avatar.bottom
topMargin: Theme.paddingMedium
left: avatar.left
}
}
Image {
id: iconDirectMsg
2020-06-10 11:17:51 +03:00
visible: status_visibility === "direct"
width: Theme.iconSizeMedium
height: width
source: "image://theme/icon-m-mail"
anchors {
horizontalCenter: avatar.horizontalCenter
top: avatar.bottom
topMargin: Theme.paddingMedium
left: avatar.left
}
}
Rectangle {
id: bgReblogAvatar
2020-06-09 09:52:22 +03:00
color: Theme.secondaryColor
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
}
2020-06-04 12:17:06 +03:00
Image {
id: reblogAvatar
asynchronous: true
smooth: true
2017-06-16 17:45:04 +03:00
opacity: status === Image.Ready ? 1.0 : 0.0
Behavior on opacity { FadeAnimator {} }
2017-06-14 17:57:44 +03:00
source: typeof reblog_account_avatar !== "undefined" ? reblog_account_avatar : ''
visible: typeof status_reblog !== "undefined" && status_reblog
2020-06-04 12:17:06 +03:00
width: Theme.iconSizeSmall
height: width
}
}
}
MiniHeader {
id: miniHeader
anchors {
top: avatar.top
left: avatar.right
right: parent.right
}
}
2018-10-24 14:38:17 +03:00
Text {
id: lblContent
2020-06-04 20:44:12 +03:00
visible: model.type !== "follow"
2020-06-04 12:17:06 +03:00
text: content.replace(new RegExp("<a ", 'g'), '<a style="text-decoration: none; color:'+(pressed ? Theme.secondaryColor : Theme.highlightColor)+'" ')
textFormat: Text.RichText
font.pixelSize: Theme.fontSizeSmall
linkColor: if (myList.type === "notifications" && ( model.type === "favourite" || model.type === "reblog" )) {
2020-06-11 15:11:39 +03:00
Theme.secondaryHighlightColor
} else Theme.highlightColor
2020-06-04 12:17:06 +03:00
wrapMode: Text.Wrap
color: if (myList.type === "notifications" && ( model.type === "favourite" || model.type === "reblog" )) {
(pressed ? Theme.secondaryHighlightColor : (!highlight ? Theme.secondaryColor : Theme.secondaryHighlightColor))
} else (pressed ? Theme.highlightColor : (!highlight ? Theme.primaryColor : Theme.secondaryColor))
2020-06-04 20:44:12 +03:00
height: if (model.type === "follow") {
Theme.paddingLarge
} else content.length ? (contentWarningLabel.paintedHeight > paintedHeight ? contentWarningLabel.paintedHeight : paintedHeight) : 0
anchors {
left: miniHeader.left
leftMargin: Theme.paddingMedium
right: miniHeader.right
rightMargin: Theme.horizontalPageMargin
top: miniHeader.bottom
topMargin: Theme.paddingSmall
bottomMargin: Theme.paddingLarge
}
onLinkActivated: {
var test = link.split("/")
console.log(link)
console.log(JSON.stringify(test))
console.log(JSON.stringify(test.length))
if (test.length === 5 && (test[3] === "tags" || test[3] === "tag") ) {
pageStack.pop(pageStack.find(function(page) {
var check = page.isFirstPage === true;
if (check)
page.onLinkActivated(link)
return check;
}));
send(link)
} else if (test.length === 4 && test[3][0] === "@" ) {
2020-06-04 12:17:06 +03:00
pageStack.pop(pageStack.find(function(page) {
var check = page.isFirstPage === true;
if (check)
page.onLinkActivated(link)
return check;
}));
} else {
Qt.openUrlExternally(link);
}
}
2020-06-04 12:17:06 +03:00
Rectangle {
color: Theme.highlightDimmerColor
visible: status_spoiler_text.length > 0
2020-06-04 12:17:06 +03:00
anchors.fill: parent
Label {
2017-07-20 13:14:16 +03:00
id: contentWarningLabel
2020-06-04 12:17:06 +03:00
text: model.status_spoiler_text
font.pixelSize: Theme.fontSizeExtraSmall
2020-06-04 12:17:06 +03:00
color: Theme.highlightColor
truncationMode: TruncationMode.Fade
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
2020-06-04 12:17:06 +03:00
width: parent.width
2017-07-20 13:14:16 +03:00
anchors {
topMargin: Theme.paddingSmall
left: parent.left
leftMargin: Theme.paddingMedium
centerIn: parent
right: parent.right
rightMargin: Theme.paddingMedium
bottomMargin: Theme.paddingSmall
}
}
MouseArea {
anchors.fill: parent
2020-06-04 12:17:06 +03:00
onClicked: parent.visible = false
}
}
}
2017-06-16 17:45:04 +03:00
MediaBlock {
id: media
2020-06-12 17:56:10 +03:00
visible: if (myList.type === "notifications" && ( type === "favourite" || type === "reblog" )) {
false
} else true
2020-06-04 12:17:06 +03:00
model: typeof attachments !== "undefined" ? attachments : Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
height: Theme.iconSizeExtraLarge * 2
anchors {
2017-06-16 17:45:04 +03:00
left: lblContent.left
right: lblContent.right
top: lblContent.bottom
topMargin: Theme.paddingSmall
bottomMargin: Theme.paddingLarge
}
}
ContextMenu {
id: mnu
2020-06-04 12:17:06 +03:00
2017-07-04 02:07:39 +03:00
MenuItem {
2020-06-10 11:17:51 +03:00
id: mnuBoost
2020-06-04 20:44:12 +03:00
visible: model.type !== "follow"
2020-06-10 11:17:51 +03:00
enabled: status_visibility !== "direct"
text: typeof model.reblogged !== "undefined" && model.reblogged ? qsTr("Unboost") : qsTr("Boost")
2017-07-04 02:07:39 +03:00
onClicked: {
var status = typeof model.reblogged !== "undefined" && model.reblogged
2017-07-04 02:07:39 +03:00
worker.sendMessage({
"conf" : Logic.conf,
"params" : [],
"method" : "POST",
"bgAction": true,
"action" : "statuses/"+model.status_id+"/" + (status ? "unreblog" : "reblog")
2017-07-04 02:07:39 +03:00
})
model.reblogs_count = !status ? model.reblogs_count+1 : (model.reblogs_count > 0 ? model.reblogs_count-1 : model.reblogs_count);
model.reblogged = !model.reblogged
}
2020-06-04 12:17:06 +03:00
Image {
id: icRT
2020-06-04 12:17:06 +03:00
source: "image://theme/icon-s-retweet?" + (!model.reblogged ? Theme.highlightColor : Theme.primaryColor)
width: Theme.iconSizeExtraSmall
height: width
anchors {
leftMargin: Theme.horizontalPageMargin
left: parent.left
verticalCenter: parent.verticalCenter
}
}
Label {
2020-06-04 12:17:06 +03:00
text: reblogs_count
font.pixelSize: Theme.fontSizeExtraSmall
color: !model.reblogged ? Theme.highlightColor : Theme.primaryColor
anchors {
left: icRT.right
leftMargin: Theme.paddingMedium
verticalCenter: parent.verticalCenter
}
2017-07-04 02:07:39 +03:00
}
}
2017-07-04 02:07:39 +03:00
MenuItem {
2020-06-10 11:17:51 +03:00
id: mnuFavourite
2020-06-11 15:11:39 +03:00
visible: model.type !== "follow"
text: typeof model.favourited !== "undefined" && model.favourited ? qsTr("Unfavorite") : qsTr("Favorite")
2017-07-04 02:07:39 +03:00
onClicked: {
var status = typeof model.favourited !== "undefined" && model.favourited
2017-07-04 02:07:39 +03:00
worker.sendMessage({
"conf" : Logic.conf,
"params" : [],
"method" : "POST",
"bgAction": true,
"action" : "statuses/"+model.status_id+"/" + (status ? "unfavourite" : "favourite")
2017-07-04 02:07:39 +03:00
})
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 {
2020-06-04 12:17:06 +03:00
text: favourites_count
font.pixelSize: Theme.fontSizeExtraSmall
color: !model.favourited ? Theme.highlightColor : Theme.primaryColor
anchors {
left: icFA.right
leftMargin: Theme.paddingMedium
verticalCenter: parent.verticalCenter
}
2017-07-04 02:07:39 +03:00
}
}
2020-06-04 20:44:12 +03:00
MenuItem {
2020-06-10 11:17:51 +03:00
id: mnuMention
2020-06-04 20:44:12 +03:00
visible: model.type === "follow"
text: qsTr("Mention")
onClicked: {
pageStack.push(Qt.resolvedUrl("../ConversationPage.qml"), {
headerTitle: "Mention",
description: "@"+reblog_account_acct,
type: "new"
})
}
Image {
id: icMT
anchors {
leftMargin: Theme.horizontalPageMargin
left: parent.left
verticalCenter: parent.verticalCenter
}
width: Theme.iconSizeExtraSmall
height: width
source: "image://theme/icon-s-chat?" + (!model.favourited ? Theme.highlightColor : Theme.primaryColor)
}
}
2017-07-04 02:07:39 +03:00
}
onClicked: {
var m = Qt.createQmlObject('import QtQuick 2.0; ListModel { }', Qt.application, 'InternalQmlObject');
if (typeof mdl !== "undefined")
m.append(mdl.get(index))
pageStack.push(Qt.resolvedUrl("../ConversationPage.qml"), {
headerTitle: "Conversation",
toot_id: status_id,
toot_url: status_url,
toot_uri: status_uri,
title: account_display_name,
description: '@'+account_acct,
avatar: account_avatar,
mdl: m,
type: "reply"
})
}
2017-06-16 17:45:04 +03:00
onPressAndHold: {
2018-10-24 14:38:17 +03:00
console.log(JSON.stringify(mdl.get(index)))
mnu.show(delegate)
}
onDoubleClicked: {
console.log("double click")
2017-06-16 17:45:04 +03:00
}
}