examples/QtQuick/videoapp/qml/videoapp/main.qml

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation
00006 **
00007 **
00008 ** $QT_BEGIN_LICENSE:BSD$
00009 ** You may use this file under the terms of the BSD license as follows:
00010 **
00011 ** "Redistribution and use in source and binary forms, with or without
00012 ** modification, are permitted provided that the following conditions are
00013 ** met:
00014 **   * Redistributions of source code must retain the above copyright
00015 **     notice, this list of conditions and the following disclaimer.
00016 **   * Redistributions in binary form must reproduce the above copyright
00017 **     notice, this list of conditions and the following disclaimer in
00018 **     the documentation and/or other materials provided with the
00019 **     distribution.
00020 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
00021 **     the names of its contributors may be used to endorse or promote
00022 **     products derived from this software without specific prior written
00023 **     permission.
00024 **
00025 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00026 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00027 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00029 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00030 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00031 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00035 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
00036 ** $QT_END_LICENSE$
00037 **
00038 ****************************************************************************/
00039 
00040 
00041 import QtQuick 1.0
00042 import com.nokia.symbian 1.0
00043 import QtMobility.sensors 1.1
00044 
00045 ApplicationWindow {
00046     id: window
00047 
00048     function setStateIfFound(target, name) {
00049         for (var i = 0; i < target.states.length; i++) {
00050             var curState = target.states[i];
00051             if(curState.name == name) {
00052                 target.state = name
00053                 break
00054             }
00055         }
00056     }
00057 
00058     ToolBarLayout {
00059         id: commonTools
00060         ToolButton {
00061             flat: true
00062             iconSource: "qrc:/toolbar_back.svg"
00063             onClicked: pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
00064         }
00065 
00066         ToolButton {
00067             flat: true
00068             iconSource: "qrc:/qgn_prop_hl_folder_open.svg"
00069             onClicked:
00070             {
00071                 video.open()
00072                 // Deactivate the sensors.
00073                 myOrientationSensor.active = false;
00074                 myProximitySensor.active = false;
00075             }
00076         }
00077 
00078         ToolButton {
00079             flat: true
00080             iconSource: "qrc:/toolbar_play.svg"
00081             onClicked:
00082             {
00083                 video.play()
00084                // Activate the sensors.
00085                 myOrientationSensor.active = true;
00086                 myProximitySensor.active = true;
00087             }
00088     }
00089 
00090         ToolButton {
00091             flat: true
00092             iconSource: "qrc:/toolbar_pause.svg"
00093             onClicked:
00094             {
00095                 video.pause()
00096                 // Activate the sensors.
00097                 myOrientationSensor.active = false;
00098                 myProximitySensor.active = false;
00099             }
00100     }
00101         ToolButton {
00102             flat: true
00103             iconSource: "qrc:/toolbar_stop.svg"
00104             onClicked:
00105             {
00106                 video.stop()
00107               }
00108         }
00109 
00110     }
00111 
00112     Page {
00113         id: page
00114         anchors.fill: parent
00115         tools: commonTools
00116 
00117         Component.onCompleted: {
00118             if(screen.currentOrientation == Screen.Portrait) {
00119                 setStateIfFound(page, "PortraitState")
00120             } else if(screen.currentOrientation == Screen.Landscape) {
00121                 setStateIfFound(page, "LandscapeState")
00122             }
00123         }
00124 
00125         Rectangle{
00126             id:mainRect
00127             color: "grey"
00128             width: page.width
00129             height: page.height
00130            }
00131 
00132         // Text to display the application name.
00133         PageHeading{
00134             id: heading
00135             anchors.top: parent.top
00136             width: parent.width
00137             text: "Video player"
00138             fontItalic: true
00139         }
00140         // These messages are aligned towards the top left corner of the screen.
00141         Text {
00142                 id: textDisplay
00143                 height: 30
00144                 text: ""
00145                 //readOnly: true
00146                 font.bold: true
00147                 font.pixelSize: 25
00148                 anchors.top: page.top
00149                 anchors.topMargin: 50
00150                 anchors.left: page.left
00151                 anchors.leftMargin: 15
00152                 font.italic: true
00153 
00154             }
00155 
00156          // Proximity Sensor element.
00157          ProximitySensor{
00158              id: myProximitySensor
00159              onReadingChanged: {
00160                  updatePlayer()
00161              }
00162          }
00163 
00164          // Orientation Sensor element.
00165          OrientationSensor{
00166              id: myOrientationSensor
00167              onReadingChanged: {
00168                  updatePlayer()
00169              }
00170          }
00171 
00172 
00173 
00174              // Flag to control the player using sensors.
00175              property bool toggleFlag: false
00176 
00177 
00178                  // Update video playing based on changing sensor data.
00179              function updatePlayer()
00180              {
00181                  // Only if orientation is face down and proximity is close, pause the player if it was playing.
00182                  if(( myOrientationSensor.reading.orientation == OrientationReading.FaceDown ) && ( myProximitySensor.reading.close == true ))
00183                  {
00184                      video.pause();
00185                      toggleFlag = true;
00186                  }
00187                  else if(toggleFlag == true)
00188                  {
00189                      video.play();
00190                      toggleFlag = false;
00191                  }
00192              }
00193 
00194          // Prints info message on the device screen.
00195          // These messages are aligned towards the top left corner of the screen.
00196 
00197 
00198 
00199              // The volume slider.
00200              Rectangle {
00201                  // Container for the sliding bar.
00202                  id: container
00203                  // Positioning of the container within the UI.
00204                  anchors { bottom: parent.bottom; left: parent.left
00205                      right: parent.right; leftMargin: 30; rightMargin: 30
00206                      //bottomMargin:parent.bottom+100 // ( 10+50+15 )   // mainRect.bottommargin + Button height + spacing.
00207                  }
00208                  height: 16
00209 
00210                  radius: 8
00211                  opacity: 0.7
00212                  smooth: true
00213                  gradient: Gradient {
00214                      GradientStop { position: 0.0; color: "gray" }
00215                      GradientStop { position: 1.0; color: "white" }
00216                  }
00217                  // This rectangle forms the sliding bar, used for adjusting the volume.
00218                  Rectangle {
00219                      id: slider
00220                      // Offsets, height and width of the slider.
00221                      x: 1; y: 1; width: 30; height: 14
00222                      radius: 6   // This results in a rounded rectangle.
00223                      smooth: true
00224                      gradient: Gradient {
00225                          GradientStop { position: 0.0; color: "#424242" }
00226                          GradientStop { position: 1.0; color: "black" }
00227                      }
00228 
00229                      // This ensbles the slider bar to take mouse events, and invoke necessary actions.
00230                      MouseArea {
00231                          anchors.fill: parent
00232                          anchors.margins: -16 // Increase mouse area a lot outside the slider
00233                          drag.target: parent; drag.axis: Drag.XAxis
00234                          drag.minimumX: 2; drag.maximumX: container.width - 32;
00235                          // Obtains the change in the slider position and appropraitely does the volume setting.
00236                          onPositionChanged:
00237                          {
00238                             video.volume = slider.x * 100 / (container.width - 34);
00239                          }
00240                      }
00241                  }
00242              }
00243 
00244 
00245 
00246 
00247     }
00248     Component.onCompleted: pageStack.push(page)
00249 
00250     Connections{
00251         target: video
00252         onDisplayMessage: textDisplay.text = video.showResponse()
00253     }
00254 }

Generated by  doxygen 1.6.2