Added altitude display to detail screen. Added option to disable auto rotation.
[jspeed] / src / detailscreen.cpp
index ba54052..ee2da40 100644 (file)
 
 #include <QtGui/QGraphicsTextItem>
 #include <QtGui/QGraphicsLineItem>
+#include <QtGui/QGraphicsPixmapItem>
+#include <QtGui/QPixmap>
 #include <QtCore/QString>
 #include <QtCore/QDebug>
+#include <math.h>
 #include "detailscreen.h"
 #include "odometer.h"
 #include "graphicsscene.h"
 namespace
 {
     QString const FONT = "Tahoma";
-    QString const BACKGROUND = ":/resources/themes/default/background.png";
+    QString const DEFAULT_BACKGROUND_COLOR = "#000";
+    QString const DEFAULT_COLOR = "#fff";
     int const FONT_SIZE = 20;
-    int const PADDING_LEFT = 40;
-    int const START_HEIGHT = 80;
+    int const START_HEIGHT = 61;
     int const ITEM_WIDTH = 130;
+
 }
 
-DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent)
+DetailScreen::DetailScreen(QWidget* parent): ThemeScreen(parent)
 {
     QString unit = Odometer::getUnit();
     QString speedUnit = Odometer::getSpeedUnit();
+    QString meterUnit = Odometer::getMeterUnit();
 
-    QGraphicsPixmapItem* background = new QGraphicsPixmapItem(QPixmap(BACKGROUND));
-    getScene()->addItem(background);
+    getScene()->setBackgroundBrush(QBrush(QColor(DEFAULT_BACKGROUND_COLOR)));
 
     tripLabel_ = createItem(tr("Trip"));
     trip_ = createItem(roundDouble(Odometer::instance().getTrip()));
@@ -50,6 +54,10 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(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);
@@ -71,6 +79,12 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent)
     line1_ = createLine();
     line2_ = createLine();
 
+    strength_ = new QGraphicsPixmapItem;
+    currentStrength_ = getStrength();
+    strength_->setPixmap(QPixmap(":/resources/signal_" + QString::number(currentStrength_) + ".png"));
+    strength_->setZValue(999);
+    getScene()->addItem(strength_);
+
     connect(&(Odometer::instance()), SIGNAL(timeUpdated()), this, SLOT(updateTime()));
     connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(updateUnits()));
 
@@ -79,11 +93,22 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent)
 
 void DetailScreen::update()
 {
+    ThemeScreen::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()));
+
+    int strength = getStrength();
+
+    if(strength != currentStrength_)
+    {
+        currentStrength_ = strength;
+        strength_->setPixmap(QPixmap(":/resources/signal_" + QString::number(strength) + ".png"));
+    }
 }
 
 void DetailScreen::updateTime()
@@ -96,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);
@@ -108,44 +135,54 @@ void DetailScreen::updateUnits()
 
 void DetailScreen::reArrange()
 {
-    GraphicsScreen::reArrange();
+    ThemeScreen::reArrange();
 
-    int lineHeight = getScene()->height() / 9;
+    int width = getScene()->width();
+    int height = getScene()->height();
 
-    int area1 = (getScene()->width() / 3) + ITEM_WIDTH / 2 + 20;
+    int lineHeight = (height - START_HEIGHT) / 8;
+
+    int padding = width / 22;
+    int area1 = (width / 3) + ITEM_WIDTH / 2 + 20;
     int area2 = area1 + ITEM_WIDTH;
 
-    tripLabel_->setPos(PADDING_LEFT, START_HEIGHT);
+    tripLabel_->setPos(padding, START_HEIGHT);
     trip_->setPos(area1, START_HEIGHT);
     tripUnit_->setPos(area2, START_HEIGHT);
 
-    totalLabel_->setPos(PADDING_LEFT, START_HEIGHT + lineHeight);
+    totalLabel_->setPos(padding, START_HEIGHT + lineHeight);
     total_->setPos(area1, START_HEIGHT + lineHeight);
     totalUnit_->setPos(area2, START_HEIGHT + lineHeight);
 
-    speedLabel_->setPos(PADDING_LEFT, 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_LEFT, 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_LEFT, 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_LEFT, 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_LEFT, 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 x = getScene()->width() - PADDING_LEFT;
-    line1_->setLine(PADDING_LEFT + 2, y1, x, y1);
-    line2_->setLine(PADDING_LEFT + 2, y2, x, y2);
+    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);
+
+    strength_->setPos(width - padding - 64, height - padding - 41);
 }
 
 QGraphicsTextItem* DetailScreen::createItem(QString const& text)
@@ -154,7 +191,8 @@ QGraphicsTextItem* DetailScreen::createItem(QString const& text)
     QFont font(FONT, FONT_SIZE);
     font.setBold(true);
     item->setFont(font);
-    item->setDefaultTextColor(QColor("#fff"));
+    item->setDefaultTextColor(QColor(DEFAULT_COLOR));
+    item->setZValue(999);
     getScene()->addItem(item);
     return item;
 }
@@ -162,9 +200,11 @@ QGraphicsTextItem* DetailScreen::createItem(QString const& text)
 QGraphicsLineItem* DetailScreen::createLine()
 {
     QGraphicsLineItem* item = new QGraphicsLineItem;
-    QPen pen(QColor("#ddd"));
-    pen.setWidth(1);
-    item->setPen(pen);
+    QColor pColor(DEFAULT_COLOR);
+    QPen p(pColor);
+    p.setWidth(1);
+    item->setPen(p);
+    item->setZValue(999);
     getScene()->addItem(item);
     return item;
 }
@@ -189,3 +229,40 @@ QString DetailScreen::formatTime(qulonglong time)
            QString().sprintf(format, mins) + ":" +
            QString().sprintf(format, secs);
 }
+
+int DetailScreen::getStrength()
+{
+    double strength = round(Odometer::instance().getSignalStrength() / 25.0);
+    return static_cast<int>(strength);
+}
+
+void DetailScreen::setColor(QString const& color)
+{
+    QColor c(color);
+
+    tripLabel_->setDefaultTextColor(c);
+    trip_->setDefaultTextColor(c);
+    tripUnit_->setDefaultTextColor(c);
+    totalLabel_->setDefaultTextColor(c);
+    total_->setDefaultTextColor(c);
+    totalUnit_->setDefaultTextColor(c);
+    speedLabel_->setDefaultTextColor(c);
+    speed_->setDefaultTextColor(c);
+    speedUnit_->setDefaultTextColor(c);
+    avgSpeedLabel_->setDefaultTextColor(c);
+    avgSpeed_->setDefaultTextColor(c);
+    avgSpeedUnit_->setDefaultTextColor(c);
+    maxSpeedLabel_->setDefaultTextColor(c);
+    maxSpeed_->setDefaultTextColor(c);
+    maxSpeedUnit_->setDefaultTextColor(c);
+    tripTimeLabel_->setDefaultTextColor(c);
+    tripTime_->setDefaultTextColor(c);
+    totalTimeLabel_->setDefaultTextColor(c);
+    totalTime_->setDefaultTextColor(c);
+
+    QPen p(c);
+    p.setWidth(1);
+
+    line1_->setPen(p);
+    line2_->setPen(p);
+}