Changed app to use Qt Mobility in screen rotation instead of default Qt screen rotation.
authoreshe <jessehakanen@gmail.com>
Sun, 1 Aug 2010 12:20:11 +0000 (13:20 +0100)
committereshe <jessehakanen@gmail.com>
Sun, 1 Aug 2010 12:20:11 +0000 (13:20 +0100)
debian/changelog
debian/control
jspeed.pro
src/mainwindow.cpp
src/mainwindow.h
src/orientation.cpp [new file with mode: 0644]
src/orientation.h [new file with mode: 0644]
src/widgetscreen.cpp

index 2ba370e..9dfc77d 100644 (file)
@@ -1,3 +1,9 @@
+jspeed (0.1-5) unstable; urgency=low
+
+  * Faster and better screen rotation using Qt Mobility.
+
+ -- Jesse Hakanen <jessehakanen@gmail.com>  Sun,  1 Aug 2010 13:00:29 +0100
+
 jspeed (0.1-4) unstable; urgency=low
 
   * Fixed a bug in theme scheduler settings saving.
 jspeed (0.1-4) unstable; urgency=low
 
   * Fixed a bug in theme scheduler settings saving.
index bf064a6..9111c09 100644 (file)
@@ -2,7 +2,7 @@ Source: jspeed
 Section: user/navigation
 Priority: optional
 Maintainer: Jesse Hakanen <jessehakanen@gmail.com>
 Section: user/navigation
 Priority: optional
 Maintainer: Jesse Hakanen <jessehakanen@gmail.com>
-Build-Depends: debhelper (>= 5), libqt4-dev, libzip-dev, liblocation-dev, libgconf2-dev, libqtm-dev
+Build-Depends: debhelper (>= 5), libqt4-dev, libzip-dev, liblocation-dev, libgconf2-dev, libqtm-dev, libqtm-sensors
 Standards-Version: 3.7.2
 Homepage: http://jspeed.garage.maemo.org
 
 Standards-Version: 3.7.2
 Homepage: http://jspeed.garage.maemo.org
 
index ac26de9..e0cc83d 100644 (file)
@@ -2,7 +2,7 @@ QT += maemo5 xml
 TARGET = jspeed
 TEMPLATE = app
 CONFIG += mobility
 TARGET = jspeed
 TEMPLATE = app
 CONFIG += mobility
-MOBILITY += multimedia
+MOBILITY += multimedia sensors
 SOURCES += src/main.cpp \ 
            src/mainwindow.cpp \
            src/mainwindowstack.cpp \
 SOURCES += src/main.cpp \ 
            src/mainwindow.cpp \
            src/mainwindowstack.cpp \
@@ -47,7 +47,8 @@ SOURCES += src/main.cpp \
            src/themepicker.cpp \
            src/mediaplayer.cpp \
            src/soundselector.cpp \
            src/themepicker.cpp \
            src/mediaplayer.cpp \
            src/soundselector.cpp \
-           src/buttonbox.cpp
+           src/buttonbox.cpp \
+           src/orientation.cpp
 HEADERS += src/mainwindow.h \
            src/mainwindowstack.h \
            src/location.h \
 HEADERS += src/mainwindow.h \
            src/mainwindowstack.h \
            src/location.h \
@@ -91,7 +92,8 @@ HEADERS += src/mainwindow.h \
            src/themepicker.h \
            src/mediaplayer.h \
            src/soundselector.h \
            src/themepicker.h \
            src/mediaplayer.h \
            src/soundselector.h \
-           src/buttonbox.h
+           src/buttonbox.h \
+           src/orientation.h
 RESOURCES = src/resources.qrc
 CONFIG += link_pkgconfig
 PKGCONFIG += liblocation libzip
 RESOURCES = src/resources.qrc
 CONFIG += link_pkgconfig
 PKGCONFIG += liblocation libzip
index e08ab2c..f67121d 100644 (file)
 #include "poialerts.h"
 #include "speedalarm.h"
 #include "mediaplayer.h"
 #include "poialerts.h"
 #include "speedalarm.h"
 #include "mediaplayer.h"
+#include "orientation.h"
+#include <QOrientationSensor>
+#include <QSensor>
 
 
-MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0), mainScreen_(0)
+
+MainWindow::MainWindow(): QMainWindow(0), menu_(0), themeLoader_(0),
+mainScreen_(0), orientation_(0)
 {
     setWindowTitle(tr("jSpeed"));
     showFullScreen();
 {
     setWindowTitle(tr("jSpeed"));
     showFullScreen();
+    orientation_ = new Orientation(this);
+    orientation_->start();
     addScreens();
     QTimer::singleShot(500, this, SLOT(loadServices()));
 }
     addScreens();
     QTimer::singleShot(500, this, SLOT(loadServices()));
 }
