2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include "orientation.h"
21 Orientation::Orientation(QMainWindow* window): QtMobility::QOrientationSensor(window),
22 current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window)
24 connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
27 void Orientation::setSupportedOrientations(int orientations)
29 orientations_ = orientations;
32 void Orientation::update()
34 using QtMobility::QOrientationReading;
36 OrientationName orientation = LANDSCAPE;
38 QOrientationReading::Orientation current = reading()->orientation();
42 case QOrientationReading::LeftUp:
43 orientation = PORTRAIT;
45 case QOrientationReading::FaceUp:
46 if(current_ == QOrientationReading::LeftUp)
48 orientation = PORTRAIT;
52 orientation = LANDSCAPE;
56 orientation = LANDSCAPE;
62 if(orientations_ & orientation)
67 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
70 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
76 if(orientations_ & LANDSCAPE)
78 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
80 else if(orientations_ & PORTRAIT)
82 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
87 void Orientation::onReadingChanged()
89 if(reading()->orientation() != current_)