harbour-tooter/qml/pages/Conversation.qml
2017-06-09 16:56:16 +02:00

143 lines
4.7 KiB
QML

import QtQuick 2.0
import Sailfish.Silica 1.0
import "../lib/API.js" as Logic
import "./components/"
Page {
id: conversationPage
property string type;
property alias title: header.title
property alias description: header.description
property alias avatar: header.image
property int toot_id
WorkerScript {
id: worker
source: "../lib/Worker.js"
onMessage: {
console.log(JSON.stringify(messageObject))
}
}
ProfileHeader {
id: header
}
DockedPanel {
id: panel
open: true
width: parent.width
height: toot.height + btnAddImages.height + Theme.paddingMedium + (warningContent.visible ? warningContent.height : 0)
dock: Dock.Bottom
TextField {
id: warningContent
visible: false
height: visible ? implicitHeight : 0;
anchors {
top: parent.top
topMargin: Theme.paddingMedium
left: parent.left
right: parent.right
}
autoScrollEnabled: true
labelVisible: false
placeholderText: qsTr("Content warning!")
horizontalAlignment: Text.AlignLeft
EnterKey.onClicked: {
//tweet()
}
}
TextArea {
id: toot
anchors {
top: warningContent.bottom
topMargin: Theme.paddingMedium
left: parent.left
right: parent.right
}
autoScrollEnabled: true
labelVisible: false
focus: true
text: description !== "" && (description.charAt(0) == '@' || description.charAt(0) == '#') ? description+' ' : ''
height: implicitHeight
horizontalAlignment: Text.AlignLeft
EnterKey.onClicked: {
//tweet()
}
}
IconButton {
id: btnAddImages
enabled: false
anchors {
verticalCenter: btnSend.verticalCenter
left: parent.left
leftMargin: Theme.paddingMedium
}
icon.source: "image://theme/icon-s-attach?" + (pressed
? Theme.highlightColor
: Theme.primaryColor)
onClicked: console.log("Delete!")
}
IconButton {
id: btnContentWarning
anchors {
verticalCenter: btnSend.verticalCenter
left: btnAddImages.right
}
icon.source: "image://theme/icon-s-high-importance?" + (pressed
? Theme.highlightColor
: (warningContent.visible ? Theme.secondaryHighlightColor : Theme.primaryColor))
onClicked: warningContent.visible = !warningContent.visible
}
ComboBox {
id: privacy
anchors {
top: toot.bottom
left: btnContentWarning.right
right: btnSend.left
}
menu: ContextMenu {
MenuItem { text: qsTr("public") }
MenuItem { text: qsTr("unlisted") }
MenuItem { text: qsTr("followers only") }
MenuItem { text: qsTr("direct") }
}
}
IconButton {
id: btnSend
icon.source: "image://theme/icon-m-enter?" + (pressed
? Theme.highlightColor
: Theme.primaryColor)
anchors {
top: toot.bottom
right: parent.right
rightMargin: Theme.paddingLarge
}
enabled: toot.text !== ""
onClicked: {
var visibility = [ "public", "unlisted", "private", "direct"];
var msg = {
'action' : 'statuses',
'method' : 'POST',
'params' : {
"status": toot.text,
"visibility": visibility[privacy.currentIndex]
},
'conf' : Logic.conf
};
if (toot_id > 0)
msg.params['in_reply_to_id'] = toot_id
if (warningContent.visible && warningContent.text.length > 0){
msg.params['sensitive'] = 1
msg.params['spoiler_text'] = warningContent.text
}
worker.sendMessage(msg);
console.log(JSON.stringify(msg));
warningContent.text = ""
toot.text = ""
}
}
}
}