summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-12-01 03:30:13 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-12-01 03:30:13 (GMT)
commit5f9172a3db108a0cc4719fd75f7ffe3f256f1fcc (patch)
tree4ac8fecfc919d6d405d801a0a271aa0c54303531 /tools
parentc20ff1f36b8f5ba47e0358c4d63eed408c97b993 (diff)
downloadQt-5f9172a3db108a0cc4719fd75f7ffe3f256f1fcc.zip
Qt-5f9172a3db108a0cc4719fd75f7ffe3f256f1fcc.tar.gz
Qt-5f9172a3db108a0cc4719fd75f7ffe3f256f1fcc.tar.bz2
Add Screen element in QmlViewr Module including orientation property.
Add support for automatic Maemo rotation update.
Diffstat (limited to 'tools')
-rw-r--r--tools/qmlviewer/deviceorientation.cpp73
-rw-r--r--tools/qmlviewer/deviceorientation.h69
-rw-r--r--tools/qmlviewer/deviceorientation_maemo.cpp139
-rw-r--r--tools/qmlviewer/qmlviewer.cpp42
-rw-r--r--tools/qmlviewer/qmlviewer.pro8
5 files changed, 328 insertions, 3 deletions
diff --git a/tools/qmlviewer/deviceorientation.cpp b/tools/qmlviewer/deviceorientation.cpp
new file mode 100644
index 0000000..c507479
--- /dev/null
+++ b/tools/qmlviewer/deviceorientation.cpp
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "deviceorientation.h"
+
+class DefaultDeviceOrientation : public DeviceOrientation
+{
+ Q_OBJECT
+public:
+ DefaultDeviceOrientation() : DeviceOrientation(), m_orientation(DeviceOrientation::Portrait) {}
+
+ Orientation orientation() const {
+ return m_orientation;
+ }
+
+ void setOrientation(Orientation o) {
+ if (o != m_orientation) {
+ m_orientation = o;
+ emit orientationChanged();
+ }
+ }
+
+ Orientation m_orientation;
+};
+
+DeviceOrientation* DeviceOrientation::instance()
+{
+ static DefaultDeviceOrientation *o = 0;
+ if (!o)
+ o = new DefaultDeviceOrientation;
+ return o;
+}
+
+#include "deviceorientation.moc"
+
diff --git a/tools/qmlviewer/deviceorientation.h b/tools/qmlviewer/deviceorientation.h
new file mode 100644
index 0000000..fa7758f
--- /dev/null
+++ b/tools/qmlviewer/deviceorientation.h
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ORIENTATION_H
+#define ORIENTATION_H
+
+#include <QObject>
+
+class DeviceOrientationPrivate;
+class DeviceOrientation : public QObject
+{
+ Q_OBJECT
+public:
+ enum Orientation { UnknownOrientation, Portrait, Landscape };
+ virtual Orientation orientation() const = 0;
+ virtual void setOrientation(Orientation) = 0;
+
+ static DeviceOrientation *instance();
+
+signals:
+ void orientationChanged();
+
+protected:
+ DeviceOrientation() {}
+
+private:
+ DeviceOrientationPrivate *d_ptr;
+ friend class DeviceOrientationPrivate;
+};
+
+#endif
diff --git a/tools/qmlviewer/deviceorientation_maemo.cpp b/tools/qmlviewer/deviceorientation_maemo.cpp
new file mode 100644
index 0000000..9df9af4
--- /dev/null
+++ b/tools/qmlviewer/deviceorientation_maemo.cpp
@@ -0,0 +1,139 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "deviceorientation.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+class MaemoOrientation : public DeviceOrientation
+{
+ Q_OBJECT
+public:
+ MaemoOrientation()
+ : DeviceOrientation(),m_current(Portrait), m_lastSeen(Portrait), m_lastSeenCount(0)
+ {
+ startTimer(100);
+ }
+
+ Orientation orientation() const {
+ return m_current;
+ }
+
+ void setOrientation(Orientation orient) {
+ //XXX maybe better to just ignore
+ if (orient != m_current) {
+ m_current = orient;
+ emit orientationChanged();
+ }
+ }
+
+
+protected:
+ virtual void timerEvent(QTimerEvent *)
+ {
+ Orientation c = get();
+
+ if (c == m_lastSeen) {
+ m_lastSeenCount++;
+ } else {
+ m_lastSeenCount = 0;
+ m_lastSeen = c;
+ }
+
+ if (m_lastSeen != UnknownOrientation && m_lastSeen != m_current && m_lastSeenCount > 4) {
+ m_current = m_lastSeen;
+ emit orientationChanged();
+ printf("%d\n", m_current);
+ }
+ }
+
+signals:
+ void changed();
+
+private:
+ Orientation m_current;
+ Orientation m_lastSeen;
+ int m_lastSeenCount;
+
+ Orientation get()
+ {
+ Orientation o = UnknownOrientation;
+
+ int ax, ay, az;
+
+ read(&ax, &ay, &az);
+
+ if (abs(az) > 850) {
+ o = UnknownOrientation;
+ } else if (ax < -750) {
+ o = Portrait;
+ } else if (ay < -750) {
+ o = Landscape;
+ }
+
+ return o;
+ }
+
+ int read(int *ax,int *ay,int *az)
+ {
+ static const char *accel_filename = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";
+
+ FILE *fd;
+ int rs;
+ fd = fopen(accel_filename, "r");
+ if(fd==NULL){ printf("liqaccel, cannot open for reading\n"); return -1;}
+ rs=fscanf((FILE*) fd,"%i %i %i",ax,ay,az);
+ fclose(fd);
+ if(rs != 3){ printf("liqaccel, cannot read information\n"); return -2;}
+ return 0;
+ }
+};
+
+
+DeviceOrientation* DeviceOrientation::instance()
+{
+ static MaemoOrientation *o = 0;
+ if (!o)
+ o = new MaemoOrientation;
+ return o;
+}
+
+#include "deviceorientation_maemo.moc"
diff --git a/tools/qmlviewer/qmlviewer.cpp b/tools/qmlviewer/qmlviewer.cpp
index a354653..8c50b09 100644
--- a/tools/qmlviewer/qmlviewer.cpp
+++ b/tools/qmlviewer/qmlviewer.cpp
@@ -74,6 +74,7 @@
#include <QNetworkProxyFactory>
#include <QKeyEvent>
#include "proxysettings.h"
+#include "deviceorientation.h"
#ifdef GL_SUPPORTED
#include <QGLWidget>
@@ -84,6 +85,43 @@
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) {
+ m_screens.append(this);
+ connect(DeviceOrientation::instance(), SIGNAL(orientationChanged()),
+ this, SIGNAL(orientationChanged()));
+ }
+ ~Screen() { m_screens.removeAll(this); }
+
+ enum Orientation { UnknownOrientation = DeviceOrientation::UnknownOrientation,
+ Portrait = DeviceOrientation::Portrait,
+ Landscape = DeviceOrientation::Landscape };
+ Orientation orientation() const { return Orientation(DeviceOrientation::instance()->orientation()); }
+ static void setOrientation(Orientation orient) {
+ if (orient != Orientation(DeviceOrientation::instance()->orientation())) {
+ DeviceOrientation::instance()->setOrientation(DeviceOrientation::Orientation(orient));
+ }
+ }
+
+signals:
+ void orientationChanged();
+
+private:
+ static QList<Screen*> m_screens;
+};
+
+QList<Screen*> Screen::m_screens;
+
+QML_DECLARE_TYPE(Screen)
+QML_DEFINE_TYPE(QmlViewer, 1, 0, Screen, Screen)
+
class SizedMenuBar : public QMenuBar
{
Q_OBJECT
@@ -532,13 +570,13 @@ void QmlViewer::proxySettingsChanged()
void QmlViewer::setPortrait()
{
- canvas->rootContext()->setContextProperty("orientation", "Portrait");
+ Screen::setOrientation(Screen::Portrait);
portraitOrientation->setChecked(true);
}
void QmlViewer::setLandscape()
{
- canvas->rootContext()->setContextProperty("orientation", "Landscape");
+ Screen::setOrientation(Screen::Landscape);
landscapeOrientation->setChecked(true);
}
diff --git a/tools/qmlviewer/qmlviewer.pro b/tools/qmlviewer/qmlviewer.pro
index ed26d00..4d5effd 100644
--- a/tools/qmlviewer/qmlviewer.pro
+++ b/tools/qmlviewer/qmlviewer.pro
@@ -15,11 +15,17 @@ contains(QT_CONFIG, opengl) {
# Input
HEADERS += qmlviewer.h \
proxysettings.h \
- qfxtester.h
+ qfxtester.h \
+ deviceorientation.h
SOURCES += main.cpp \
qmlviewer.cpp \
proxysettings.cpp \
qfxtester.cpp
+maemo: {
+ SOURCES += deviceorientation_maemo.cpp
+} else {
+ SOURCES += deviceorientation.cpp
+}
FORMS = recopts.ui \
proxysettings.ui
INCLUDEPATH += ../../include/QtDeclarative