main.cpp 1.74 KB
Newer Older
1 2 3
#include <QtGui/QApplication>
#include <QtDeclarative>
#include "qmlapplicationviewer.h"
4
#include "activemonitor.h"
5 6
#include <stdio.h>

7

8 9
int main(int argc, char *argv[])
{
10 11 12 13 14 15 16
#if defined(Q_WS_MAEMO_5)
    bool portrait = false;
    bool fullscreen = false;
#else
    bool portrait = true;
    bool fullscreen = true;
#endif
17

18
    QApplication app(argc, argv);
19 20
    app.setProperty("NoMStyle", true);

21
    QmlApplicationViewer viewer;
22
    viewer.engine()->addImportPath("/opt/qtm11/imports");
23 24 25 26 27 28 29 30

    /**
     * Qt Quick 1.0 does not have the possibility to tell the QML if
     * the application is in the foreground or not. To fix this, we
     * monitor the changes manually in the viewer and expose a new
     * ActiveMonitor object that has an "active" property to the QML
     * context. Inside QML, use "activeMonitor.active" as boolean.
     **/
31
// TODO With Qt Quick Components, we can http://library.developer.nokia.com/topic/MeeGo_1.2_Harmattan_API/html/guide/html/Developer_Library_Application_development_framework_Application_lifecycle_a92f.html
32 33 34 35 36
    ActiveMonitor *monitor = new ActiveMonitor(&viewer);
    QObject::connect(&viewer, SIGNAL(activeChanged(bool)),
                     monitor, SLOT(activeChanged(bool)));
    viewer.rootContext()->setContextProperty("activeMonitor", monitor);

37 38
    viewer.engine()->rootContext()->setContextProperty("portraitDevice", portrait);
    viewer.setMainQmlFile("qml/attitude/qtc-root.qml");
39 40
    if (viewer.status() != QDeclarativeView::Ready || viewer.errors().length() != 0)
        viewer.setMainQmlFile("qml/attitude/Main.qml");
41

42 43 44 45 46 47 48
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockLandscape);

    if (fullscreen) {
        viewer.showFullScreen();
    } else {
        viewer.show();
    }
49

50
    app.exec();
51
}