qmlui prototyping code added
authorJanne Kiiski <janne.kiiski@ixonos.com>
Wed, 10 Nov 2010 15:15:30 +0000 (17:15 +0200)
committerJanne Kiiski <janne.kiiski@ixonos.com>
Wed, 10 Nov 2010 15:15:30 +0000 (17:15 +0200)
src/engine/engine.cpp
src/qmlui/geomap.cpp [new file with mode: 0644]
src/qmlui/geomap.h [new file with mode: 0644]
src/qmlui/loginlogic.cpp [new file with mode: 0644]
src/qmlui/loginlogic.h [new file with mode: 0644]
src/qmlui/res.qrc [new file with mode: 0644]
src/qmlui/rotation.cpp [new file with mode: 0644]
src/qmlui/rotation.h [new file with mode: 0644]
src/src.pro

index f8fcf91..de809a6 100644 (file)
 #include "network/networkaccessmanager.h"
 #include "situareservice/situareservice.h"
 #include "ui/mainwindow.h"
+#include "qmlui/geomap.h"
+#include "qmlui/rotation.h"
+#include "qmlui/loginlogic.h"
+#include <qdeclarative.h>
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+#include <QApplication>
+#include <QDesktopWidget>
 
 #include "engine.h"
 
@@ -124,16 +132,31 @@ SituareEngine::SituareEngine()
     // signals connected, now it's time to show the main window
     // but init the MapEngine before so starting location is set
     m_mapEngine->init();
-    m_ui->show();
+//    m_ui->show();
+
+    // QML UI INIT
+    qmlRegisterType<GeoMap>("MapPlugin", 1, 0, "GeoMap");
 
-    m_facebookAuthenticator->start();
+    QDeclarativeView* view = new QDeclarativeView(QApplication::desktop());
+#ifdef Q_WS_MAEMO_5
+//    view.setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+#endif
+    Rotation *rotation = new Rotation();
+    view->rootContext()->setContextProperty("deviceRotation", static_cast<QObject *>(rotation));
+    LoginLogic loginLogic;
+    view->rootContext()->setContextProperty("loginLogic", &loginLogic);
+    view->setSource(QUrl("qrc:/Main.qml"));
+    view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+    view->show();
+
+    //m_facebookAuthenticator->start();
 
     m_gps->setMode(GPSPosition::Default);
     initializeGpsAndAutocentering();
 
     m_mce = new MCE(this);
     connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
-    
+
     m_contactManager = new ContactManager(this);
     m_contactManager->requestContactGuids();
 }
