summaryrefslogtreecommitdiffstats
path: root/tools/qml/qmlruntime.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/qml/qmlruntime.cpp')
-rw-r--r--tools/qml/qmlruntime.cpp61
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