qtmobility/examples/sensors/orientation/orientation.qml
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 5 453da2cfceef
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    48 
    48 
    49     OrientationSensor {
    49     OrientationSensor {
    50         id: orientation
    50         id: orientation
    51 
    51 
    52         onReadingChanged: {
    52         onReadingChanged: {
    53             if (reading.orientation == OrientationReading.LeftUp)
    53             if (reading.orientation == OrientationReading.TopUp)
    54                 content.state = "Portrait";
    54                 content.state = "TopUp";
    55             else if (reading.orientation == OrientationReading.BottomDown)
    55             else if (reading.orientation == OrientationReading.TopDown)
    56                 content.state = "";
    56                 content.state = "TopDown";
       
    57             else if (reading.orientation == OrientationReading.LeftUp)
       
    58                 content.state = "LeftUp";
    57             else if (reading.orientation == OrientationReading.RightUp)
    59             else if (reading.orientation == OrientationReading.RightUp)
    58                 content.state = "ReversePortrait";
    60                 content.state = "RightUp";
    59             else if (reading.orientation == OrientationReading.BottomUp)
       
    60                 content.state = "ReverseLandscape";
       
    61             else if (reading.orientation == OrientationReading.FaceUp)
    61             else if (reading.orientation == OrientationReading.FaceUp)
    62                 content.state = "FaceUp";
    62                 content.state = "FaceUp";
    63             else if (reading.orientation == OrientationReading.FaceDown)
    63             else if (reading.orientation == OrientationReading.FaceDown)
    64                 content.state = "FaceDown";
    64                 content.state = "FaceDown";
       
    65             else
       
    66                 content.state = "";
    65         }
    67         }
    66     }
    68     }
    67     Component.onCompleted: orientation.start()
    69     Component.onCompleted: orientation.start()
    68 
    70 
    69     Item {
    71     Item {
    70         id: content
    72         id: content
    71         transformOrigin: Item.Center
    73         transformOrigin: Item.Center
    72         anchors.centerIn: parent
    74         anchors.centerIn: parent
    73         Text {
    75         Text {
    74             id: text
    76             id: text
    75             text: "hello world"
    77             text: "Orientation: Unknown"
    76             color: "white"
    78             color: "white"
    77             font.pointSize: 24
    79             font.pointSize: 24
    78             anchors.centerIn: parent
    80             anchors.centerIn: parent
    79         }
    81         }
    80 
    82 
    81         states: [
    83         states: [
    82             State {
    84             State {
    83                 name: "Portrait"
    85                 name: "TopUp"
    84                 PropertyChanges { target: content; rotation: -90 }
    86                 changes: [
       
    87                     PropertyChanges { target: text; text: "Orientation: TopUp" }
       
    88                 ]
    85             },
    89             },
    86             State {
    90             State {
    87                 name: "ReversePortrait"
    91                 name: "TopDown"
    88                 PropertyChanges { target: content; rotation: 90 }
    92                 changes: [
       
    93                     PropertyChanges { target: content; rotation: 180 },
       
    94                     PropertyChanges { target: text; text: "Orientation: TopDown" }
       
    95                 ]
    89             },
    96             },
    90             State {
    97             State {
    91                 name: "ReverseLandscape"
    98                 name: "LeftUp"
    92                 PropertyChanges { target: content; rotation: 180 }
    99                 changes: [
       
   100                     PropertyChanges { target: content; rotation: -90 },
       
   101                     PropertyChanges { target: text; text: "Orientation: LeftUp" }
       
   102                 ]
       
   103             },
       
   104             State {
       
   105                 name: "RightUp"
       
   106                 changes: [
       
   107                     PropertyChanges { target: content; rotation: 90 },
       
   108                     PropertyChanges { target: text; text: "Orientation: RightUp" }
       
   109                 ]
    93             },
   110             },
    94             State {
   111             State {
    95                 name: "FaceUp"
   112                 name: "FaceUp"
    96                 PropertyChanges { target: text; text: "hello roof" }
   113                 changes: [
       
   114                     PropertyChanges { target: text; text: "Orientation: FaceUp" }
       
   115                 ]
    97             },
   116             },
    98             State {
   117             State {
    99                 name: "FaceDown"
   118                 name: "FaceDown"
   100                 PropertyChanges { target: text; text: "hello ground" }
   119                 changes: [
       
   120                     PropertyChanges { target: text; text: "Orientation: FaceDown" }
       
   121                 ]
   101             }
   122             }
   102         ]
   123         ]
   103 
   124 
   104         transitions: Transition {
   125         transitions: Transition {
   105             NumberAnimation { matchProperties: "rotation"; easing: "InOutQuad"; duration: 400 }
   126             NumberAnimation { matchProperties: "rotation"; easing: "InOutQuad"; duration: 400 }