Friendiqa/v0.002/Develop/source-linux/qml/newsqml/Newsitem.qml

337 lines
13 KiB
QML

import QtQuick 2.0
import QtQuick.LocalStorage 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "qrc:/js/news.js" as Newsjs
Item {
id: newsitem
width: newsView.width
height:Math.max((itemMessage.height+topFlow.height+friendicaActivities.height+4*mm),profileImage.height+user_name.height+mm)
property string conversation_id: ""
property string attending: ""
onAttendingChanged: {attendLabel.visible=true;
attendLabel.text= qsTr("attending: ")+ qsTr(attending)}
signal replyto(string parent_id)
Rectangle{width:newsitem.width; height: 1; anchors.bottom: newsitem.bottom; color:"light grey"}
Rectangle{
width:newsitem.width
height:newsitem.height-1
color: (newsitemobject.messagetype==1)?"#ffe6e6" : "white"
Column {
id: authorcolumn
width: 8*mm
Image {
id:profileImage
source: (newsitemobject.user.profile_image!="")? "file://"+newsitemobject.user.profile_image : newsitemobject.user.profile_image_url
x:1
width: 7*mm
height: 7*mm
MouseArea{
anchors.fill: parent
onPressAndHold: { newsmenu.popup()}
}
onStatusChanged: if (profileImage.status == Image.Error) {source="qrc:/images/defaultcontact.jpg"}
}
Label {
id:user_name
color: "grey"
//height:3.5*mm
width:parent.width
font.pixelSize: 1.5*mm
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
text: Qt.atob(newsitemobject.user.name)
}
}
Column {
id:newscolumn
width: newsitem.width-8*mm
anchors.left: authorcolumn.right
Flow{
id:topFlow
spacing: 2*mm
width:parent.width
Label {
color: "grey"
text: if (newsitemobject.messagetype==0){qsTr("Source: ")+newsitemobject.source
} else if (newsitemobject.messagetype==1){ qsTr("Direct Message")} else {" Notification"}
font.pixelSize: 1.5*mm
}
Label {
id:createdAtLabel
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: dateDiff
}
CheckBox {
id:favoritedCheckbox
style: CheckBoxStyle {
background: Rectangle {
implicitWidth: 6*mm
implicitHeight:2*mm
color:"white"
}
indicator:
Rectangle{x:3*mm
width: 3*mm
implicitHeight:2*mm
Text{
anchors.centerIn: parent
color:control.checked?"black":"grey"
text:"\u2605"
}}
}
checked:(newsitemobject.favorited>0)
onClicked:{
if(favoritedCheckbox.checkedState==Qt.Checked)
{Newsjs.favorite(login,true,newsitemobject.status_id,root)}
else
if(favoritedCheckbox.checkedState==Qt.Unchecked)
{Newsjs.favorite(login,false,newsitemobject.status_id,root)}
}
}
Rectangle{
width: 4*mm
height: 3*mm
Text{
id:newsmenusymbol
color: "grey"
anchors.centerIn: parent
font.pixelSize: 2*mm
font.bold: true
text: "\u22EE"
}
MouseArea{
anchors.fill:parent
onClicked: {newsmenu.popup()}}
}
Rectangle{
width: 4*mm
height: 3*mm
visible:(newsitemobject.in_reply_to_status_id!="")?true:false
Text{
id:conversationsymbol
color: "grey"
anchors.centerIn: parent
font.pixelSize: 2*mm
text: "\u21C4"
}
MouseArea{
anchors.fill:parent
onClicked: {
newsBusy.running=true;
Newsjs.requestConversation(root.login,db,newsitemobject.status_id,root.contactlist,root,function(news,newContacts){
for (var i=0;i<newContacts.length;i++){
root.updateContactInDB(root.login,root.db,0,newContacts[i])
}
Newsjs.storeNews(root.login,root.db,news,root,function(){
var currentTime= new Date();
Newsjs.conversationfromdb(db,root.login.username,newsitemobject.statusnet_conversation_id, function(newsarray){
newsModel.clear();
newstab.newstabStatus="conversation";
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsarray,'latestmessage':0};
newsWorker.sendMessage(msg);
newsBusy.running=false
})
}
)})
}}
}}
Text {
color: "#404040"
linkColor: "light green"
id: itemMessage
textFormat: Text.RichText
text: Qt.atob(newsitemobject.statusnet_html)
width: newsitem.width-8*mm-2
height: implicitHeight
wrapMode: Text.Wrap
onLinkActivated:{
Qt.openUrlExternally(link)}
}
Row{id:friendicaActivities
spacing:mm
Label{color: "grey"
font.pixelSize: 1.5*mm
text: friendica_activities.likeText
}
Label{color: "grey"
font.pixelSize: 1.5*mm
text: friendica_activities.dislikeText
}
Label{color: "grey"
font.pixelSize: 1.5*mm
text: friendica_activities.attendyesText
}
Label{color: "grey"
font.pixelSize: 1.5*mm
text: friendica_activities.attendnoText
}
Label{color: "grey"
font.pixelSize: 1.5*mm
text: friendica_activities.attendmaybeText
}
}
Row {
CheckBox{id:likeCheckbox
height:3*mm
width:8*mm
visible: (newsitemobject.messagetype==0)? true:false
checked:(friendica_activities.self.liked)?true:false
style: CheckBoxStyle {
background: Rectangle {
implicitWidth: 7*mm
implicitHeight: 3*mm
color:"white"
}
indicator:
Rectangle{
implicitWidth: 3*mm
implicitHeight:3*mm
color:control.checked?"yellow":"white"
x: 5*mm
Text{
font.pixelSize: 1.5*mm
color:"grey"
text:":-)"
}}
}
onClicked: {
if(likeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"like",newsitemobject.status_id,root);dislikeCheckbox.checked=false}
else{Newsjs.like(root.login,root.db,0,"like",newsitemobject.status_id,root)}}
}
CheckBox{id: dislikeCheckbox
height:3*mm
width:8*mm
visible: (newsitemobject.messagetype==0)? true:false
checked: (friendica_activities.self.disliked)?true:false
style: CheckBoxStyle {
background: Rectangle {
implicitWidth: 7*mm
implicitHeight:3*mm
color:"white"
}
indicator:
Rectangle{
implicitWidth: 3*mm
implicitHeight:3*mm
color:control.checked?"yellow":"white"
x:5*mm
Text{
font.pixelSize: 1.5*mm
color:"grey"
text:":-("
}}
}
onClicked: {
if (dislikeCheckbox.checked==true){Newsjs.like(root.login,root.db,1,"dislike",newsitemobject.status_id);likeCheckbox.checked=false}
else {Newsjs.like(root.login,root.db,0,"dislike",newsitemobject.status_id,root)}}
}
Label {
id:replytoLabel
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: try {qsTr("In reply to ")+newsitemobject.reply_user.screen_name
}catch(e){" "}
}
Label {
id:attendLabel
visible: false
color: "grey"
height:3.5*mm
font.pixelSize: 1.5*mm
horizontalAlignment: Label.AlignRight
text: (friendica_activities.self.attending)?qsTr("attending: ")+ qsTr(attending):""
}
}
}
Menu {
id:newsmenu
MenuItem {
text: qsTr("Reply")
onTriggered: {
var directmessage=0;
if (newsitemobject.messagetype==1){ directmessage=1}
newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"reply_to_user": newsitemobject.user.screen_name,"parentId":newsitemobject.status_id,"login":root.login,"directmessage":directmessage}});
}
}
MenuItem {
text: qsTr("DM")
onTriggered: {
root.directmessageSignal(newsitemobject.user.screen_name);
}
}
MenuItem {
text: qsTr("Repost")
onTriggered: {
Newsjs.retweetNews(root.login,db,newsitemobject.status_id,root,function(reply){
print(reply);
})
}
}
MenuItem {
text: qsTr("Conversation")
onTriggered: {
Newsjs.requestConversation(root.login,db,newsitemobject.status_id,root.contactlist,root,function(news,newContacts){
for (var i=0;i<newContacts.length;i++){
root.updateContactInDB(root.login,root.db,0,newContacts[i])
}
Newsjs.storeNews(root.login,root.db,news,root,function(){
var currentTime= new Date();
Newsjs.conversationfromdb(db,root.login.username,newsitemobject.statusnet_conversation_id, function(newsarray){
newsModel.clear();
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsarray,'latestmessage':0};
newsWorker.sendMessage(msg);
});
}
)})
}}
Menu{
title: qsTr("Attending")
MenuItem{text:qsTr("yes")
onTriggered: {Newsjs.attend(root.login,db,"yes",newsitemobject.status_id,root,function(){
newsitem.attending="yes";
attendLabel.visible=true})}
}
MenuItem{text:qsTr("maybe")
onTriggered: {Newsjs.attend(root.login,db,"maybe",newsitemobject.status_id,root,function(){
newsitem.attending="maybe"})}
}
MenuItem{text:qsTr("no")
onTriggered: {Newsjs.attend(root.login,db,"no",newsitemobject.status_id,root,function(){
newsitem.attending="no"})}
}
}
MenuItem {
text: qsTr("Delete")
onTriggered: {
Newsjs.deleteNews(root.login,root.db,newsitemobject.status_id,newsitemobject.messagetype,root,function(reply){
print("Deleted "+reply);
newsModel.remove(index);
})
}
}
}
}}