diff --git a/src/qmlui/geomap.cpp b/src/qmlui/geomap.cpp
new file mode 100644 (file)
index 0000000..2d1c2fe
--- /dev/null
@@ -0,0 +1,113 @@
+#include "geomap.h"
+#include <QDebug>
+#include <QGeoMapPixmapObject>
+
+using namespace QtMobility;
+
+GeoMap::GeoMap(QGraphicsItem* parent)
+    : QGraphicsGeoMap(parent),
+      source(0),
+      prevGpsLocation(0,0),
+      initialized(false)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    connect(this, SIGNAL(panned(QPoint)), this, SLOT(panned()));
+
+    setCenter(prevGpsLocation);
+
+    goToGpsLocation();
+}
+
+GeoMap::~GeoMap()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+qreal GeoMap::angleToGpsLocation() const
+{
+    const qreal result = prevGpsLocation.isValid() ? center().azimuthTo(prevGpsLocation) : 0.0;
+    qDebug() << "QmlMap::angleToGpsLocation: " << result;
+    return result;
+}
+
+qreal GeoMap::distanceToGpsLocation() const
+{
+    const qreal result = prevGpsLocation.isValid() ? center().distanceTo(prevGpsLocation) : 0.0;
+    const int km = result * 0.001;
+    qDebug() << "QmlMap::distanceToGpsLocation: " << km;
+    return km;
+}
+
+double GeoMap::centerLatitude() const {
+    return center().latitude();
+}
+
+void GeoMap::setCenterLatitude(const double latitude) {
+    QGeoCoordinate newCenter = center();
+    newCenter.setLatitude(latitude);
+    setCenter(newCenter);
+    emit positionChanged();
+}
+
+double GeoMap::centerLongitude() const
+{
+    return center().longitude();
+}
+
+void GeoMap::setCenterLongitude(const double longitude) {
+    QGeoCoordinate newCenter = center();
+    newCenter.setLongitude(longitude);
+    setCenter(newCenter);
+    emit positionChanged();
+
+}
+
+double GeoMap::gpsLocationLatitude() const
+{
+    return prevGpsLocation.latitude();
+}
+
+double GeoMap::gpsLocationLongitude() const
+{
+    return prevGpsLocation.longitude();
+}
+
+void GeoMap::panned()
+{
+    emit positionChanged();
+}
+
+void GeoMap::goToGpsLocation()
+{
+    qDebug() << "QmlMap::goToGpsLocation";
+    if (!source)
+        source = QGeoPositionInfoSource::createDefaultSource(this);
+
+    if (source) {
+        source->requestUpdate();
+        connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
+        source->setUpdateInterval(10000);
+        source->startUpdates();
+    }
+}
+
+void GeoMap::positionUpdated(const QGeoPositionInfo& positionInfo)
+{
+    qDebug() << "QmlMap::positionUpdated: " << positionInfo.coordinate();
+    prevGpsLocation = positionInfo.coordinate();
+
+    if (!initialized) {
+        initialized = true;
+        QPixmap image(":/res/gps_position.png");
+        Q_ASSERT(!image.isNull());
+        QGeoMapPixmapObject* pixmap = new QGeoMapPixmapObject(prevGpsLocation, QPoint(-image.width()/2, -image.height()/2), image);
+        addMapObject(pixmap);
+        setCenter(prevGpsLocation);
+        emit positionChanged();
+    }
+    else {
+        qobject_cast<QGeoMapPixmapObject*>(mapObjects().at(0))->setCoordinate(prevGpsLocation);
+
+    }
+    emit gpsLocationChanged();
+}
diff --git a/src/qmlui/geomap.h b/src/qmlui/geomap.h
new file mode 100644 (file)
index 0000000..37a1eb3
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef GEOMAP_H
+#define GEOMAP_H
+
+#include <QGraphicsGeoMap>
+#include <QGeoPositionInfo>
+#include <QGeoPositionInfoSource>
+#include <QGeoCoordinate>
+#include <QVector3D>
+
+using namespace QtMobility;
+
+class GeoMap : public QGraphicsGeoMap
+{
+    Q_OBJECT
+
+    Q_PROPERTY(qreal angleToGpsLocation READ angleToGpsLocation NOTIFY positionChanged)
+    Q_PROPERTY(qreal distanceToGpsLocation READ distanceToGpsLocation NOTIFY positionChanged)
+    Q_PROPERTY(double centerLatitude READ centerLatitude WRITE setCenterLatitude NOTIFY positionChanged)
+    Q_PROPERTY(double centerLongitude READ centerLongitude WRITE setCenterLongitude NOTIFY positionChanged)
+    Q_PROPERTY(double gpsLocationLatitude READ gpsLocationLatitude NOTIFY gpsLocationChanged)
+    Q_PROPERTY(double gpsLocationLongitude READ gpsLocationLongitude NOTIFY gpsLocationChanged)
+
+public:
+    GeoMap(QGraphicsItem* parent = 0);
+    virtual ~GeoMap();
+
+    qreal angleToGpsLocation() const;
+    qreal distanceToGpsLocation() const;
+
+    double centerLatitude() const;
+    void setCenterLatitude(const double latitude);
+    double centerLongitude() const;
+    void setCenterLongitude(const double longitude);
+    double gpsLocationLatitude() const;
+    double gpsLocationLongitude() const;
+
+signals:
+    void positionChanged();
+    void screenCenterChanged();
+    void gpsLocationChanged();
+
+public slots:
+    void goToGpsLocation();
+
+private slots:
+    void positionUpdated(const QGeoPositionInfo& positionInfo);
+    void panned();
+
+private:
+    QGeoPositionInfoSource *source;
+    QGeoCoordinate prevGpsLocation;
+    bool initialized;
+};
+
+#endif
diff --git a/src/qmlui/loginlogic.cpp b/src/qmlui/loginlogic.cpp
new file mode 100644 (file)
index 0000000..0afd61b
--- /dev/null
@@ -0,0 +1,86 @@
+#include "loginlogic.h"
+#include <QDebug>
+#include <QTimer>
+#include <QDialog>
+#include <QLabel>
+#include <QApplication>
+#include <QDesktopWidget>
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
+#endif
+class LoginLogicPrivate
+{
+public:
+    QString email;
+    QString password;
+
+    LoginLogicPrivate() :
+        email("janne.kiiski@gmail.com"),
+        password("mypassword")
+    {}
+};
+
+LoginLogic::LoginLogic(QObject *parent) :
+    QObject(parent), d_ptr(new LoginLogicPrivate)
+{
+}
+
+LoginLogic::~LoginLogic()
+{
+}
+
+void LoginLogic::login()
+{
+    Q_D(LoginLogic);
+    qDebug() << __PRETTY_FUNCTION__ << " user: " << d->email << " password: " << d->password;
+
+    QTimer::singleShot(5000, this, SLOT(onLoginCompleted()));
+}
+
+QString LoginLogic::email() const
+{
+    Q_D(const LoginLogic);
+    return d->email;
+}
+void LoginLogic::setEmail(const QString& email)
+{
+    Q_D(LoginLogic);
+    d->email = email;
+}
+
+QString LoginLogic::password() const
+{
+    Q_D(const LoginLogic);
+    return d->password;
+}
+
+void LoginLogic::setPassword(const QString& password)
+{
+     Q_D(LoginLogic);
+     d->password = password;
+}
+
+void LoginLogic::onLoginCompleted()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(QApplication::desktop());
+
+    QString errorMessage("login completed");
+
+    if(false) {
+        msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
+        // extra line changes are needed to make error notes broader
+        errorMessage.prepend("\n");
+        errorMessage.append("\n");
+    } else {
+        msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+    }
+    QLabel *label = new QLabel(msgBox);
+    label->setAlignment(Qt::AlignCenter);
+    label->setText(errorMessage);
+    msgBox->setWidget(label);
+    msgBox->show();
+#endif
+    emit loginCompleted(rand()%2);
+}
diff --git a/src/qmlui/loginlogic.h b/src/qmlui/loginlogic.h
new file mode 100644 (file)
index 0000000..896ce22
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef LOGINLOGIC_H
+#define LOGINLOGIC_H
+
+#include <QObject>
+#include <QScopedPointer>
+
+class LoginLogicPrivate;
+
+class LoginLogic : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged)
+    Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
+
+public:
+    LoginLogic(QObject *parent = 0);
+    virtual ~LoginLogic();
+
+    Q_INVOKABLE void login();
+
+    QString email() const;
+    void setEmail(const QString& email);
+    QString password() const;
+    void setPassword(const QString& password);
+
+signals:
+    void emailChanged();
+    void passwordChanged();
+
+    void loginCompleted(bool success);
+
+private slots:
+    void onLoginCompleted();
+
+private:
+    Q_DECLARE_PRIVATE(LoginLogic)
+    QScopedPointer<LoginLogicPrivate> d_ptr;
+};
+
+#endif // LOGINLOGIC_H
diff --git a/src/qmlui/res.qrc b/src/qmlui/res.qrc
new file mode 100644 (file)
index 0000000..6662d9c
--- /dev/null
@@ -0,0 +1,27 @@
+<RCC>
+    <qresource prefix="/">
+        <file>res/friend_list.png</file>
+        <file>res/location_search.png</file>
+        <file>res/routing.png</file>
+        <file>res/user_info.png</file>
+        <file>PanelContents.qml</file>
+        <file>Main.qml</file>
+        <file>Button.qml</file>
+        <file>res/friends/default.gif</file>
+        <file>res/friends/henri.jpg</file>
+        <file>res/friends/jussi.jpg</file>
+        <file>res/friends/katri.jpg</file>
+        <file>res/friends/pekka.jpg</file>
+        <file>FriendsModel.qml</file>
+        <file>List.qml</file>
+        <file>Map.qml</file>
+        <file>res/gps_position.png</file>
+        <file>res/gps_position_dir.png</file>
+        <file>res/sight.png</file>
+        <file>res/zoom_in.png</file>
+        <file>res/zoom_out.png</file>
+        <file>res/ixonos_logo.png</file>
+        <file>Dialog.qml</file>
+        <file>LoginWidget.qml</file>
+    </qresource>
+</RCC>
diff --git a/src/qmlui/rotation.cpp b/src/qmlui/rotation.cpp
new file mode 100644 (file)
index 0000000..ff0c7a3
--- /dev/null
@@ -0,0 +1,46 @@
+#include <QDebug>
+#include <QOrientationReading>
+#include <QOrientationSensor>
+
+#include "rotation.h"
+
+QTM_USE_NAMESPACE
+
+Rotation::Rotation(QObject *parent) :
+    QObject(parent)
+{
+//    qDebug() << __PRETTY_FUNCTION__;
+
+    m_sensor = new QOrientationSensor(this);
+    m_sensor->start();
+    connect(m_sensor, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
+}
+
+void Rotation::onReadingChanged()
+{
+//    qDebug() << __PRETTY_FUNCTION__ << m_sensor->reading()->orientation();
+
+    switch (m_sensor->reading()->orientation()) {
+        case QOrientationReading::TopUp:
+        case QOrientationReading::TopDown:
+            m_orientation = "";
+//            qDebug() << __PRETTY_FUNCTION__ << "changed to:" << m_orientation;
+            break;
+        case QOrientationReading::LeftUp:
+        case QOrientationReading::RightUp:
+            m_orientation = "potrait";
+//            qDebug() << __PRETTY_FUNCTION__ << "changed to:" << m_orientation;
+            break;
+        default:
+            break;
+    }
+
+    emit orientationChanged();
+}
+
+QString Rotation::orientation()
+{
+//    qDebug() << __PRETTY_FUNCTION__ << m_orientation;
+
+    return m_orientation;
+}
diff --git a/src/qmlui/rotation.h b/src/qmlui/rotation.h
new file mode 100644 (file)
index 0000000..0e663fb
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef ROTATION_H
+#define ROTATION_H
+
+#include <QObject>
+
+namespace QtMobility {
+class QOrientationSensor;
+}
+using QtMobility::QOrientationSensor;
+
+class Rotation : public QObject
+{
+    Q_OBJECT
+
+    Q_PROPERTY(QString orientation READ orientation NOTIFY orientationChanged)
+
+public:
+    explicit Rotation(QObject *parent = 0);
+
+    QString orientation();
+
+signals:
+    void orientationChanged();
+
+public slots:
+    void onReadingChanged();
+
+private:
+    QOrientationSensor *m_sensor;
+    QString m_orientation;
+};
+
+#endif // ROTATION_H
index a678492..63498f1 100644 (file)
@@ -5,7 +5,9 @@ TARGET = ../situare
 TEMPLATE = app
 LIBS += -lqjson
 RESOURCES += ../images.qrc \
-    ../languages.qrc
+    ../languages.qrc \
+    qmlui/res.qrc \
+
 TRANSLATIONS += ../res/languages/situare_fi.ts
 SOURCES += main.cpp \
     application.cpp \
@@ -73,7 +75,7 @@ SOURCES += main.cpp \
     ui/paneltabbar.cpp \
     ui/routingpanel.cpp \
     ui/routewaypointlistitem.cpp \
-    ui/routewaypointlistview.cpp \    
+    ui/routewaypointlistview.cpp \
     ui/searchdialog.cpp \
     ui/searchhistorylistitem.cpp \
     ui/searchhistorylistview.cpp \
@@ -85,7 +87,11 @@ SOURCES += main.cpp \
     ui/zoombutton.cpp \
     ui/zoombuttonpanel.cpp \
     user/user.cpp \
-    ui/listitemcontextbuttonbar.cpp
+    ui/listitemcontextbuttonbar.cpp \
+    qmlui/geomap.cpp \
+    qmlui/loginlogic.cpp \
+    qmlui/rotation.cpp \
+
 HEADERS += application.h \
     common.h \
     coordinates/geocoordinate.h \
@@ -123,7 +129,7 @@ HEADERS += application.h \
     routing/location.h \
     routing/route.h \
     routing/routesegment.h \
-    routing/routingcommon.h \    
+    routing/routingcommon.h \
     routing/routingservice.h \
     situareservice/imagefetcher.h \
     situareservice/situarecommon.h \
@@ -142,7 +148,7 @@ HEADERS += application.h \
     ui/imagebutton.h \
     ui/indicatorbutton.h \
     ui/indicatorbuttonpanel.h \
-    ui/listcommon.h \    
+    ui/listcommon.h \
     ui/listview.h \
     ui/listitem.h \
     ui/listitemdelegate.h \
@@ -173,9 +179,15 @@ HEADERS += application.h \
     ui/zoombutton.h \
     ui/zoombuttonpanel.h \
     user/user.h \
-    ui/listitemcontextbuttonbar.h
+    ui/listitemcontextbuttonbar.h \
+    qmlui/geomap.h \
+    qmlui/loginlogic.h \
+    qmlui/rotation.h \
+
 QT += network \
-    webkit
+    webkit  \
+    declarative
+
 DEFINES += QT_NO_DEBUG_OUTPUT
 
 simulator {
@@ -188,7 +200,7 @@ simulator {
                engine/contactmanagerprivatestub.h \
                engine/mceprivatestub.h
     CONFIG += mobility
-    MOBILITY += location
+    MOBILITY += location sensors
 } else:maemo5 {
     armel {
         DEFINES += ARMEL
@@ -212,8 +224,6 @@ simulator {
                    ui/ossoabookdialog.cpp
         HEADERS += engine/contactmanagerprivate.h \
                    ui/ossoabookdialog.h
-        CONFIG += mobility
-        MOBILITY += contacts
     } else {
         SOURCES += gps/gpspositionprivatestub.cpp \
                    network/networkhandlerprivatestub.cpp \
@@ -225,6 +235,8 @@ simulator {
         HEADERS += engine/contactmanagerprivatestub.h
     }
 
+    CONFIG += mobility
+    MOBILITY += contacts location sensors
     QT += maemo5
 
     message([QJson])