Added altitude display to detail screen. Added option to disable auto rotation.
authoreshe <jessehakanen@gmail.com>
Fri, 15 Oct 2010 19:25:34 +0000 (20:25 +0100)
committereshe <jessehakanen@gmail.com>
Fri, 15 Oct 2010 19:25:34 +0000 (20:25 +0100)
debian/changelog
src/detailscreen.cpp
src/detailscreen.h
src/mainmenu.cpp
src/mainmenu.h
src/mainwindow.cpp
src/mainwindow.h
src/orientation.cpp
src/orientation.h
src/unitselector.cpp
src/unitselector.h

index 0c06d13..37b57c2 100644 (file)
@@ -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 <jessehakanen@gmail.com>  Fri, 15 Oct 2010 20:30:24 +0100
+
 jspeed (0.1-6) unstable; urgency=low
 
   * Added speed camera warning images to default themes.
index 4599e4c..ee2da40 100644 (file)
@@ -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);
index 494599a..f0bfea1 100644 (file)
@@ -54,6 +54,9 @@ private:
     QGraphicsTextItem* totalLabel_;
     QGraphicsTextItem* total_;
     QGraphicsTextItem* totalUnit_;
+    QGraphicsTextItem* altitudeLabel_;
+    QGraphicsTextItem* altitude_;
+    QGraphicsTextItem* altitudeUnit_;
     QGraphicsTextItem* speedLabel_;
     QGraphicsTextItem* speed_;
     QGraphicsTextItem* speedUnit_;
index da6af01..e9a8670 100644 (file)
@@ -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();
index 39dbb5d..733cd55 100644 (file)
@@ -42,6 +42,7 @@ signals:
     void flip();
     void themeChanged();
     void unitChanged();
+    void orientationChanged();
 
 private slots:
     void selectTheme();
index f67121d..f8e9185 100644 (file)
@@ -33,6 +33,7 @@
 #include "speedalarm.h"
 #include "mediaplayer.h"
 #include "orientation.h"
+#include "settings.h"
 #include <QOrientationSensor>
 #include <QSensor>
 
@@ -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);
+    }
+}
index b7fd823..e22d091 100644 (file)
@@ -44,6 +44,7 @@ private slots:
     void openMenu();
     void keepBacklightOn();
     bool loadTheme();
+    void onOrientationChanged();
 
 private:
     void addScreens();
index 0452cf1..fccb24a 100644 (file)
@@ -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;
+    }
+}
index 193f687..5848f22 100644 (file)
@@ -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
index e4b0e16..9bd3824 100644 (file)
 
 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();
 }
index b5baad6..5dfa8ac 100644 (file)
@@ -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