diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-14 23:06:54 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-04-14 23:06:54 (GMT) |
commit | aad7bc4085980edf9fd6736efe909dc5a74a9d27 (patch) | |
tree | f44440a2633cb79b0e8e7c08315e0a8d8645a58b /tools/qml/qmlruntime.cpp | |
parent | ca52a35fa6bf4a86310d06c22aa256ab654712de (diff) | |
parent | 4174dd5dca647bfbe5ff5db1d495b7f887833323 (diff) | |
download | Qt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.zip Qt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.tar.gz Qt-aad7bc4085980edf9fd6736efe909dc5a74a9d27.tar.bz2 |
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-qml into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/qt-qml: (71 commits)
Add QML documentation for validators
Updates to the module documentation
Fix minor typo in docs
Revert "qdeclarativefocusscope works fine as a parallel test"
qdeclarativefocusscope works fine as a parallel test
Reduce warnings at shutdown
Image with PreserveAspect enabled with either width or height defined should implicitly update the undefined axis to follow the aspect ratio
Fix GridView.onRemove animation in photoviewer.
Reduce warnings at shutdown
Fix QT_NO_DESKTOPSERVICES
Compiled bindings should not print warnings where normal bindings don't
Update references links
Move example code into separate files to make sure they compile
Include qvariant.h as a convenience as context properties
Merged 'orientation' into 'runtime' context property in qmlruntime
Add 'runtime' property to the rootContext of DeclarativeViewer
Temporarily disable tests that require compilation
Fix qdeclarativedom test
Further improve failure output
Doc: more mention of using QUrl::fromLocalFile() for URLs on local filesystem
...
Diffstat (limited to 'tools/qml/qmlruntime.cpp')
-rw-r--r-- | tools/qml/qmlruntime.cpp | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index c4ebd80..df29294 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -112,33 +112,47 @@ QT_BEGIN_NAMESPACE -class Screen : public QObject +class Runtime : public QObject { Q_OBJECT - Q_PROPERTY(Orientation orientation READ orientation NOTIFY orientationChanged) - Q_ENUMS(Orientation) + Q_PROPERTY(bool isActiveWindow READ isActiveWindow NOTIFY isActiveWindowChanged) + Q_PROPERTY(DeviceOrientation::Orientation orientation READ orientation NOTIFY orientationChanged) public: - Screen(QObject *parent=0) : QObject(parent) { - connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), - this, SIGNAL(orientationChanged())); + static Runtime* instance() + { + static Runtime *instance = 0; + if (!instance) + instance = new Runtime; + return instance; } - enum Orientation { UnknownOrientation = DeviceOrientation::UnknownOrientation, - Portrait = DeviceOrientation::Portrait, - Landscape = DeviceOrientation::Landscape }; - Orientation orientation() const { return Orientation(DeviceOrientation::instance()->orientation()); } + bool isActiveWindow() const { return activeWindow; } + void setActiveWindow(bool active) + { + if (active == activeWindow) + return; + activeWindow = active; + emit isActiveWindowChanged(); + } -signals: + DeviceOrientation::Orientation orientation() const { return DeviceOrientation::instance()->orientation(); } + +Q_SIGNALS: + void isActiveWindowChanged(); void orientationChanged(); -}; -QT_END_NAMESPACE +private: + Runtime(QObject *parent=0) : QObject(parent), activeWindow(false) + { + connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()), + this, SIGNAL(orientationChanged())); + } -QML_DECLARE_TYPE(Screen) + bool activeWindow; +}; -QT_BEGIN_NAMESPACE class SizedMenuBar : public QMenuBar { @@ -1035,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(); @@ -1048,6 +1062,8 @@ void QDeclarativeViewer::openQml(const QString& file_or_url) ctxt->setContextProperty("qmlViewerFolder", QDir::currentPath()); #endif + ctxt->setContextProperty("runtime", Runtime::instance()); + QString fileName = url.toLocalFile(); if (!fileName.isEmpty()) { QFileInfo fi(fileName); @@ -1249,6 +1265,16 @@ void QDeclarativeViewer::keyPressEvent(QKeyEvent *event) QWidget::keyPressEvent(event); } +bool QDeclarativeViewer::event(QEvent *event) +{ + if (event->type() == QEvent::WindowActivate) { + Runtime::instance()->setActiveWindow(true); + } else if (event->type() == QEvent::WindowDeactivate) { + Runtime::instance()->setActiveWindow(false); + } + return QWidget::event(event); +} + void QDeclarativeViewer::senseImageMagick() { QProcess proc; @@ -1474,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 |