diff options
author | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-13 07:01:54 (GMT) |
---|---|---|
committer | Leonardo Sobral Cunha <leo.cunha@nokia.com> | 2010-04-14 05:09:40 (GMT) |
commit | ffd45093795e9481505af0ae9bf5df7b6c704c72 (patch) | |
tree | 8a92da61c63c9f31ff7e7b55319be49cf8478f3a /tools | |
parent | 117e65f1f13ff3c453ab7ed8a88d042cc7eeebee (diff) | |
download | Qt-ffd45093795e9481505af0ae9bf5df7b6c704c72.zip Qt-ffd45093795e9481505af0ae9bf5df7b6c704c72.tar.gz Qt-ffd45093795e9481505af0ae9bf5df7b6c704c72.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
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 b934a70..1ae771a 100644 --- a/tools/qml/qmlruntime.h +++ b/tools/qml/qmlruntime.h @@ -126,6 +126,7 @@ public slots: protected: virtual void keyPressEvent(QKeyEvent *); + virtual bool event(QEvent *); void createMenu(QMenuBar *menu, QMenu *flatmenu); |