From 36d7905fbbcc49571fef5b7769707441f344d179 Mon Sep 17 00:00:00 2001 From: eshe Date: Fri, 15 Oct 2010 20:25:34 +0100 Subject: [PATCH 1/1] Added altitude display to detail screen. Added option to disable auto rotation. --- debian/changelog | 7 +++++++ src/detailscreen.cpp | 46 +++++++++++++++++++++++++++----------------- src/detailscreen.h | 3 +++ src/mainmenu.cpp | 3 ++- src/mainmenu.h | 1 + src/mainwindow.cpp | 21 ++++++++++++++++++++ src/mainwindow.h | 1 + src/orientation.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++- src/orientation.h | 4 ++++ src/unitselector.cpp | 52 ++++++++++++++++++++++++++++++++++++++------------ src/unitselector.h | 3 +++ 11 files changed, 160 insertions(+), 31 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0c06d13..37b57c2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +jspeed (0.1-7) unstable; urgency=low + + * Added altitude display to detail screen. + * Added option to disable automatic screen rotation. + + -- Jesse Hakanen Fri, 15 Oct 2010 20:30:24 +0100 + jspeed (0.1-6) unstable; urgency=low * Added speed camera warning images to default themes. diff --git a/src/detailscreen.cpp b/src/detailscreen.cpp index 4599e4c..ee2da40 100644 --- a/src/detailscreen.cpp +++ b/src/detailscreen.cpp @@ -33,7 +33,7 @@ namespace QString const DEFAULT_BACKGROUND_COLOR = "#000"; QString const DEFAULT_COLOR = "#fff"; int const FONT_SIZE = 20; - int const START_HEIGHT = 80; + int const START_HEIGHT = 61; int const ITEM_WIDTH = 130; } @@ -42,6 +42,7 @@ DetailScreen::DetailScreen(QWidget* parent): ThemeScreen(parent) { QString unit = Odometer::getUnit(); QString speedUnit = Odometer::getSpeedUnit(); + QString meterUnit = Odometer::getMeterUnit(); getScene()->setBackgroundBrush(QBrush(QColor(DEFAULT_BACKGROUND_COLOR))); @@ -53,6 +54,10 @@ DetailScreen::DetailScreen(QWidget* parent): ThemeScreen(parent) total_ = createItem(roundDouble(Odometer::instance().getTotal())); totalUnit_ = createItem(unit); + altitudeLabel_ = createItem(tr("Altitude")); + altitude_ = createItem(roundDouble(Odometer::instance().getLatestFix().altitude)); + altitudeUnit_ = createItem(meterUnit); + speedLabel_ = createItem(tr("Speed")); speed_ = createItem(roundDouble(0.0)); speedUnit_ = createItem(speedUnit); @@ -92,6 +97,7 @@ void DetailScreen::update() speed_->setPlainText(roundDouble(Odometer::instance().getLatestFix().speed)); trip_->setPlainText(roundDouble(Odometer::instance().getTrip())); + altitude_->setPlainText(roundDouble(Odometer::instance().getLatestFix().altitude)); total_->setPlainText(roundDouble(Odometer::instance().getTotal())); avgSpeed_->setPlainText(roundDouble(Odometer::instance().getAverageSpeed())); maxSpeed_->setPlainText(roundDouble(Odometer::instance().getMaxSpeed())); @@ -115,9 +121,11 @@ void DetailScreen::updateUnits() { QString unit = Odometer::getUnit(); QString speedUnit = Odometer::getSpeedUnit(); + QString meterUnit = Odometer::getMeterUnit(); tripUnit_->setPlainText(unit); totalUnit_->setPlainText(unit); + altitudeUnit_->setPlainText(meterUnit); speedUnit_->setPlainText(speedUnit); avgSpeedUnit_->setPlainText(speedUnit); maxSpeedUnit_->setPlainText(speedUnit); @@ -132,7 +140,7 @@ void DetailScreen::reArrange() int width = getScene()->width(); int height = getScene()->height(); - int lineHeight = height / 9; + int lineHeight = (height - START_HEIGHT) / 8; int padding = width / 22; int area1 = (width / 3) + ITEM_WIDTH / 2 + 20; @@ -146,26 +154,30 @@ void DetailScreen::reArrange() total_->setPos(area1, START_HEIGHT + lineHeight); totalUnit_->setPos(area2, START_HEIGHT + lineHeight); - speedLabel_->setPos(padding, START_HEIGHT + 2 * lineHeight); - speed_->setPos(area1, START_HEIGHT + 2 * lineHeight); - speedUnit_->setPos(area2, START_HEIGHT + 2 * lineHeight); + altitudeLabel_->setPos(padding, START_HEIGHT + 2 * lineHeight); + altitude_->setPos(area1, START_HEIGHT + 2 * lineHeight); + altitudeUnit_->setPos(area2, START_HEIGHT + 2 * lineHeight); + + speedLabel_->setPos(padding, START_HEIGHT + 3 * lineHeight); + speed_->setPos(area1, START_HEIGHT + 3 * lineHeight); + speedUnit_->setPos(area2, START_HEIGHT + 3 * lineHeight); - avgSpeedLabel_->setPos(padding, START_HEIGHT + 3 * lineHeight); - avgSpeed_->setPos(area1, START_HEIGHT + 3 * lineHeight); - avgSpeedUnit_->setPos(area2, START_HEIGHT + 3 * lineHeight); + avgSpeedLabel_->setPos(padding, START_HEIGHT + 4 * lineHeight); + avgSpeed_->setPos(area1, START_HEIGHT + 4 * lineHeight); + avgSpeedUnit_->setPos(area2, START_HEIGHT + 4 * lineHeight); - maxSpeedLabel_->setPos(padding, START_HEIGHT + 4 * lineHeight); - maxSpeed_->setPos(area1, START_HEIGHT + 4 * lineHeight); - maxSpeedUnit_->setPos(area2, START_HEIGHT + 4 * lineHeight); + maxSpeedLabel_->setPos(padding, START_HEIGHT + 5 * lineHeight); + maxSpeed_->setPos(area1, START_HEIGHT + 5 * lineHeight); + maxSpeedUnit_->setPos(area2, START_HEIGHT + 5 * lineHeight); - tripTimeLabel_->setPos(padding, START_HEIGHT + 5 * lineHeight); - tripTime_->setPos(area1, START_HEIGHT + 5 * lineHeight); + tripTimeLabel_->setPos(padding, START_HEIGHT + 6 * lineHeight); + tripTime_->setPos(area1, START_HEIGHT + 6 * lineHeight); - totalTimeLabel_->setPos(padding, START_HEIGHT + 6 * lineHeight); - totalTime_->setPos(area1, START_HEIGHT + 6 * lineHeight); + totalTimeLabel_->setPos(padding, START_HEIGHT + 7 * lineHeight); + totalTime_->setPos(area1, START_HEIGHT + 7 * lineHeight); - int y1 = START_HEIGHT + 2 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; - int y2 = START_HEIGHT + 5 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; + int y1 = START_HEIGHT + 3 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; + int y2 = START_HEIGHT + 6 * lineHeight - lineHeight / 2 + FONT_SIZE + 2; int x = width - padding; line1_->setLine(padding + 2, y1, x, y1); line2_->setLine(padding + 2, y2, x, y2); diff --git a/src/detailscreen.h b/src/detailscreen.h index 494599a..f0bfea1 100644 --- a/src/detailscreen.h +++ b/src/detailscreen.h @@ -54,6 +54,9 @@ private: QGraphicsTextItem* totalLabel_; QGraphicsTextItem* total_; QGraphicsTextItem* totalUnit_; + QGraphicsTextItem* altitudeLabel_; + QGraphicsTextItem* altitude_; + QGraphicsTextItem* altitudeUnit_; QGraphicsTextItem* speedLabel_; QGraphicsTextItem* speed_; QGraphicsTextItem* speedUnit_; diff --git a/src/mainmenu.cpp b/src/mainmenu.cpp index da6af01..e9a8670 100644 --- a/src/mainmenu.cpp +++ b/src/mainmenu.cpp @@ -39,7 +39,7 @@ speedAlarmSettings_(0), aboutDialog_(0) addAction(tr("Reset trip"), this, SIGNAL(resetTrip())); addAction(tr("Reset all"), this, SLOT(confirmReset())); addAction(tr("Theme"), this, SLOT(selectTheme())); - addAction(tr("Set unit"), this, SLOT(selectUnit())); + addAction(tr("Options"), this, SLOT(selectUnit())); addAction(tr("Speed camera alerts"), this, SLOT(openPoiAlerts())); addAction(tr("Speed alarm"), this, SLOT(openSpeedAlarm())); addAction(tr("Flip screen"), this, SIGNAL(flip())); @@ -83,6 +83,7 @@ void MainMenu::selectUnit() { unitSelector_ = new UnitSelector(this); connect(unitSelector_, SIGNAL(unitChanged()), this, SIGNAL(unitChanged())); + connect(unitSelector_, SIGNAL(orientationChanged()), this, SIGNAL(orientationChanged())); } unitSelector_->show(); diff --git a/src/mainmenu.h b/src/mainmenu.h index 39dbb5d..733cd55 100644 --- a/src/mainmenu.h +++ b/src/mainmenu.h @@ -42,6 +42,7 @@ signals: void flip(); void themeChanged(); void unitChanged(); + void orientationChanged(); private slots: void selectTheme(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f67121d..f8e9185 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -33,6 +33,7 @@ #include "speedalarm.h" #include "mediaplayer.h" #include "orientation.h" +#include "settings.h" #include #include @@ -113,6 +114,7 @@ bool MainWindow::loadTheme() } orientation_->setSupportedOrientations(orientations); + onOrientationChanged(); orientation_->update(); return true; @@ -137,6 +139,7 @@ void MainWindow::openMenu() connect(menu_, SIGNAL(flip()), stack_, SLOT(flip())); connect(menu_, SIGNAL(themeChanged()), this, SLOT(loadTheme())); connect(menu_, SIGNAL(unitChanged()), &(Odometer::instance()), SLOT(updateUnit())); + connect(menu_, SIGNAL(orientationChanged()), this, SLOT(onOrientationChanged())); } menu_->show(); @@ -160,3 +163,21 @@ void MainWindow::keepBacklightOn() connection.call(msg); } + +void MainWindow::onOrientationChanged() +{ + QString value = Settings::instance().value("orientation").toString(); + + if(value == "auto") + { + orientation_->setOrientationType(Orientation::TYPE_AUTO); + } + else if(value == "landscape") + { + orientation_->setOrientationType(Orientation::TYPE_LANDSCAPE); + } + else if(value == "portrait") + { + orientation_->setOrientationType(Orientation::TYPE_PORTRAIT); + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h index b7fd823..e22d091 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -44,6 +44,7 @@ private slots: void openMenu(); void keepBacklightOn(); bool loadTheme(); + void onOrientationChanged(); private: void addScreens(); diff --git a/src/orientation.cpp b/src/orientation.cpp index 0452cf1..fccb24a 100644 --- a/src/orientation.cpp +++ b/src/orientation.cpp @@ -19,7 +19,8 @@ #include "orientation.h" Orientation::Orientation(QMainWindow* window): QtMobility::QOrientationSensor(window), -current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window) +current_(QtMobility::QOrientationReading::TopUp), orientations_(0), window_(window), +type_(TYPE_AUTO) { connect(this, SIGNAL(readingChanged()), this, SLOT(onReadingChanged())); } @@ -29,8 +30,21 @@ void Orientation::setSupportedOrientations(int orientations) orientations_ = orientations; } +void Orientation::setOrientationType(OrientationType type) +{ + type_ = type; + + handleManualOrientation(); +} + void Orientation::update() { + if(type_ != TYPE_AUTO) + { + handleManualOrientation(); + return; + } + using QtMobility::QOrientationReading; OrientationName orientation = LANDSCAPE; @@ -86,9 +100,43 @@ void Orientation::update() void Orientation::onReadingChanged() { + if(type_ != TYPE_AUTO) + { + return; + } + if(reading()->orientation() != current_) { update(); emit changed(); } } + +void Orientation::handleManualOrientation() +{ + switch(type_) + { + case TYPE_LANDSCAPE: + if(orientations_ & LANDSCAPE) + { + window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); + } + else if(orientations_ & PORTRAIT) + { + window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); + } + break; + case TYPE_PORTRAIT: + if(orientations_ & PORTRAIT) + { + window_->setAttribute(Qt::WA_Maemo5PortraitOrientation, true); + } + else if(orientations_ & LANDSCAPE) + { + window_->setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); + } + break; + default: + break; + } +} diff --git a/src/orientation.h b/src/orientation.h index 193f687..5848f22 100644 --- a/src/orientation.h +++ b/src/orientation.h @@ -29,8 +29,10 @@ class Orientation : public QtMobility::QOrientationSensor public: enum OrientationName {LANDSCAPE = 0x01, PORTRAIT = 0x02}; + enum OrientationType {TYPE_AUTO, TYPE_LANDSCAPE, TYPE_PORTRAIT}; Orientation(QMainWindow* window); void setSupportedOrientations(int orientations); + void setOrientationType(OrientationType type); public slots: void update(); @@ -40,11 +42,13 @@ signals: private slots: void onReadingChanged(); + void handleManualOrientation(); private: QtMobility::QOrientationReading::Orientation current_; int orientations_; QMainWindow* window_; + OrientationType type_; }; #endif diff --git a/src/unitselector.cpp b/src/unitselector.cpp index e4b0e16..9bd3824 100644 --- a/src/unitselector.cpp +++ b/src/unitselector.cpp @@ -27,11 +27,13 @@ UnitSelector::UnitSelector(QWidget* parent): QDialog(parent) { - setWindowTitle(tr("Set unit")); + setWindowTitle(tr("Options")); unit_ = Settings::instance().value("unit", "km").toString(); - QHBoxLayout* layout = new QHBoxLayout; + QHBoxLayout* mainLayout = new QHBoxLayout; + + QVBoxLayout* layout = new QVBoxLayout; selector_ = new ButtonSelector(tr("Unit")); @@ -43,29 +45,55 @@ UnitSelector::UnitSelector(QWidget* parent): QDialog(parent) selector_->setCurrentIndex(1); } - layout->addWidget(selector_, Qt::AlignLeft); + layout->addWidget(selector_); + + orientation_ = Settings::instance().value("orientation", "auto").toString(); + + orientationSelector_ = new ButtonSelector(tr("Screen orientation")); + + orientationSelector_->addItem(tr("Automatic"), "auto"); + orientationSelector_->addItem(tr("Landscape"), "landscape"); + orientationSelector_->addItem(tr("Portrait"), "portrait"); + + if(orientation_ == "landscape") + { + orientationSelector_->setCurrentIndex(1); + } + else if(orientation_ == "portrait") + { + orientationSelector_->setCurrentIndex(2); + } + + layout->addWidget(orientationSelector_); ButtonBox* buttons = new ButtonBox; buttons->setOrientation(Qt::Horizontal); connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveUnit())); - layout->addWidget(buttons); + mainLayout->addLayout(layout, Qt::AlignLeft); + mainLayout->addWidget(buttons); - setLayout(layout); + setLayout(mainLayout); } void UnitSelector::saveUnit() { - QString value = selector_->value().toString(); + QString unitValue = selector_->value().toString(); + QString orientationValue = orientationSelector_->value().toString(); + + if(unitValue != unit_) + { + Settings::instance().setValue("unit", unitValue); + unit_ = unitValue; + emit unitChanged(); + } - if(value == unit_) + if(orientationValue != orientation_) { - hide(); - return; + Settings::instance().setValue("orientation", orientationValue); + orientation_ = orientationValue; + emit orientationChanged(); } - Settings::instance().setValue("unit", value); - unit_ = value; hide(); - emit unitChanged(); } diff --git a/src/unitselector.h b/src/unitselector.h index b5baad6..5dfa8ac 100644 --- a/src/unitselector.h +++ b/src/unitselector.h @@ -33,6 +33,7 @@ public: signals: void unitChanged(); + void orientationChanged(); private slots: void saveUnit(); @@ -40,6 +41,8 @@ private slots: private: ButtonSelector* selector_; QString unit_; + ButtonSelector* orientationSelector_; + QString orientation_; }; #endif -- 1.7.9.5