diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-06-16 16:21:24 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-06-16 16:21:24 (GMT) |
commit | 7b30a66b2f16a8bf8828d26b7d0b193b5dffe713 (patch) | |
tree | 3ed1219e02bab53df871e7bf87bcf191c1a7534b /tools | |
parent | 65b05e330640a5e1920c61a4735cbc27a5ca3fe2 (diff) | |
parent | 6d178306f71564471cc08eb7dc98743c3752cac4 (diff) | |
download | Qt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.zip Qt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.tar.gz Qt-7b30a66b2f16a8bf8828d26b7d0b193b5dffe713.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:
Fix the N900 device orientation backend
Micro cleanup
Write TextInput.positionToRectangle docs.
Minor demo fixes
Fix autoScroll implementation
Move knowledge of QGraphicsObject out of qml engine
Stopping a flick resulted in the next click being consumed.
Enhance docs
Slight addition to the docs.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qml/deviceorientation_maemo.cpp | 123 | ||||
-rw-r--r-- | tools/qml/main.cpp | 7 | ||||
-rw-r--r-- | tools/qml/qml.pri | 1 |
3 files changed, 59 insertions, 72 deletions
diff --git a/tools/qml/deviceorientation_maemo.cpp b/tools/qml/deviceorientation_maemo.cpp index 7948e2a..443edc8 100644 --- a/tools/qml/deviceorientation_maemo.cpp +++ b/tools/qml/deviceorientation_maemo.cpp @@ -40,100 +40,87 @@ ****************************************************************************/ #include "deviceorientation.h" -#include <stdio.h> -#include <stdlib.h> +#include <QtDBus> + +#include <mce/mode-names.h> +#include <mce/dbus-names.h> class MaemoOrientation : public DeviceOrientation { Q_OBJECT public: MaemoOrientation() - : DeviceOrientation(),m_current(Portrait), m_lastSeen(Portrait), m_lastSeenCount(0) + : o(UnknownOrientation) { - m_current = get(); - if (m_current == UnknownOrientation) - m_current = Portrait; + // enable the orientation sensor + QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_ACCELEROMETER_ENABLE_REQ)); + + // query the initial orientation + QDBusMessage reply = QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_DEVICE_ORIENTATION_GET)); + if (reply.type() == QDBusMessage::ErrorMessage) { + qWarning("Unable to retrieve device orientation: %s", qPrintable(reply.errorMessage())); + } else { + o = toOrientation(reply.arguments().value(0).toString()); + } - startTimer(100); + // connect to the orientation change signal + QDBusConnection::systemBus().connect(QString(), MCE_SIGNAL_PATH, MCE_SIGNAL_IF, + MCE_DEVICE_ORIENTATION_SIG, + this, + SLOT(deviceOrientationChanged(QString))); } - Orientation orientation() const { - return m_current; + ~MaemoOrientation() + { + // disable the orientation sensor + QDBusConnection::systemBus().call( + QDBusMessage::createMethodCall(MCE_SERVICE, MCE_REQUEST_PATH, + MCE_REQUEST_IF, MCE_ACCELEROMETER_DISABLE_REQ)); } - void setOrientation(Orientation) { } - -protected: - virtual void timerEvent(QTimerEvent *) + inline Orientation orientation() const { - 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); - } + return o; } -signals: - void changed(); - -private: - Orientation m_current; - Orientation m_lastSeen; - int m_lastSeenCount; - - Orientation get() + void setOrientation(Orientation o) { - 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 (ax > 750) { - o = PortraitInverted; - } else if (ay < -750) { - o = Landscape; - } else if (ay > 750) { - o = LandscapeInverted; - } +private Q_SLOTS: + void deviceOrientationChanged(const QString &newOrientation) + { + o = toOrientation(newOrientation); - return o; + emit orientationChanged(); +// printf("%d\n", o); } - int read(int *ax,int *ay,int *az) +private: + static Orientation toOrientation(const QString &nativeOrientation) { - 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; + if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE) + return Landscape; + else if (nativeOrientation == MCE_ORIENTATION_LANDSCAPE_INVERTED) + return LandscapeInverted; + else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT) + return Portrait; + else if (nativeOrientation == MCE_ORIENTATION_PORTRAIT_INVERTED) + return PortraitInverted; + return UnknownOrientation; } -}; +private: + Orientation o; +}; DeviceOrientation* DeviceOrientation::instance() { - static MaemoOrientation *o = 0; - if (!o) - o = new MaemoOrientation; + static MaemoOrientation *o = new MaemoOrientation; return o; } diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 0cce1cc..a75023b 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -347,8 +347,9 @@ int main(int argc, char ** argv) wflags |= Qt::WindowStaysOnTopHint; QDeclarativeViewer *viewer = new QDeclarativeViewer(0, wflags); + viewer->setAttribute(Qt::WA_DeleteOnClose, true); if (!scriptopts.isEmpty()) { - QStringList options = + QStringList options = scriptopts.split(QLatin1Char(','), QString::SkipEmptyParts); QDeclarativeViewer::ScriptOptions scriptOptions = 0; @@ -451,7 +452,5 @@ int main(int argc, char ** argv) viewer->setUseGL(useGL); viewer->raise(); - int rv = app.exec(); - delete viewer; - exit(rv); + return app.exec(); } diff --git a/tools/qml/qml.pri b/tools/qml/qml.pri index cff65be..58d8cc1 100644 --- a/tools/qml/qml.pri +++ b/tools/qml/qml.pri @@ -18,6 +18,7 @@ SOURCES += $$PWD/qmlruntime.cpp \ RESOURCES = $$PWD/qmlruntime.qrc maemo5 { + QT += dbus SOURCES += $$PWD/deviceorientation_maemo.cpp } else { SOURCES += $$PWD/deviceorientation.cpp |