diff options
-rw-r--r-- | doc/src/declarative/qmlruntime.qdoc | 46 | ||||
-rw-r--r-- | tools/qml/deviceorientation.h | 1 | ||||
-rw-r--r-- | tools/qml/qmlruntime.cpp | 45 |
3 files changed, 51 insertions, 41 deletions
diff --git a/doc/src/declarative/qmlruntime.qdoc b/doc/src/declarative/qmlruntime.qdoc index 8bb3ec7..fbe82c6 100644 --- a/doc/src/declarative/qmlruntime.qdoc +++ b/doc/src/declarative/qmlruntime.qdoc @@ -70,7 +70,7 @@ \code qml myQmlFile.qml \endcode - + Deploying a QML application via the \c qml executable allows for QML only deployments, but can also include custom C++ modules just as easily. Below is an example of how you might structure a complex application deployed via the qml runtime, it is a listing of the files that would @@ -101,7 +101,7 @@ import "MyAppCore" import "OtherModule" 1.0 as Other \endcode - + \section1 \c qml application functionality The \c qml application implements some additional functionality to help it serve the role of a launcher for myriad applications. If you implement your own launcher application, you may also wish to reimplement @@ -134,23 +134,25 @@ Any QML can be used in the dummy data files. You could even animate the fictional data! - \section2 Screen Orientation + \section2 Runtime Object + + All applications using the qmlruntime will have access to the 'runtime' + property on the root context. This property contains several information + about the runtime environment of the application. + + \section3 Screen Orientation A special piece of dummy data which is integrated into the runtime is a simple orientation property. The orientation can be set via the settings menu in the application, or by pressing Ctrl+T to toggle it. - To use this from within your QML file, import QDeclarativeViewer 1.0 and create a - Screen object. This object has a property, orientation, which can be either - Screen.Landscape or Screen.Portrait and which can be bound to in your + To use this from within your QML file, access runtime.orientation, + which can be either Orientation.Landscape or Orientation.Portrait and which can be bound to in your application. An example is below: \code - import QDeclarativeViewer 1.0 as QDeclarativeViewer - Item { - QDeclarativeViewer.Screen { id: screen } - state: (screen.orientation == QDeclarativeViewer.Screen.Landscape) ? 'landscape' : '' + state: (runtime.orientation == Orientation.Landscape) ? 'landscape' : '' } \endcode @@ -158,4 +160,28 @@ will automatically update this on some platforms (currently the N900 only) to match the physical screen's orientation. On other plaforms orientation changes will only happen when explictly asked for. + \section3 Window Active + + The runtime.isActiveWindow property tells whether the main window of the qml runtime is currently active + or not. This is specially useful for embedded devices when you want to pause parts of your application, + including animations, when your application looses focus or goes to the background. + + The example below, stops the animation when the application's window is deactivated and resumes on activation: + +\code + Item { + width: 300; height: 200 + Rectangle { + width: 100; height: 100 + color: "green" + SequentialAnimation on x { + running: runtime.isActiveWindow + loops: Animation.Infinite + NumberAnimation {to: 200} + NumberAnimation {to: 0} + } + } + } +\endcode + */ diff --git a/tools/qml/deviceorientation.h b/tools/qml/deviceorientation.h index c8125cd..d209005 100644 --- a/tools/qml/deviceorientation.h +++ b/tools/qml/deviceorientation.h @@ -50,6 +50,7 @@ class DeviceOrientationPrivate; class DeviceOrientation : public QObject { Q_OBJECT + Q_ENUMS(Orientation) public: enum Orientation { UnknownOrientation, Portrait, Landscape }; virtual Orientation orientation() const = 0; diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index 40de100..df29294 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -112,32 +112,12 @@ QT_BEGIN_NAMESPACE -class Screen : public QObject -{ - Q_OBJECT - - Q_PROPERTY(Orientation orientation READ orientation NOTIFY orientationChanged) - Q_ENUMS(Orientation) - -public: - Screen(QObject *parent=0) : QObject(parent) { - connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), - this, SIGNAL(orientationChanged())); - } - - enum Orientation { UnknownOrientation = DeviceOrientation::UnknownOrientation, - Portrait = DeviceOrientation::Portrait, - Landscape = DeviceOrientation::Landscape }; - Orientation orientation() const { return Orientation(DeviceOrientation::instance()->orientation()); } - -signals: - void orientationChanged(); -}; - class Runtime : public QObject { Q_OBJECT + Q_PROPERTY(bool isActiveWindow READ isActiveWindow NOTIFY isActiveWindowChanged) + Q_PROPERTY(DeviceOrientation::Orientation orientation READ orientation NOTIFY orientationChanged) public: static Runtime* instance() @@ -157,20 +137,22 @@ public: emit isActiveWindowChanged(); } -signals: + DeviceOrientation::Orientation orientation() const { return DeviceOrientation::instance()->orientation(); } + +Q_SIGNALS: void isActiveWindowChanged(); + void orientationChanged(); private: - Runtime(QObject *parent=0) : QObject(parent), activeWindow(false) {} + Runtime(QObject *parent=0) : QObject(parent), activeWindow(false) + { + connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), + this, SIGNAL(orientationChanged())); + } bool activeWindow; }; -QT_END_NAMESPACE - -QML_DECLARE_TYPE(Screen) - -QT_BEGIN_NAMESPACE class SizedMenuBar : public QMenuBar { @@ -1067,7 +1049,7 @@ void QDeclarativeViewer::openQml(const QString& file_or_url) url = QUrl(file_or_url); setWindowTitle(tr("%1 - Qt Declarative UI Viewer").arg(file_or_url)); - if (!m_script.isEmpty()) + if (!m_script.isEmpty()) tester = new QDeclarativeTester(m_script, m_scriptOptions, canvas); delete canvas->rootObject(); @@ -1518,7 +1500,8 @@ void QDeclarativeViewer::setUseNativeFileBrowser(bool use) void QDeclarativeViewer::registerTypes() { - qmlRegisterType<Screen>("QDeclarativeViewer", 1, 0, "Screen"); + // registering only for exposing the DeviceOrientation::Orientation enum + qmlRegisterUncreatableType<DeviceOrientation>("Qt",4,6,"Orientation"); } QT_END_NAMESPACE |