Merge branch 'master' of ssh://drop.maemo.org/git/qwp
[qwp] / qml / qwp / content / FatDelegate.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 import QtQuick 1.0
43 import QtWebKit 1.0
44
45 Component {
46     id: listDelegate
47     Item {property real detailsOpacity : 0
48         id: wrapper; width: wrapper.ListView.view.width; height: if(txt.height > 60){txt.height+10}else{60} //50+5+5
49         function handleLink(link){
50             if(link.slice(0,3) == 'app'){
51                 screen.setUser(link.slice(7));
52             }else if(link.slice(0,4) == 'http'){
53                 Qt.openUrlExternally(link);
54             }
55         }
56         function addTags(str){
57             var ret = str.replace(/@[a-zA-Z0-9_]+/g, '<a href="app://$&">$&</a>');//click to jump to user?
58             var ret2 = ret.replace(/http:\/\/[^ \n\t]+/g, '<a href="$&">$&</a>');//surrounds http links with html link tags
59             return ret2;
60         }
61
62         // Strip away paranthesis
63         function userName(str) {
64             var user = str.replace(/\([\S|\s]*\)/gi, "");
65             return user.trim();
66         }
67
68         MouseArea {
69             anchors.fill: parent
70             onClicked: {
71                 wrapper.state = 'Details';
72                 //timer.stop();
73                 loader.sourceComponent = webViewPage;
74             }
75         }
76
77         Item {
78             id: moveMe; height: parent.height
79             Rectangle {
80                 id: blackRect
81                 color: "black"; opacity: wrapper.ListView.index % 2 ? 0.2 : 0.3; height: wrapper.height-2; width: wrapper.width; y: 1
82             }
83
84             Item {
85                 id: image; x: 6; width: 48; height: 48; smooth: true
86                 anchors.verticalCenter: parent.verticalCenter
87
88                 Loading { x: 1; y: 1; width: 48; height: 48; visible: realImage.status != Image.Ready }
89                 Image {
90                     id: realImage;
91                     source: userImage; x: 1; y: 1;
92                     width:48; height:48; opacity:0 ;
93                     onStatusChanged: {
94                         if(status==Image.Ready)
95                             image.state="loaded"
96                     }
97                 }
98                 states: State {
99                     name: "loaded";
100                     PropertyChanges { target: realImage ; opacity:1 }
101                 }
102                 transitions: Transition { NumberAnimation { target: realImage; property: "opacity"; duration: 200 } }
103
104             }
105             Text { id:txt; y:4; x: 56
106                 text: '<html><style type="text/css">a:link {color:"#aaccaa"}; a:visited {color:"#336633"}</style>'
107                       + '<a href="app://@'+userName(name)+'"><b>'+userName(name) + "</b></a> from " +source
108                       + "<br /><b>" + statusText + "</b></html>";
109                 textFormat: Qt.RichText
110                 color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrapMode: Text.WordWrap
111                 anchors.left: image.right; anchors.right: blackRect.right; anchors.leftMargin: 6; anchors.rightMargin: 6
112                 onLinkActivated: wrapper.handleLink(link)
113             }
114         }
115         Item {
116             id: details
117             x: 0; width: parent.width // - 20
118             anchors { top: parent.top; topMargin: 10; bottom: parent.bottom; bottomMargin: 10 }
119             opacity: wrapper.detailsOpacity
120
121             Grid {
122                 columns: 3
123                 id: pages
124                 height: parent.height; width: parent.width
125
126                 Component {
127                     id: webViewPage
128                     Rectangle {
129                         width: webView.width
130                         height: webView.height
131                         border.color: "gray"
132
133                         WebView {
134                             id: webView
135                             newWindowComponent: webViewPage
136                             newWindowParent: pages
137                             url: "http://fr.wikipedia.org/w/index.php?title=" + name
138                         }
139                     }
140                 }
141
142                 Loader {
143                     id: loader
144                 }
145                 // Loader { sourceComponent: webViewPage }
146             }
147         }
148
149         states: State {
150             name: "Details"
151
152             PropertyChanges { target: blackRect; color: "#c0c0c0" }
153             //PropertyChanges { target: recipeImage; width: 130; height: 130 } // Make picture bigger
154             PropertyChanges { target: wrapper; detailsOpacity: 1; x: 0 } // Make details visible
155             PropertyChanges { target: wrapper; height: wrapper.ListView.view.height } //lstRC.height } // Fill the entire list area with the detailed view
156
157             // Move the list so that this item is at the top.
158             PropertyChanges { target: wrapper.ListView.view; explicit: true; contentY: listDelegate.y }
159
160             // Disallow flicking while we're in detailed view
161             PropertyChanges { target: wrapper.ListView.view; interactive: false }
162         }
163
164
165     }
166 }