@@ -94,20 +101,20 @@ bool MainWindow::loadTheme()
         return false;
     }
 
         return false;
     }
 
-    if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE) &&
-       mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
-    {
-        setAttribute(Qt::WA_Maemo5AutoOrientation, true);
-    }
-    else if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
+    int orientations = 0;
+
+    if(mainScreen_->orientationEnabled(WidgetScreen::LANDSCAPE))
     {
     {
-        setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+        orientations |= Orientation::LANDSCAPE;
     }
     }
-    else
+    if(mainScreen_->orientationEnabled(WidgetScreen::PORTRAIT))
     {
     {
-        setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+        orientations |= Orientation::PORTRAIT;
     }
 
     }
 
+    orientation_->setSupportedOrientations(orientations);
+    orientation_->update();
+
     return true;
 }
 
     return true;
 }
 
index 45db816..b7fd823 100644 (file)
@@ -25,6 +25,7 @@ class MainWindowStack;
 class MainMenu;
 class ThemeLoader;
 class WidgetScreen;
 class MainMenu;
 class ThemeLoader;
 class WidgetScreen;
+class Orientation;
 
 class MainWindow : public QMainWindow
 {
 
 class MainWindow : public QMainWindow
 {
@@ -52,6 +53,7 @@ private:
     MainMenu* menu_;
     ThemeLoader* themeLoader_;
     WidgetScreen* mainScreen_;
     MainMenu* menu_;
     ThemeLoader* themeLoader_;
     WidgetScreen* mainScreen_;
+    Orientation* orientation_;
 
 };
 
 
 };
 
diff --git a/src/orientation.cpp b/src/orientation.cpp
new file mode 100644 (file)
index 0000000..0452cf1
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "orientation.h"
+
+Orientation::Orientation(QMainWindow* window): QtMobility::QOrientationSensor(window),
+current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window)
+{
+    connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
+}
+
+void Orientation::setSupportedOrientations(int orientations)
+{
+    orientations_ = orientations;
+}
+
+void Orientation::update()
+{
+    using QtMobility::QOrientationReading;
+
+    OrientationName orientation = LANDSCAPE;
+
+    QOrientationReading::Orientation current = reading()->orientation();
+
+    switch(current)
+    {
+    case QOrientationReading::LeftUp:
+        orientation = PORTRAIT;
+        break;
+    case QOrientationReading::FaceUp:
+        if(current_ == QOrientationReading::LeftUp)
+        {
+            orientation = PORTRAIT;
+        }
+        else
+        {
+            orientation = LANDSCAPE;
+        }
+        break;
+    default:
+        orientation = LANDSCAPE;
+        break;
+    }
+
+    current_ = current;
+
+    if(orientations_ & orientation)
+    {
+        switch(orientation)
+        {
+        case LANDSCAPE:
+            window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+            break;
+        case PORTRAIT:
+            window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+            break;
+        }
+    }
+    else
+    {
+        if(orientations_ & LANDSCAPE)
+        {
+            window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
+        }
+        else if(orientations_ & PORTRAIT)
+        {
+            window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
+        }
+    }
+}
+
+void Orientation::onReadingChanged()
+{
+    if(reading()->orientation() != current_)
+    {
+        update();
+        emit changed();
+    }
+}
diff --git a/src/orientation.h b/src/orientation.h
new file mode 100644 (file)
index 0000000..193f687
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef ORIENTATION_H
+#define ORIENTATION_H
+
+#include <QtGui/QMainWindow>
+#include <QOrientationReading>
+#include <QOrientationSensor>
+
+class Orientation : public QtMobility::QOrientationSensor
+{
+    Q_OBJECT
+
+public:
+    enum OrientationName {LANDSCAPE = 0x01, PORTRAIT = 0x02};
+    Orientation(QMainWindow* window);
+    void setSupportedOrientations(int orientations);
+
+public slots:
+    void update();
+
+signals:
+    void changed();
+
+private slots:
+    void onReadingChanged();
+
+private:
+    QtMobility::QOrientationReading::Orientation current_;
+    int orientations_;
+    QMainWindow* window_;
+};
+
+#endif
index 0532807..120de24 100644 (file)
@@ -120,8 +120,8 @@ void WidgetScreen::reArrange()
         if(screens_.find(o) != screens_.end())
         {
             currentOrientation_ = o;
         if(screens_.find(o) != screens_.end())
         {
             currentOrientation_ = o;
-            setCurrentWidget(screens_[o]);
             screens_[o]->reArrange();
             screens_[o]->reArrange();
+            setCurrentWidget(screens_[o]);
             screens_[o]->forceRepaint();
         }
     }
             screens_[o]->forceRepaint();
         }
     }