567e9a917292a536a4b369a039b52278d4e35bf0
[profile/ivi/qtdeclarative.git] / examples / declarative / twitter / TwitterCore / FatDelegate.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 2.0
43
44 Component {
45     id: listDelegate
46     Item {
47         id: wrapper; width: wrapper.ListView.view.width; height: if(txt.height > 60){txt.height+10}else{60} //50+5+5
48         function handleLink(link){
49             if(link.slice(0,3) == 'app'){
50                 screen.setUser(link.slice(7));
51             }else if(link.slice(0,4) == 'http'){
52                 Qt.openUrlExternally(link);
53             }
54         }
55         function addTags(str){
56             var ret = str.replace(/@[a-zA-Z0-9_]+/g, '<a href="app://$&">$&</a>');//click to jump to user?
57             var ret2 = ret.replace(/http:\/\/[^ \n\t]+/g, '<a href="$&">$&</a>');//surrounds http links with html link tags
58             return ret2;
59         }
60
61         // Strip away paranthesis
62         function userName(str) {
63             var user = str.replace(/\([\S|\s]*\)/gi, "");
64             return user.trim();
65         }
66
67         Item {
68             id: moveMe; height: parent.height
69             Rectangle {
70                 id: blackRect
71                 color: "black"; opacity: wrapper.ListView.index % 2 ? 0.2 : 0.3; height: wrapper.height-2; width: wrapper.width; y: 1
72             }
73             Item {
74                 id: image; x: 6; width: 48; height: 48; smooth: true
75                 anchors.verticalCenter: parent.verticalCenter
76
77                 Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != Image.Ready }
78                 Image {
79                     id: realImage;
80                     source: userImage; x: 1; y: 1;
81                     width:48; height:48; opacity:0 ;
82                     onStatusChanged: {
83                         if(status==Image.Ready)
84                             image.state="loaded"
85                     }
86                 }
87                 states: State {
88                     name: "loaded";
89                     PropertyChanges { target: realImage ; opacity:1 }
90                 }
91                 transitions: Transition { NumberAnimation { target: realImage; property: "opacity"; duration: 200 } }
92
93             }
94             Text { id:txt; y:4; x: 56
95                 text: '<html><style type="text/css">a:link {color:"#aaccaa"}; a:visited {color:"#336633"}</style>'
96                     + '<a href="app://@'+userName(name)+'"><b>'+userName(name) + "</b></a> from " +source
97                     + "<br /><b>" + statusText + "</b></html>";
98                 textFormat: Qt.RichText
99                 color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrapMode: Text.WordWrap
100                 anchors.left: image.right; anchors.right: blackRect.right; anchors.leftMargin: 6; anchors.rightMargin: 6
101                 onLinkActivated: wrapper.handleLink(link)
102             }
103         }
104     }
105 }