qtmobility/examples/declarative/sfw-kinetic-example.qml
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
     1 import Qt 4.6
       
     2 
       
     3 //Layout of the mainPage
       
     4 //----------------------------------------------  ____ mainPage
       
     5 //| ------------------- ---------------------- | /
       
     6 //| | serviceList     | | dialScreen         | |/
       
     7 //| |                 | |                    | |
       
     8 //| |                 | |                    | |
       
     9 //| |                 | |                    | |
       
    10 //| ------------------- |                    | |
       
    11 //| ------------------- |                    | |
       
    12 //| | serviceDetails  | |                    | |
       
    13 //| ------------------- |                    | |
       
    14 //|                     |                    | |
       
    15 //|                     |                    | |
       
    16 //|                     |                    | |
       
    17 //|                     |                    | |
       
    18 //| ------------------- |                    | |
       
    19 //| | status          | |                    | |
       
    20 //| ------------------- ---------------------- |
       
    21 //----------------------------------------------
       
    22 
       
    23 Rectangle {
       
    24     id: mainPage
       
    25     width: 500
       
    26     height: 250
       
    27     color: "white"
       
    28 
       
    29     ServiceList {
       
    30         id: serviceList
       
    31         height: childrenRect.height + 10
       
    32         width: childrenRect.width
       
    33         anchors.top: parent.top
       
    34         anchors.left: parent.left
       
    35         anchors.right: dialScreen.left
       
    36         anchors.topMargin: 5
       
    37         anchors.leftMargin: 5
       
    38         anchors.rightMargin: 5
       
    39         radius: 5
       
    40         color: "steelblue"
       
    41         border.color: "black"
       
    42         border.width: 3
       
    43         gradient:     
       
    44             Gradient {
       
    45                 GradientStop {
       
    46                     position: 0.0
       
    47                     color: "lightsteelblue"
       
    48                 }
       
    49                 
       
    50                 GradientStop {
       
    51                     position: 1.0
       
    52                     color: "steelblue"
       
    53                 }
       
    54             }
       
    55         onServiceSelected: { ServiceSelected(); }
       
    56     }
       
    57 
       
    58     Script {
       
    59         function ServiceSelected()
       
    60         {
       
    61             serviceDetails.text = "Selected dial service:" + "\n   " + 
       
    62                                    serviceList.dialService.serviceName + 
       
    63                                    "\n   (" + serviceList.dialService.version + ")";
       
    64         }
       
    65     }
       
    66     
       
    67     Text {
       
    68         id: serviceDetails
       
    69         text: "Selected dial service:"
       
    70         anchors.topMargin: 5
       
    71         anchors.leftMargin: 5
       
    72         anchors.rightMargin: 5;
       
    73         anchors.left: parent.left
       
    74         anchors.top: serviceList.bottom
       
    75     }
       
    76     
       
    77     Text {
       
    78         id: status
       
    79         anchors.top: parent.bottom
       
    80         anchors.left: parent.left
       
    81         anchors.topMargin: -40
       
    82         anchors.leftMargin: 5
       
    83     }
       
    84     
       
    85     Timer {
       
    86         id: clearStatusTimer
       
    87         interval: 2000
       
    88         running: false
       
    89         repeat: false
       
    90         onTriggered: {
       
    91             status.text = ""
       
    92         }
       
    93     }
       
    94 
       
    95     //! [0]
       
    96     DialScreen {
       
    97         id: dialScreen
       
    98         property bool activeCall : false
       
    99         property var currentDialer: 0;
       
   100         anchors.topMargin: 5
       
   101         anchors.leftMargin: 5
       
   102         anchors.rightMargin: 5
       
   103         anchors.right: parent.right
       
   104         anchors.top: parent.top
       
   105         onDial: {
       
   106             if (activeCall == false) {
       
   107                 if (serviceList.dialService != 0) {
       
   108                     var o = serviceList.dialService.serviceObject();
       
   109                     status.text = "Dialing " + numberToDial +"...";
       
   110                     dialScreen.currentDialer = o;
       
   111                     o.dialNumber(numberToDial);
       
   112                     activeCall = true;
       
   113                 }
       
   114             }
       
   115         }
       
   116         onHangup: {
       
   117             if (activeCall) {
       
   118                 if (dialScreen.currentDialer != 0) {
       
   119                     dialScreen.currentDialer.hangup();
       
   120                 }
       
   121                 status.text = "Hang up";
       
   122             }
       
   123         }
       
   124     }
       
   125     //! [0]
       
   126 
       
   127     //! [1]
       
   128     Connection {
       
   129         sender: dialScreen
       
   130         signal: "stateChanged()"
       
   131         script: { 
       
   132             if (dialScreen.currentDialer.state == 1) {
       
   133                 status.text += "\nRinging";
       
   134             } 
       
   135             else if (dialScreen.currentDialer.state == 2) {
       
   136                 status.text += "\nConnected";
       
   137             } 
       
   138             else if (dialScreen.currentDialer.state == 0) {
       
   139                 status.text += "\nConnection terminated";
       
   140                 dialScreen.activeCall = false;
       
   141                 clearStatusTimer.running = true;
       
   142             } 
       
   143             else if (dialScreen.currentDialer.state == 3) {
       
   144                 status.text += "\nPhone already engaged";
       
   145             }
       
   146         }
       
   147     }
       
   148     //! [1]
       
   149 }