From: eshe Date: Sun, 1 Aug 2010 12:20:11 +0000 (+0100) Subject: Changed app to use Qt Mobility in screen rotation instead of default Qt screen rotation. X-Git-Url: http://git.maemo.org/git/?p=jspeed;a=commitdiff_plain;h=e3f2858377ed1ecb7e35dd9af82597ab55ae935a Changed app to use Qt Mobility in screen rotation instead of default Qt screen rotation. --- diff --git a/debian/changelog b/debian/changelog index 2ba370e..9dfc77d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +jspeed (0.1-5) unstable; urgency=low + + * Faster and better screen rotation using Qt Mobility. + + -- Jesse Hakanen Sun, 1 Aug 2010 13:00:29 +0100 + jspeed (0.1-4) unstable; urgency=low * Fixed a bug in theme scheduler settings saving. diff --git a/debian/control b/debian/control index bf064a6..9111c09 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: jspeed Section: user/navigation Priority: optional Maintainer: Jesse Hakanen -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 diff --git a/jspeed.pro b/jspeed.pro index ac26de9..e0cc83d 100644 --- a/jspeed.pro +++ b/jspeed.pro @@ -2,7 +2,7 @@ QT += maemo5 xml TARGET = jspeed TEMPLATE = app CONFIG += mobility -MOBILITY += multimedia +MOBILITY += multimedia sensors 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/buttonbox.cpp + src/buttonbox.cpp \ + src/orientation.cpp 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/buttonbox.h + src/buttonbox.h \ + src/orientation.h RESOURCES = src/resources.qrc CONFIG += link_pkgconfig PKGCONFIG += liblocation libzip diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e08ab2c..f67121d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -32,11 +32,18 @@ #include "poialerts.h" #include "speedalarm.h" #include "mediaplayer.h" +#include "orientation.h" +#include +#include -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(); + orientation_ = new Orientation(this); + orientation_->start(); addScreens(); QTimer::singleShot(500, this, SLOT(loadServices())); } @@ -94,20 +101,20 @@ bool MainWindow::loadTheme() 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; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 45db816..b7fd823 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -25,6 +25,7 @@ class MainWindowStack; class MainMenu; class ThemeLoader; class WidgetScreen; +class Orientation; class MainWindow : public QMainWindow { @@ -52,6 +53,7 @@ private: MainMenu* menu_; ThemeLoader* themeLoader_; WidgetScreen* mainScreen_; + Orientation* orientation_; }; diff --git a/src/orientation.cpp b/src/orientation.cpp new file mode 100644 index 0000000..0452cf1 --- /dev/null +++ b/src/orientation.cpp @@ -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 . + * + */ + +#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 index 0000000..193f687 --- /dev/null +++ b/src/orientation.h @@ -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 . + * + */ + +#ifndef ORIENTATION_H +#define ORIENTATION_H + +#include +#include +#include + +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 diff --git a/src/widgetscreen.cpp b/src/widgetscreen.cpp index 0532807..120de24 100644 --- a/src/widgetscreen.cpp +++ b/src/widgetscreen.cpp @@ -120,8 +120,8 @@ void WidgetScreen::reArrange() if(screens_.find(o) != screens_.end()) { currentOrientation_ = o; - setCurrentWidget(screens_[o]); screens_[o]->reArrange(); + setCurrentWidget(screens_[o]); screens_[o]->forceRepaint(); } }