From: eshe Date: Thu, 15 Jul 2010 22:27:18 +0000 (+0100) Subject: Added new theme. Made detail screen also themable. X-Git-Url: http://git.maemo.org/git/?p=jspeed;a=commitdiff_plain;h=72650dd361fdc879b8295ef11a1e0c1cbc0cbd91 Added new theme. Made detail screen also themable. --- diff --git a/src/data/graphical.jspeed b/src/data/graphical.jspeed new file mode 100755 index 0000000..aac7e0d Binary files /dev/null and b/src/data/graphical.jspeed differ diff --git a/src/detailscreen.cpp b/src/detailscreen.cpp index 660ba27..4599e4c 100644 --- a/src/detailscreen.cpp +++ b/src/detailscreen.cpp @@ -30,19 +30,20 @@ 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 START_HEIGHT = 80; 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(); - 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())); @@ -76,6 +77,7 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent) 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())); @@ -86,6 +88,8 @@ DetailScreen::DetailScreen(QWidget* parent): GraphicsScreen(parent) void DetailScreen::update() { + ThemeScreen::update(); + speed_->setPlainText(roundDouble(Odometer::instance().getLatestFix().speed)); trip_->setPlainText(roundDouble(Odometer::instance().getTrip())); total_->setPlainText(roundDouble(Odometer::instance().getTotal())); @@ -123,7 +127,7 @@ void DetailScreen::updateUnits() void DetailScreen::reArrange() { - GraphicsScreen::reArrange(); + ThemeScreen::reArrange(); int width = getScene()->width(); int height = getScene()->height(); @@ -175,7 +179,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; } @@ -183,9 +188,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; } @@ -216,3 +223,34 @@ int DetailScreen::getStrength() double strength = round(Odometer::instance().getSignalStrength() / 25.0); return static_cast(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); +} diff --git a/src/detailscreen.h b/src/detailscreen.h index 5e94ff5..94d51a8 100644 --- a/src/detailscreen.h +++ b/src/detailscreen.h @@ -19,19 +19,20 @@ #ifndef DETAILSCREEN_H #define DETAILSCREEN_H -#include "graphicsscreen.h" +#include "themescreen.h" class QString; class QGraphicsTextItem; class QGraphicsLineItem; class QGraphicsPixmapItem; -class DetailScreen : public GraphicsScreen +class DetailScreen : public ThemeScreen { Q_OBJECT public: DetailScreen(QWidget* parent = 0); + void setColor(QString const& color); public slots: virtual void update(); diff --git a/src/detailwidget.cpp b/src/detailwidget.cpp index 4a6f523..cbacc65 100644 --- a/src/detailwidget.cpp +++ b/src/detailwidget.cpp @@ -43,3 +43,8 @@ void DetailWidget::flip() { screen_->flip(); } + +DetailScreen* DetailWidget::getScreen() const +{ + return screen_; +} diff --git a/src/detailwidget.h b/src/detailwidget.h index 037c60d..d016fc9 100644 --- a/src/detailwidget.h +++ b/src/detailwidget.h @@ -29,6 +29,7 @@ class DetailWidget : public WidgetScreen public: DetailWidget(QWidget* parent = 0); + DetailScreen* getScreen() const; public slots: virtual void update(); diff --git a/src/graphicselement.h b/src/graphicselement.h index 8880c07..ee9c4c2 100644 --- a/src/graphicselement.h +++ b/src/graphicselement.h @@ -25,6 +25,7 @@ class QString; class QByteArray; class QFont; +class QGraphicsItem; class GraphicsScene; class Reader; @@ -43,6 +44,7 @@ public: virtual bool setAttribute(QString const& name, QString const& value) = 0; virtual void addToScene(GraphicsScene* scene) = 0; virtual void update() = 0; + virtual QGraphicsItem* getElement() const = 0; QString const& getError() const; protected: diff --git a/src/graphicsscreen.cpp b/src/graphicsscreen.cpp index 42c67f8..8520c8c 100644 --- a/src/graphicsscreen.cpp +++ b/src/graphicsscreen.cpp @@ -25,7 +25,7 @@ namespace { - int const PADDING = 8; + int const PADDING = 6; } GraphicsScreen::GraphicsScreen(QWidget* parent): QGraphicsView(parent), diff --git a/src/imageelement.cpp b/src/imageelement.cpp index 675924b..066c1b7 100644 --- a/src/imageelement.cpp +++ b/src/imageelement.cpp @@ -135,3 +135,8 @@ bool ImageElement::loadImage(QString const& name) return true; } + +QGraphicsItem* ImageElement::getElement() const +{ + return element_; +} diff --git a/src/imageelement.h b/src/imageelement.h index b4ac299..f7b1d53 100644 --- a/src/imageelement.h +++ b/src/imageelement.h @@ -24,6 +24,7 @@ class QString; class QGraphicsPixmapItem; +class QGraphicsItem; class Reader; class GraphicsScene; @@ -35,6 +36,7 @@ public: virtual bool setAttribute(QString const& name, QString const& value); virtual void addToScene(GraphicsScene* scene); virtual void update(); + virtual QGraphicsItem* getElement() const; private: bool loadImage(QString const& name); diff --git a/src/location.cpp b/src/location.cpp index 3b5ee32..d8ef14c 100644 --- a/src/location.cpp +++ b/src/location.cpp @@ -87,7 +87,6 @@ double Location::getSignalStrength() const { if(!hasFix()) { - qDebug() << "No fix"; return 0.0; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e0280d3..f383234 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -27,6 +27,7 @@ #include "mainwindowstack.h" #include "theme.h" #include "detailwidget.h" +#include "detailscreen.h" #include "mainmenu.h" #include "odometer.h" @@ -51,7 +52,9 @@ void MainWindow::addScreens() connect(stack_, SIGNAL(settingsPressed()), this, SLOT(openMenu())); connect(stack_, SIGNAL(closePressed()), this, SIGNAL(quit())); - theme_ = new Theme; + DetailWidget* details = new DetailWidget(this); + + theme_ = new Theme(details->getScreen()); if(!loadTheme()) { @@ -59,7 +62,7 @@ void MainWindow::addScreens() } stack_->addScreen(theme_); - stack_->addScreen(new DetailWidget(this)); + stack_->addScreen(details); connect(QApplication::desktop(), SIGNAL(resized(int)), stack_, SLOT(reArrange())); @@ -83,6 +86,10 @@ bool MainWindow::loadTheme() { setAttribute(Qt::WA_Maemo5PortraitOrientation, true); } + else + { + setAttribute(Qt::WA_Maemo5LandscapeOrientation, true); + } return true; } diff --git a/src/odometer.cpp b/src/odometer.cpp index 161f0b2..41c6fe3 100644 --- a/src/odometer.cpp +++ b/src/odometer.cpp @@ -33,6 +33,7 @@ namespace QString const MILE_UNIT = "mi"; QString const KM_SPEEDUNIT = "km/h"; QString const MILE_SPEEDUNIT = "mph"; + static const int FIX_TIMEOUT = 4000; double const DEFAULT_SPEED_TRESHOLD = 8.0; double const MIN_SPEED_TRESHOLD = 0.8; double const SPEED_IGNORE_LEVEL = 0.01; @@ -58,6 +59,10 @@ mainTimer_(0), emitUpdate_(true), location_(0), signalTimer_(0) signalTimer_->setInterval(1000); connect(signalTimer_, SIGNAL(timeout()), this, SIGNAL(timeUpdated())); updateUnit(); + timeoutTimer_ = new QTimer(this); + timeoutTimer_->setSingleShot(true); + connect(timeoutTimer_, SIGNAL(timeout()), this, SLOT(fixTimeout())); + } Odometer::~Odometer() @@ -104,6 +109,7 @@ void Odometer::update(Location::Fix const& fix) int elapsed = fixTimer_->elapsed(); fixTimer_->restart(); + timeoutTimer_->start(FIX_TIMEOUT); if(fix.kmSpeed > SPEED_IGNORE_LEVEL) { @@ -119,7 +125,7 @@ void Odometer::update(Location::Fix const& fix) } } - if(fix.kmSpeed > treshold && elapsed > 200 && elapsed < 8000) + if(fix.kmSpeed > treshold && elapsed > 200 && elapsed < FIX_TIMEOUT) { double km = fix.kmSpeed * (static_cast(elapsed) / (1000 * 3600)); trip_ += km; @@ -140,16 +146,19 @@ void Odometer::update(Location::Fix const& fix) } else { - if(latestFix_.kmSpeed > SPEED_IGNORE_LEVEL) - { - latestFix_ = fix; - latestFix_.speed = 0.0; - latestFix_.kmSpeed = 0.0; - emit dataUpdated(); - } + fixTimeout(); + } +} - endTiming(); +void Odometer::fixTimeout() +{ + if(latestFix_.kmSpeed > SPEED_IGNORE_LEVEL) + { + latestFix_ = Location::Fix(); + emit dataUpdated(); } + + endTiming(); } double Odometer::getTrip() const diff --git a/src/odometer.h b/src/odometer.h index 0bbee30..c68fee3 100644 --- a/src/odometer.h +++ b/src/odometer.h @@ -45,21 +45,22 @@ public: static QString const& getUnit(); static QString const& getSpeedUnit(); -public slots: - void update(Location::Fix const& fix); - void updateUnit(); - signals: void dataUpdated(); void timeUpdated(); void unitChanged(); public slots: + void update(Location::Fix const& fix); + void updateUnit(); void resetTrip(); void resetTotal(); void resetAll(); void store(); +private slots: + void fixTimeout(); + private: Q_DISABLE_COPY(Odometer); Odometer(); @@ -78,6 +79,7 @@ private: bool emitUpdate_; Location* location_; QTimer* signalTimer_; + QTimer* timeoutTimer_; }; #endif diff --git a/src/pointer.cpp b/src/pointer.cpp index 973a412..b48412e 100644 --- a/src/pointer.cpp +++ b/src/pointer.cpp @@ -206,3 +206,9 @@ bool Pointer::loadImage(QString const& name) return true; } + +QGraphicsItem* Pointer::getElement() const +{ + return element_; +} + diff --git a/src/pointer.h b/src/pointer.h index a5f063f..d7870a7 100644 --- a/src/pointer.h +++ b/src/pointer.h @@ -24,6 +24,7 @@ class QGraphicsPixmapItem; class QTimeLine; +class QGraphicsItem; class GraphicsScene; class Reader; @@ -38,6 +39,7 @@ public: virtual bool setAttribute(QString const& name, QString const& value); virtual void addToScene(GraphicsScene* scene); virtual void update(); + virtual QGraphicsItem* getElement() const; private slots: void setFrame(int frame); diff --git a/src/rectangle.cpp b/src/rectangle.cpp index 5448748..2e0705b 100644 --- a/src/rectangle.cpp +++ b/src/rectangle.cpp @@ -111,3 +111,8 @@ void Rectangle::addToScene(GraphicsScene* scene) void Rectangle::update() { } + +QGraphicsItem* Rectangle::getElement() const +{ + return element_; +} diff --git a/src/rectangle.h b/src/rectangle.h index b9c1fb6..1ccae40 100644 --- a/src/rectangle.h +++ b/src/rectangle.h @@ -24,6 +24,7 @@ class QString; class QGraphicsRectItem; +class QGraphicsItem; class Reader; class GraphicsScene; @@ -35,6 +36,7 @@ public: virtual bool setAttribute(QString const& name, QString const& value); virtual void addToScene(GraphicsScene* scene); virtual void update(); + virtual QGraphicsItem* getElement() const; private: QGraphicsRectItem* element_; diff --git a/src/resources/themes/default/theme.xml b/src/resources/themes/default/theme.xml index d1d21f5..0064f70 100644 --- a/src/resources/themes/default/theme.xml +++ b/src/resources/themes/default/theme.xml @@ -1,4 +1,11 @@ - + + + + 0 + 0 + background.png + + 0 diff --git a/src/textelement.cpp b/src/textelement.cpp index 5779d1c..b9d5a79 100644 --- a/src/textelement.cpp +++ b/src/textelement.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include "textelement.h" @@ -42,7 +43,7 @@ namespace const QString FIELDS[TextElement::FIELD_COUNT] = {"TRIP", "TOTAL", "SPEED", "MAXSPEED", "AVGSPEED", - "UNIT", "SPEEDUNIT"}; + "UNIT", "SPEEDUNIT", "TIME"}; } TextElement::TextElement(Reader* reader): GraphicsElement(reader), @@ -196,6 +197,9 @@ void TextElement::replaceSpecialFields(QString& value) case SPEEDUNIT: replaceValue(value, f, o->getSpeedUnit()); break; + case TIME: + replaceValue(value, f, QTime::currentTime().toString("hh:mm")); + break; default: qDebug() << "Unknown field: " << f; } @@ -223,3 +227,9 @@ QString TextElement::formatString(double val) return result; } + + +QGraphicsItem* TextElement::getElement() const +{ + return element_; +} diff --git a/src/textelement.h b/src/textelement.h index ec4f7f1..19116c1 100644 --- a/src/textelement.h +++ b/src/textelement.h @@ -21,20 +21,22 @@ #include "graphicselement.h" -class Reader; class QString; -class GraphicsScene; +class QGraphicsItem; class QGraphicsTextItem; +class Reader; +class GraphicsScene; class TextElement : public GraphicsElement { public: enum Attribute {XPOS, YPOS, DATA, FORMAT, WIDTH, ALIGN, COLOR, SIZE, FONT, ATTRIBUTE_COUNT}; - enum Field {TRIP, TOTAL, SPEED, MAXSPEED, AVGSPEED, UNIT, SPEEDUNIT, FIELD_COUNT}; + enum Field {TRIP, TOTAL, SPEED, MAXSPEED, AVGSPEED, UNIT, SPEEDUNIT, TIME, FIELD_COUNT}; TextElement(Reader* reader); virtual bool setAttribute(QString const& name, QString const& value); virtual void addToScene(GraphicsScene* scene); virtual void update(); + virtual QGraphicsItem* getElement() const; private: void updateHtml(QString const& data); diff --git a/src/theme.cpp b/src/theme.cpp index 09baddf..c7d97d4 100644 --- a/src/theme.cpp +++ b/src/theme.cpp @@ -31,6 +31,7 @@ #include "zipreader.h" #include "filereader.h" #include "themescreen.h" +#include "detailscreen.h" #include "settings.h" namespace @@ -39,9 +40,9 @@ namespace QString const THEME_SUFFIX = ".jspeed"; } -Theme::Theme(QWidget* parent): WidgetScreen(parent), +Theme::Theme(DetailScreen* detailScreen, QWidget* parent): WidgetScreen(parent), portraitId_(-1), landscapeId_(-1), reader_(0), -portrait_(0), landscape_(0), portraitMode_(false) +portrait_(0), landscape_(0), detailScreen_(detailScreen), portraitMode_(false) { } @@ -77,7 +78,6 @@ bool Theme::load() if(read()) { - qDebug() << "Ladattiin " << theme; return true; } else @@ -136,6 +136,28 @@ bool Theme::read() return false; } + QDomNodeList detailConfigs = doc.elementsByTagName("detailscreen"); + + if(detailConfigs.size() > 1) + { + error_ = "Multiple tags specified"; + return false; + } + + if(detailConfigs.size() == 1) + { + detailScreen_->removeElements(); + + QDomNode color = detailConfigs.at(0).attributes().namedItem("color"); + + if(!color.isNull()) + { + detailScreen_->setColor(color.toAttr().value()); + } + + detailScreen_->load(detailConfigs.at(0), reader_); + } + QDomNodeList orientations = doc.elementsByTagName("orientation"); if(orientations.isEmpty()) @@ -204,6 +226,22 @@ bool Theme::read() portraitId_ = addWidget(portrait_); connectSignals(portrait_); } + + if(landscape_ && portrait_) + { + QRect rect = QApplication::desktop()->screenGeometry(); + + if(rect.height() > rect.width()) + { + setCurrentIndex(portraitId_); + portraitMode_ = true; + } + else + { + setCurrentIndex(landscapeId_); + portraitMode_ = false; + } + } } else { @@ -233,12 +271,12 @@ QString const& Theme::error() const bool Theme::portraitEnabled() const { - return portraitId_ != -1; + return portrait_ != 0; } bool Theme::landscapeEnabled() const { - return landscapeId_ != -1; + return landscape_ != 0; } void Theme::reArrange() diff --git a/src/theme.h b/src/theme.h index 79682d5..308043e 100644 --- a/src/theme.h +++ b/src/theme.h @@ -24,13 +24,14 @@ class QString; class Reader; class ThemeScreen; +class DetailScreen; class Theme : public WidgetScreen { Q_OBJECT public: - Theme(QWidget* parent = 0); + Theme(DetailScreen* detailScreen, QWidget* parent = 0); ~Theme(); bool load(); bool portraitEnabled() const; @@ -52,6 +53,7 @@ private: QString error_; ThemeScreen* portrait_; ThemeScreen* landscape_; + DetailScreen* detailScreen_; bool portraitMode_; }; diff --git a/src/themescreen.cpp b/src/themescreen.cpp index d4dcaa0..6458836 100644 --- a/src/themescreen.cpp +++ b/src/themescreen.cpp @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -24,6 +25,7 @@ #include "themescreen.h" #include "graphicselement.h" #include "reader.h" +#include "graphicsscene.h" ThemeScreen::ThemeScreen(QWidget* parent): GraphicsScreen(parent) { @@ -68,6 +70,24 @@ bool ThemeScreen::load(QDomNode const& data, Reader* reader) return true; } +void ThemeScreen::removeElements() +{ + for(int i = 0; i < elements_.size(); i++) + { + QGraphicsItem* item = elements_.at(i)->getElement(); + + if(item) + { + getScene()->removeItem(item); + delete item; + } + + delete elements_.at(i); + } + + elements_.clear(); +} + void ThemeScreen::update() { for(int i = 0; i < elements_.size(); i++) diff --git a/src/themescreen.h b/src/themescreen.h index 320cca1..33fc14a 100644 --- a/src/themescreen.h +++ b/src/themescreen.h @@ -33,6 +33,7 @@ public: ThemeScreen(QWidget* parent = 0); bool load(QDomNode const& data, Reader* reader); virtual void update(); + void removeElements(); private: QList elements_;