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),
25 connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged()));
28 void Orientation::setSupportedOrientations(int orientations)
30 orientations_ = orientations;
33 void Orientation::setOrientationType(OrientationType type)
37 handleManualOrientation();
40 void Orientation::update()
42 if(type_ != TYPE_AUTO)
44 handleManualOrientation();
48 using QtMobility::QOrientationReading;
50 OrientationName orientation = LANDSCAPE;
52 QOrientationReading::Orientation current = reading()->orientation();
56 case QOrientationReading::LeftUp:
57 orientation = PORTRAIT;
59 case QOrientationReading::FaceUp:
60 if(current_ == QOrientationReading::LeftUp)
62 orientation = PORTRAIT;
66 orientation = LANDSCAPE;
70 orientation = LANDSCAPE;
76 if(orientations_ & orientation)
81 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
84 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
90 if(orientations_ & LANDSCAPE)
92 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
94 else if(orientations_ & PORTRAIT)
96 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
101 void Orientation::onReadingChanged()
103 if(type_ != TYPE_AUTO)
108 if(reading()->orientation() != current_)
115 void Orientation::handleManualOrientation()
120 if(orientations_ & LANDSCAPE)
122 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
124 else if(orientations_ & PORTRAIT)
126 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
130 if(orientations_ & PORTRAIT)
132 window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
134 else if(orientations_ & LANDSCAPE)
136 window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);