Adding mixedview project
authorWesley Thierry <wesleyt@symbian.org>
Wed, 20 Oct 2010 12:55:41 -0700
changeset 0 061910b224a4
child 1 3e3364c5ae1c
child 3 2e16639599b7
Adding mixedview project
MixedView/MixedView.pro
MixedView/main.cpp
MixedView/mainwindow.cpp
MixedView/mainwindow.h
MixedView/mainwindow.ui
MixedView/media/intro.mp3
MixedView/media/landscapeMaze.png
MixedView/media/maze.jpg
MixedView/media/pacman_intro.wav
MixedView/resources.qrc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/MixedView.pro	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,35 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-10-15T08:28:58
+#
+#-------------------------------------------------
+
+QT       += core gui multimedia
+
+TARGET = MixedView
+TEMPLATE = app
+
+
+SOURCES += main.cpp\
+        mainwindow.cpp
+
+HEADERS  += mainwindow.h
+
+FORMS    += mainwindow.ui
+
+INCLUDEPATH+=../../../src/sensors ../../src/multimedia ../../src/multimedia/audio
+
+
+CONFIG += mobility
+MOBILITY += contacts messaging systeminfo sensors multimedia
+
+symbian {
+    TARGET.UID3 = 0xe4cef592
+    LIBS += -lcone -leikcore -lavkon
+    TARGET.CAPABILITY += LocalServices ReadUserData WriteUserData NetworkServices UserEnvironment Location ReadDeviceData
+    TARGET.EPOCSTACKSIZE = 0x14000
+    TARGET.EPOCHEAPSIZE = 0x020000 0x800000
+}
+
+RESOURCES += \
+    resources.qrc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/main.cpp	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,39 @@
+#include <QtGui/QApplication>
+#include "mainwindow.h"
+
+// Needed Symbian specific headers
+#ifdef Q_OS_SYMBIAN
+#include <eikenv.h>
+#include <eikappui.h>
+#include <aknenv.h>
+#include <aknappui.h>
+#include <coeaui.h>
+#endif
+
+int main(int argc, char *argv[])
+{
+    QApplication a(argc, argv);
+
+
+
+
+    MainWindow w;
+    a.installEventFilter(&w);
+    w.setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+
+    // Symbian specific code
+#ifdef Q_OS_SYMBIAN
+    CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
+    if(appUi){
+      TRAP_IGNORE( appUi->SetOrientationL( CAknAppUi::EAppUiOrientationPortrait ) );
+    }
+#endif
+
+#if defined(Q_WS_S60)
+    w.showMaximized();
+#else
+    w.show();
+#endif
+
+    return a.exec();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/mainwindow.cpp	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,327 @@
+#include "mainwindow.h"
+#include "ui_mainwindow.h"
+#include <QGraphicsProxyWidget>
+#include <QFormLayout>
+#include <QHBoxLayout>
+#include <QLineEdit>
+#include <QGroupBox>
+#include <QResizeEvent>
+#include <QFile>
+#include <QStringList>
+#include <QSound>
+
+
+MainWindow::MainWindow(QWidget *parent) :
+    QMainWindow(parent),
+    ui(new Ui::MainWindow)
+{
+    this->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
+    ui->setupUi(this);
+    mPacState = 0;
+    bIsMoving = true;
+    xAxis = yAxis = 0;
+    mLastPt.setX(0);
+    mLastPt.setY(0);
+    mPause = false;
+
+    // declare the accelerometer
+    mAccelerometer = new QAccelerometer(this);
+    mAccelerometer->start();
+
+    QSize screenSize = this->size();
+    mScene = new QGraphicsScene();
+
+    QRect sceneRect = ui->mainGraphicsView->rect();
+    mScene->setSceneRect(sceneRect);
+   // scene->setBackgroundBrush (QBrush(Qt::blue));
+
+    QPixmap mazeImage(":/media/maze.jpg");
+    int width = screenSize.width();
+    mazeImage = mazeImage.scaledToWidth(width);
+    QGraphicsPixmapItem *backGround = mScene->addPixmap(mazeImage);
+    backGround->setPos(-140,-200);
+
+    mPacman = new QGraphicsEllipseItem(0, 0, 18, 18);
+    mPacman->setBrush(QBrush(Qt::yellow));
+    mPacman->setSpanAngle(4500);
+    mScene->addItem(mPacman);
+
+    // lets place a pause button in the view
+    pauseButton = new QPushButton("Pause");
+    connect(pauseButton, SIGNAL(clicked()), this, SLOT(pause()));
+    pauseButton->setMaximumHeight(40);
+    pauseButton->setMaximumWidth(300);
+    QGraphicsProxyWidget *buttonProxy = mScene->addWidget(pauseButton);
+    buttonProxy->setPos(0, -220);
+
+    // now set up the boundries
+    setupBoundries();
+
+    ui->mainGraphicsView->setScene(mScene);
+    ui->mainGraphicsView->show();
+
+    mPacman->setPos(20,-8);
+
+    // declare our update timer
+    mUpdateTimer = new QTimer(this);
+    connect(mUpdateTimer, SIGNAL(timeout()), this, SLOT(updateGraphics()));
+    mUpdateTimer->start(250);
+
+    // connect the accelerometer to the readingChanged signal
+    connect(mAccelerometer, SIGNAL(readingChanged()), this, SLOT(updateReading()));
+
+    //mPlayer = new QMediaPlayer;
+    QMediaResource res(QUrl::fromLocalFile(":/media/pacman_intro.wav"));
+    QString codec = res.audioCodec();
+    QAudioFormat format;
+    // Set up the format, eg.
+    format.setFrequency(8000);
+    format.setChannels(1);
+    format.setSampleSize(8);
+    format.setCodec("audio/pcm");
+    format.setByteOrder(QAudioFormat::LittleEndian);
+    format.setSampleType(QAudioFormat::UnSignedInt);
+
+    QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
+    if (!info.isFormatSupported(format)) {
+        //qWarning()<<"raw audio format not supported by backend, cannot play audio.";
+        return;
+    }
+      // file.setFileName(":/media/pacman_intro.wav");
+      //  file.open(QIODevice::ReadOnly);
+
+
+      //  int size = file.size();
+
+       // mAudio = new QAudioOutput(format, this);
+      //  file.setParent(mAudio);
+
+      //  mAudio->start(&file);
+       // QSound::play(":/media/pacman_intro.wav");
+
+       // mPlayer->setMedia(QUrl::fromLocalFile(":/media/intro.mp3"));
+        //int leg = mPlayer->duration();
+       // mPlayer->setVolume(100);
+        //mPlayer->play();
+
+
+    mNumHits = 1;
+}
+
+MainWindow::~MainWindow()
+{
+    delete ui;
+}
+
+void MainWindow::updateGraphics() {
+    if (mPause || mNumHits > 1)
+        return;
+
+    if (!bIsMoving)
+        return;
+    switch (mPacState) {
+    case 0:
+        mPacman->setSpanAngle(5700);
+        break;
+    case 1:
+        mPacman->setSpanAngle(4500);
+        break;
+    case 2:
+        mPacman->setSpanAngle(4000);
+        break;
+    default:
+        break;
+    }
+
+    mPacState += 1;
+    if (mPacState == 2)
+        mPacState = 0;
+}
+
+void MainWindow::updateReading() {
+    if (mPause)
+        return;
+    mNumHits = mPacman->collidingItems().count();
+    if (mNumHits == 1)
+        mLastPt = mPacman->pos();
+    xAxis = (xAxis + mAccelerometer->reading()->x()) / 2;
+    yAxis = (yAxis + mAccelerometer->reading()->y()) / 2;
+
+    QPointF pt =  mPacman->pos();
+
+    pt.setX(pt.x()-xAxis);
+    pt.setY(pt.y()+yAxis);    
+
+    if (pt.x()<-103)
+        pt.setX(-103);
+    else if (pt.x()>180)
+        pt.setX(180);
+
+    if (pt.y()<-156)
+        pt.setY(-156);
+    else if (pt.y()>145)
+        pt.setY(145);
+
+
+    QList<QGraphicsItem*> itemList = mScene->items();
+    int itemCount = itemList.count();
+    bool contains = false;
+    for (int i=0;i < itemCount; i++) {
+        QGraphicsItem *item = itemList.at(i);
+        if (item->contains(pt))
+            contains = true;
+    }
+    if (mNumHits == 1) {
+        mPacman->setPos(pt);
+
+    }
+    else
+        mPacman->setPos(mLastPt);
+
+
+}
+
+void MainWindow::pause() {
+    mPause = !mPause;
+    if (mPause)
+        pauseButton->setText("Play");
+    else
+        pauseButton->setText("Pause");
+}
+
+
+void MainWindow::statusChanged(QMediaPlayer::MediaStatus status) {
+    switch (status) {
+    case QMediaPlayer::LoadedMedia:
+        mPlayer->play();
+        break;
+    default:
+        break;
+    }
+}
+
+void MainWindow::setupBoundries() {
+    // borders
+    QGraphicsRectItem *mRect1 = new QGraphicsRectItem(0,0,82,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(5,14);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,46);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(40,15);
+
+    mRect1 = new QGraphicsRectItem(0,0,82,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(5,91);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,46);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(40,92);
+
+    //
+    mRect1 = new QGraphicsRectItem(0,0,47,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-47,-136);
+
+    mRect1 = new QGraphicsRectItem(0,0,50,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(88,-136);
+
+    // center square
+    mRect1 = new QGraphicsRectItem(0,0,57,35);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(17,-46);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,55);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(40,-160);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,46);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-82,-131);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,46);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(160,-131);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,64);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-67,-60);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,64);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(153,-60);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-22,-85);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(103,-85);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-27,45);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(108,45);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-71,93);
+
+    mRect1 = new QGraphicsRectItem(0,0,11,48);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(158,95);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-63,43);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(108,45);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,12);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-70,128);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,11);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(122,132);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,12);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(-23,-85);
+
+    mRect1 = new QGraphicsRectItem(0,0,47,12);
+    mRect1->setBrush(QBrush(Qt::transparent));
+    mScene->addItem(mRect1);
+    mRect1->setPos(67,-85);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/mainwindow.h	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,59 @@
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <QMainWindow>
+#include <QPushButton>
+#include <QGraphicsEllipseItem>
+#include <QTimer>
+#include <QAccelerometer>
+#include <QLineEdit>
+#include <QGraphicsProxyWidget>
+#include <QMediaPlayer>
+#include <QMediaPlaylist>
+#include <QMediaServiceProvider>
+#include <QAudioOutput>
+#include <QFile>
+QTM_USE_NAMESPACE
+
+namespace Ui {
+    class MainWindow;
+}
+
+class MainWindow : public QMainWindow
+{
+    Q_OBJECT
+
+public:
+    explicit MainWindow(QWidget *parent = 0);
+    ~MainWindow();
+
+private:
+    Ui::MainWindow *ui;
+    QGraphicsEllipseItem *mPacman;
+    QTimer *mUpdateTimer;
+    int mPacState;
+    bool bIsMoving;
+    QAccelerometer *mAccelerometer;
+    qreal xAxis, yAxis;
+    QPointF mLastPt;
+    bool mPause;
+    QPushButton *pauseButton;
+    QMediaPlayer *mPlayer;
+    QMediaPlaylist *mPlayList;
+    QGraphicsScene *mScene;
+    int mNumHits;
+    QAudioOutput* mAudio;
+    QFile file;
+
+private slots:
+    void updateGraphics();
+    void updateReading();
+    void pause();
+    void statusChanged(QMediaPlayer::MediaStatus);
+
+private:
+    void setupBoundries();
+
+};
+
+#endif // MAINWINDOW_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/mainwindow.ui	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>360</width>
+    <height>640</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <property name="windowTitle">
+   <string>MainWindow</string>
+  </property>
+  <widget class="QWidget" name="centralWidget">
+   <layout class="QVBoxLayout" name="verticalLayout">
+    <item>
+     <widget class="QGraphicsView" name="mainGraphicsView"/>
+    </item>
+   </layout>
+  </widget>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
Binary file MixedView/media/intro.mp3 has changed
Binary file MixedView/media/landscapeMaze.png has changed
Binary file MixedView/media/maze.jpg has changed
Binary file MixedView/media/pacman_intro.wav has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MixedView/resources.qrc	Wed Oct 20 12:55:41 2010 -0700
@@ -0,0 +1,7 @@
+<RCC>
+    <qresource prefix="/">
+        <file>media/maze.jpg</file>
+        <file>media/intro.mp3</file>
+        <file>media/pacman_intro.wav</file>
+    </qresource>
+</RCC>