00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <QPlainTextEdit>
00042 #include <XQSensorGestureManager>
00043 #include <QDeclarativePropertyMap>
00044 #include <QSound>
00045 #include <QLabel>
00046
00047
00048 #include "sgexamplewidget.h"
00049
00050
00051 const QString soundFile = "z:/data/sounds/digital/alarm.aac";
00052
00053 const QString gestureType = "com.nokia.gesture.cover" ;
00054
00058 SGExampleWidget::SGExampleWidget(QWidget *parent) :
00059 QWidget(parent), mSensorGestureManager(0)
00060 {
00061
00062 mIntoductionMessage = new QPlainTextEdit(this);
00063 mIntoductionMessage->setReadOnly(true);
00064
00065 mApplicationTitle = new QLabel("SensureGesture Example");
00066 mApplicationTitle->setFrameStyle(QFrame::Box | QFrame::Plain);
00067 mApplicationTitle->setLineWidth(2);
00068
00069
00070 QVBoxLayout *vLayout = new QVBoxLayout() ;
00071 vLayout->addWidget(mApplicationTitle);
00072 vLayout->addWidget(mIntoductionMessage);
00073 setLayout(vLayout);
00074
00075
00076 mSound = new QSound(soundFile);
00077 mSound->setLoops(1);
00078
00079
00080 startGestureRecognition();
00081 }
00082
00087 void SGExampleWidget::startGestureRecognition()
00088 {
00089
00090 mSensorGestureManager = new XQSensorGestureManager(this);
00091
00092 writeMsg("\nConnected to the SG framework.") ;
00093
00094
00095 if(mSensorGestureManager->isGestureTypeAvailable(gestureType)) {
00096 writeMsg(gestureType + " is available.") ;
00097
00098
00099 if (mSensorGestureManager->start(gestureType)) {
00100 writeMsg(gestureType + " is started.") ;
00101
00102 writeMsg("\nThe cover gesture is recognized when the phone is in horizontal position, " \
00103 "facing up and covered.");
00104
00105
00106 connect(mSensorGestureManager,SIGNAL(recognized(QString, QDeclarativePropertyMap)),
00107 this, SLOT(handleGestureRecognition(QString, QDeclarativePropertyMap)));
00108 }
00109 }
00110 else {
00111 writeMsg(gestureType + " is not available.") ;
00112 }
00113 }
00114
00118 SGExampleWidget::~SGExampleWidget()
00119 {
00120
00121 mSound = NULL;
00122 delete mSound;
00123
00124
00125 if(mSensorGestureManager){
00126 if (mSensorGestureManager->isStarted(gestureType) == true)
00127 {
00128 mSensorGestureManager->stop(gestureType);
00129 }
00130 delete mSensorGestureManager ;
00131 }
00132 }
00133
00137 void SGExampleWidget::handleGestureRecognition(const QString &gestureType,
00138 const QDeclarativePropertyMap &attributes)
00139 {
00140 Q_UNUSED(gestureType);
00141 Q_UNUSED(attributes);
00142
00143
00144 if (!mSound->isFinished()) {
00145 mSound->stop();
00146 }
00147 mSound->play();
00148
00149
00150 mNotificationMsgBox.setText("Cover gesture detected");
00151 mNotificationMsgBox.show();
00152 mNotificationMsgBox.exec();
00153 }
00154
00158 void SGExampleWidget::writeMsg(QString msg)
00159 {
00160 qDebug() << msg;
00161 if (mIntoductionMessage)
00162 {
00163 mIntoductionMessage->appendPlainText(msg);
00164 }
00165 }