#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"
QString const FONT = "Tahoma";
QString const BACKGROUND = ":/resources/themes/default/background.png";
int const FONT_SIZE = 20;
- int const PADDING_LEFT = 40;
int const START_HEIGHT = 80;
int const ITEM_WIDTH = 130;
}
line1_ = createLine();
line2_ = createLine();
+ strength_ = new QGraphicsPixmapItem;
+ currentStrength_ = getStrength();
+ strength_->setPixmap(QPixmap(":/resources/signal_" + QString::number(currentStrength_) + ".png"));
+ getScene()->addItem(strength_);
+
connect(&(Odometer::instance()), SIGNAL(timeUpdated()), this, SLOT(updateTime()));
connect(&(Odometer::instance()), SIGNAL(unitChanged()), this, SLOT(updateUnits()));
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()
{
GraphicsScreen::reArrange();
- int lineHeight = getScene()->height() / 9;
+ int width = getScene()->width();
+ int height = getScene()->height();
+
+ int lineHeight = height / 9;
- int area1 = (getScene()->width() / 3) + ITEM_WIDTH / 2 + 20;
+ 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);
+ speedLabel_->setPos(padding, START_HEIGHT + 2 * lineHeight);
speed_->setPos(area1, START_HEIGHT + 2 * lineHeight);
speedUnit_->setPos(area2, START_HEIGHT + 2 * lineHeight);
- avgSpeedLabel_->setPos(PADDING_LEFT, 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);
- maxSpeedLabel_->setPos(PADDING_LEFT, 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);
- tripTimeLabel_->setPos(PADDING_LEFT, START_HEIGHT + 5 * lineHeight);
+ tripTimeLabel_->setPos(padding, START_HEIGHT + 5 * lineHeight);
tripTime_->setPos(area1, START_HEIGHT + 5 * lineHeight);
- totalTimeLabel_->setPos(PADDING_LEFT, START_HEIGHT + 6 * lineHeight);
+ totalTimeLabel_->setPos(padding, START_HEIGHT + 6 * lineHeight);
totalTime_->setPos(area1, START_HEIGHT + 6 * 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 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)
QString().sprintf(format, mins) + ":" +
QString().sprintf(format, secs);
}
+
+int DetailScreen::getStrength()
+{
+ double strength = round(Odometer::instance().getSignalStrength() / 25.0);
+ return static_cast<int>(strength);
+}
}
GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent),
-AbstractScreen(), scene_(0)
+AbstractScreen(), scene_(0), isFlipped_(false)
{
QRect rect = QApplication::desktop()->availableGeometry();
scene_->setSceneRect(rect);
minimizeButton_->setPos(PADDING, PADDING);
closeButton_->setPos(rect.width() - imageWidth_ - PADDING, PADDING);
- settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2) - (PADDING / 2), PADDING);
+ settingsButton_->setPos((rect.width() / 2) - (imageWidth_ / 2), PADDING);
}
void GraphicsScreen::flip()
{
- if(isTransformed())
+ if(isFlipped_)
{
resetMatrix();
- return;
+ isFlipped_ = false;
+ }
+ else
+ {
+ setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1));
+ isFlipped_ = true;
}
-
- setTransform(QTransform(1, 0, 0, 0, -1, 0, 0, 0, 1));
}
GraphicsScene* GraphicsScreen::getScene() const
QString const MILE_UNIT = "mi";
QString const KM_SPEEDUNIT = "km/h";
QString const MILE_SPEEDUNIT = "mph";
- double const SPEED_TRESHOLD = 0.9;
- double const SPEED_IGNORE_LEVEL = 0.2;
+ double const DEFAULT_SPEED_TRESHOLD = 8.0;
+ double const MIN_SPEED_TRESHOLD = 0.9;
+ double const SPEED_IGNORE_LEVEL = 0.01;
}
Odometer::Odometer(): QObject(0), trip_(0), total_(0),
fixTimer_->restart();
- if(elapsed > 200 && fix.kmSpeed > SPEED_IGNORE_LEVEL && elapsed < 10000)
+ if(fix.kmSpeed > SPEED_IGNORE_LEVEL)
{
- if(fix.kmSpeed > SPEED_TRESHOLD)
+ double treshold = DEFAULT_SPEED_TRESHOLD;
+
+ if(fix.eps > 0.01)
+ {
+ treshold = fix.eps * 0.23822 + 0.471204;
+
+ if(treshold < MIN_SPEED_TRESHOLD)
+ {
+ treshold = MIN_SPEED_TRESHOLD;
+ }
+ }
+
+ if(fix.kmSpeed > treshold && elapsed > 200 && elapsed < 8000)
{
double km = fix.kmSpeed * (static_cast<double>(elapsed) / (1000 * 3600));
trip_ += km;
}
else
{
- if(latestFix_.kmSpeed > 0.49)
+ if(latestFix_.kmSpeed > SPEED_IGNORE_LEVEL)
{
latestFix_ = fix;
latestFix_.speed = 0.0;
return latestFix_;
}
+double Odometer::getSignalStrength() const
+{
+ if(!location_)
+ {
+ return 0.0;
+ }
+
+ return location_->getSignalStrength();
+}
+
QString const& Odometer::getUnit()
{
if(Location::getUnit() == Location::KM)