123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- #include "accelerometerwidget.h"
- #include <QString>
- #include <QFile>
- #include <QTextStream>
- #include <QGridLayout>
- #include <QPushButton>
- #include <QMessageBox>
- #include <QFile>
- #include <phonon/MediaObject>
- accelerometerWidget::accelerometerWidget(QWidget *parent)
- : QWidget(parent)
- {
- setFont(QFont("Nokia Sans", 50, QFont::Bold));
- QGridLayout *grid = new QGridLayout;
- label1 = new QLabel("X");
- label1->setAlignment(Qt::AlignCenter);
- grid->addWidget(label1, 0, 0);
- label2 = new QLabel("Y");
- label2->setAlignment(Qt::AlignCenter);
- grid->addWidget(label2, 0, 1);
- label3 = new QLabel("Z");
- label3->setAlignment(Qt::AlignCenter);
- grid->addWidget(label3, 0, 2);
- xlabel = new QLabel("NaN");
- xlabel->setAlignment(Qt::AlignCenter);
- grid->addWidget(xlabel, 1, 0);
- ylabel = new QLabel("NaN");
- ylabel->setAlignment(Qt::AlignCenter);
- grid->addWidget(ylabel, 1, 1);
- zlabel = new QLabel("NaN");
- zlabel->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
- grid->addWidget(zlabel, 1, 2);
- currentxtx = new QLabel("NaN");
- currentxtx->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
- grid->addWidget(currentxtx, 2, 0);
- currentxty = new QLabel("NaN");
- currentxty->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
- grid->addWidget(currentxty, 2, 1);
- QPushButton *bouton = new QPushButton("Exit",this);
- grid->addWidget(bouton,2,2);
- connect(bouton,SIGNAL(clicked()),this,SLOT(close()));
- setLayout(grid);
- myThread = new accelerometerClass(this);
- connect(myThread, SIGNAL(deviceOrientation(QString, QString, QString)),
- this, SLOT(showData(QString, QString, QString)));
- myThread->start(QThread::NormalPriority);
- fileAlarm = new QFile(":/audio/CarAlarm.wav");
- if(!fileAlarm)
- qWarning()<<"Object fileAlarm is empty";
- fileCar = new QFile(":/audio/bip_car.wav");
- if(!fileCar)
- qWarning()<<"Object fileAlarm is empty";
- car = new Phonon::MediaObject(this);
- bipCar = new Phonon::MediaObject(this);
- car->setCurrentSource(fileAlarm);
- bipCar->setCurrentSource(fileCar);
- //connect(car, SIGNAL(finished()),this,SLOT(play()));
- }
- //void accelerometerWidget::currentValue(QString x, QString y)
- //{
- //}
- void accelerometerWidget::valueCurrent()
- {
- current=false;
- }
- void accelerometerWidget::showData(QString x, QString y, QString z)
- {
- if(!current)
- {
- //currentValue(x,y);
- currentx=x;
- currenty=y;
- current=true;
- }
- currentxtx->setText(currentx);
- currentxty->setText(currenty);
- if(currentx.toInt() + 250 < x.toInt() || currentx.toInt() - 250 > x.toInt() )
- {
- xlabel->setText("ALARME!");
- //SLOT(voitureAlarm());
- //connect(car, SIGNAL(finished()),this,SLOT(play()));
- car->play();
- }else
- xlabel->setText(x);
- if(currenty.toInt() + 250 < y.toInt() || currenty.toInt() - 250 > y.toInt() )
- {
- ylabel->setText("ALARME!");
- //if(car->isFinished())
- SLOT(voitureAlarm());
- //bipCar->play();
- }else
- ylabel->setText(y);
- zlabel->setText(z);
- }
- void accelerometerWidget::voitureAlarm()
- {
- //car->play();
- //connect(car, SIGNAL(finished()),this,SLOT(play()));
- // QSound::play("audio/CarAlarm.wav");
- //if (!QSound::isAvailable()) {
- // Bail out. Programs in which sound is not critical
- // could just silently (hehe) ignore the lack of a server.
- //
- /* QMessageBox::warning(this,"No Sound",
- "<p><b>Sorry, you are not running the Network Audio System.</b>"
- "<p>If you have the `au' command, run it in the background before this program. "
- "The latest release of the Network Audio System can be obtained from:"
- "<pre>\n"
- " \n"
- " ftp.ncd.com:/pub/ncd/technology/src/nas\n"
- " ftp.x.org:/contrib/audio/nas\n"
- "</pre>"
- "<p>Release 1.2 of NAS is also included with the X11R6"
- "contrib distribution."
- "<p>After installing NAS, you will then need to reconfigure Qt with NAS sound support");}
- */
- }
- void accelerometerWidget::voitureBip()
- {
- //QSound::play("Cbip_car.wav");
- bipCar->play();
- //connect(bipCar, SIGNAL(finished()),this,SLOT(play()));
- }
|