qtmobility/examples/qmlcontacts/example.qml
changeset 1 2b40d63a9c3d
child 4 90517678cc4f
equal deleted inserted replaced
0:cfcbf08528c4 1:2b40d63a9c3d
       
     1 import QMLContactManagerAsync 1.0
       
     2 import QmlContact 1.0
       
     3 import Qt 4.6
       
     4 
       
     5 Rectangle {
       
     6     id: topItem
       
     7     width: 320
       
     8     height: 480
       
     9 //    border.color: "bg
       
    10 //    border.width: 5
       
    11 //    radius: 10
       
    12     x: 0
       
    13     y: 0
       
    14 
       
    15     Script {
       
    16         function startup() {
       
    17             print("Hello");
       
    18 
       
    19             print("Num contacts: " + blah.numContacts);            
       
    20             blah.contacts();
       
    21         }
       
    22         function gotContacts(c) {
       
    23             if(c == undefined){
       
    24                 //print("Error, got null object for gotContacts");
       
    25                 return;
       
    26             }
       
    27             print("Got contacts: " + c.name);
       
    28             print(" Available actions: " + c.availableActions);
       
    29             print(" details: " + c.details);detailsOpacity
       
    30 
       
    31             var o = c.values("OnlineAccount");
       
    32             var q = c.values("Presence");
       
    33 
       
    34 
       
    35             nameModel.append({"name": c.name, "accountPath": "Account: " + o.AccountPath, "presence": "Status: " + q.Presence, "email": c.email});
       
    36 
       
    37             var j;
       
    38             for(j in c.details){                
       
    39                 var o = c.values(c.details[j]);
       
    40                 var i;
       
    41                 for(i in o){
       
    42                     print(" "+ c.details[j] + "/" + i + ": " + o[i]);
       
    43                 }
       
    44             }
       
    45         }
       
    46         function clickedList(index) {
       
    47             mainList.currentIndex = index;
       
    48         }
       
    49     }
       
    50     Component.onCompleted: startup();
       
    51 
       
    52     QMLContactManagerAsync {
       
    53         id: "blah"
       
    54 
       
    55         manager: "memory"
       
    56         onDataChanged: print("Data changed!");
       
    57         onContactsAdded: print("Contacts added: " + contactIds);
       
    58         onContactsLoaded: gotContacts(contact);
       
    59     }
       
    60 
       
    61     Component {
       
    62         id: listdelegate        
       
    63         Rectangle {
       
    64             id: wrapper            
       
    65             border.width: 2
       
    66             radius: 5
       
    67             height: 40
       
    68             width: topItem.width-2;            
       
    69             property real detailsOpacity: 0
       
    70             Row {
       
    71                 Item {
       
    72                     property real contactId: 0
       
    73                 }
       
    74                 Text {
       
    75                     id: nameTxt
       
    76                     text: name
       
    77                 }
       
    78                 Item {
       
    79                     id: details
       
    80                     opacity: wrapper.detailsOpacity
       
    81                     Text {
       
    82                         y: nameTxt.height
       
    83                         id: emailId
       
    84                         text: email
       
    85                     }
       
    86                     Text {
       
    87                         y: emailId.y + emailId.height
       
    88                         id: accountPathId
       
    89                         text: accountPath
       
    90                     }
       
    91                     Text {
       
    92                         y: accountPathId.y
       
    93                         x: accountPathId.x + accountPathId.width + 5
       
    94                         id: presenceId
       
    95                         text: presence
       
    96                     }
       
    97                 }                
       
    98             }
       
    99             /*
       
   100             Image {
       
   101                 id: avatar
       
   102                 height: wrapper.height-6
       
   103                 source: avatarsource
       
   104                 x: wrapper.width - avatar.width - 3
       
   105                 y: 3                
       
   106                 opacity: details.opacity
       
   107                 fillMode: Image.PreserveAspectFit
       
   108             }*/
       
   109             states: State {
       
   110                 name: "Details"
       
   111                 PropertyChanges { target: wrapper; height: presenceId.y + presenceId.height }
       
   112                 PropertyChanges { target: wrapper; detailsOpacity: 1; }
       
   113             }
       
   114 
       
   115             transitions: Transition {
       
   116                 from: ""
       
   117                 to: "Details"
       
   118                 reversible: true
       
   119                 ParallelAnimation {
       
   120                     NumberAnimation {
       
   121                         duration: 300; property: "detailsOpacity" }
       
   122                     NumberAnimation {
       
   123                         duration: 300; property: "height"  }
       
   124                 }
       
   125             }
       
   126             MouseRegion {
       
   127                 id: mr
       
   128                 width: topItem.width;
       
   129                 height: wrapper.height;
       
   130                 anchors.centerIn: parent;
       
   131                 onClicked: wrapper.state == "" ? wrapper.state = "Details" :  wrapper.state = "";
       
   132             }
       
   133         }
       
   134     }
       
   135 
       
   136     Component {
       
   137         id: listhighlight
       
   138         Rectangle {
       
   139             width: parent.width-8
       
   140             height: 40
       
   141             color: "lightsteelblue"
       
   142             radius: 5
       
   143         }
       
   144     }
       
   145 
       
   146     ListView {
       
   147         id: mainList
       
   148         model: nameModel
       
   149         width: parent.width; height: parent.height
       
   150         delegate: listdelegate
       
   151         highlight: listhighlight
       
   152         //highlightFollowsCurrentItem: true
       
   153         focus: true
       
   154         anchors.fill: parent
       
   155         highlightMoveSpeed: 5000
       
   156     }
       
   157 
       
   158 
       
   159     ListModel {
       
   160         id: nameModel
       
   161     }
       
   162 
       
   163     // Attach scrollbar to the right edge of the view.
       
   164     ScrollBar {
       
   165         id: verticalScrollBar
       
   166         opacity: 0.1
       
   167         orientation: "Vertical"
       
   168         position: mainList.visibleArea.yPosition
       
   169         pageSize: mainList.visibleArea.heightRatio
       
   170         width: 40
       
   171         height: mainList.height
       
   172         anchors.right: mainList.right
       
   173         // Only show the scrollbar when the view is moving.
       
   174         states: [
       
   175             State {
       
   176                 name: "ShowBars"; when: mainList.moving
       
   177                 PropertyChanges { target: verticalScrollBar; opacity: 1 }
       
   178             }
       
   179         ]
       
   180         transitions: [ Transition { NumberAnimation { property: "opacity"; duration: 400 } } ]
       
   181     }
       
   182 
       
   183 
       
   184 
       
   185 }
       
   186 
       
   187 
       
   188 
       
   189 // ![0]