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