Source

wazapp / UI / pics / SpeechBubble.qml

// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5 
import QtQuick 1.1 
import com.nokia.meego 1.0

Rectangle {

    id: bubble

    property string picture;
    property string message;
    property bool from_me;
    property string date;
    property string name;
    property int msg_id;
    property string state_status;

    state: state_status;



    width: parent.width
    height:msg_text.height+10+msg_date.height+sender_name.height;
    color:"transparent"

    states: [
        State {
            name: "sending"
            PropertyChanges {
                target: status
                source: "pics/indicators/sending.png"
            }
        },
        State {
            name: "pending"
            PropertyChanges {
                target: status
                source: "pics/indicators/pending.png"
            }
        },
        State {
            name: "delivered"
            PropertyChanges {
                target: status
                source: "pics/indicators/delivered.png"
            }
        }
    ]

    Column{
        visible: !from_me
        width:80;
        height:80;
        anchors.right: realBubble.left
        anchors.top: realBubble.top
        anchors.rightMargin: 15

        Rectangle{

            height:parent.width
            width:parent.width
            color:"transparent"
            Image{
                id:sender_picture
                width:parent.width
                height:parent.height
                fillMode: Image.PreserveAspectFit
                opacity:appWindow.stealth?0.2:1
                Component.onCompleted: {
                    if(!from_me)
                        sender_picture.source=picture
                }
            }
        }
    }


    Rectangle
    {
        id:realBubble
        radius: 5
        width:parent.width-150
        height: parent.height
        color: appWindow.stealth?"transparent":(from_me?(theme.inverted?"#69de4a":"#cfd2d4"):(theme.inverted?"#27a01b":"#42b6f2"));
        opacity:theme.inverted?0.9:1

        anchors.right: from_me?this.right:parent.right
        anchors.left: !from_me?this.left:parent.left
        anchors.rightMargin: 5
        anchors.leftMargin: 5

        Image {
            id: status
            visible: from_me
            anchors.right: parent.right
            anchors.rightMargin: 5
            anchors.top:parent.top
            anchors.topMargin: 5

        }
        Column{
            id:content
            //anchors.fill: parent;
            height:parent.height
            width:parent.width

            Label{
                id:sender_name
                width:parent.width;
                color:appWindow.stealth?colorPicker.color:(from_me?"black":"white")
                text:from_me?"You":name
                font.pixelSize: 20
                font.bold: true
                anchors.left: parent.left
                anchors.leftMargin: 5

            }
            Label{
                    id:msg_text
                    text:linkify(message);
                    color:appWindow.stealth?colorPicker.color:(from_me?"black":"white")
                    width:parent.width - 5
                    wrapMode: "WrapAtWordBoundaryOrAnywhere"
                    anchors.left: parent.left
                    anchors.leftMargin: 5
		textFormat: Text.RichText

		function linkify(inputText) {
    			var replacedText, replacePattern1, replacePattern2, replacePattern3;

    			//URLs starting with http://, https://, or ftp://
    			replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    			replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');

    			//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
    			replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
    			replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');

    			//Change email addresses to mailto:: links.
    			replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
    			replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

    			return replacedText
		}
		
	
		onLinkActivated: Qt.openUrlExternally(link);

            }

            Separator{
                top_margin: 5;
                bottom_margin: 2;
                visible:!appWindow.stealth
            }

            Label{
                id:colorPicker
                visible:false
            }

            Label{
                    id:msg_date

                    color:appWindow.stealth?colorPicker.color:(from_me?"black":"white")
                    text: date
                    anchors.right: parent.right
                    anchors.rightMargin: 5
                    font.pixelSize: 15
            }

        }

    }


}