diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-13 07:01:54 (GMT) |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2010-04-15 08:56:55 (GMT) |
commit | 8a4474d66550bddf71b5a447435d37999772079f (patch) | |
tree | 29b0f496d47278843bce461970af6bb6de33d0ad /tools | |
parent | b3d9d6e81cfafcc01a23ec0c524f91ba6db4536b (diff) | |
download | Qt-8a4474d66550bddf71b5a447435d37999772079f.zip Qt-8a4474d66550bddf71b5a447435d37999772079f.tar.gz Qt-8a4474d66550bddf71b5a447435d37999772079f.tar.bz2 |
Add 'runtime' property to the rootContext of DeclarativeViewer
The 'runtime' property is a singleton object that contains various info
about the execution environment for the qml application. Currently
it contains just one property 'isActiveWindow', which tells if the
window of the declarative viewer is active or not.
Task-number: QTBUG-8902
Reviewed-by: Martin Jones
(cherry picked from commit ffd45093795e9481505af0ae9bf5df7b6c704c72)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qml/qmlruntime.cpp | 44 | ||||
-rw-r--r-- | tools/qml/qmlruntime.h | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/tools/qml/qmlruntime.cpp b/tools/qml/qmlruntime.cpp index c4ebd80..40de100 100644 --- a/tools/qml/qmlruntime.cpp +++ b/tools/qml/qmlruntime.cpp @@ -134,6 +134,38 @@ signals: void orientationChanged(); }; +class Runtime : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool isActiveWindow READ isActiveWindow NOTIFY isActiveWindowChanged) + +public: + static Runtime* instance() + { + static Runtime *instance = 0; + if (!instance) + instance = new Runtime; + return instance; + } + + bool isActiveWindow() const { return activeWindow; } + void setActiveWindow(bool active) + { + if (active == activeWindow) + return; + activeWindow = active; + emit isActiveWindowChanged(); + } + +signals: + void isActiveWindowChanged(); + +private: + Runtime(QObject *parent=0) : QObject(parent), activeWindow(false) {} + + bool activeWindow; +}; + QT_END_NAMESPACE QML_DECLARE_TYPE(Screen) @@ -1048,6 +1080,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 +1283,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; diff --git a/tools/qml/qmlruntime.h b/tools/qml/qmlruntime.h index 6f1e425..74a0f07 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -125,6 +125,7 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); + virtual bool event(QEvent *); void createMenu(QMenuBar *menu, QMenu *flatmenu); |