diff options
Diffstat (limited to 'qmapwatchlet')
-rw-r--r-- | qmapwatchlet/arrow.png (renamed from qmapwatchlet/map-arrow.png) | bin | 180 -> 180 bytes | |||
-rw-r--r-- | qmapwatchlet/compass-metawatch-digital.qml | 53 | ||||
-rw-r--r-- | qmapwatchlet/compass.png | bin | 0 -> 211 bytes | |||
-rw-r--r-- | qmapwatchlet/compassview.cpp | 118 | ||||
-rw-r--r-- | qmapwatchlet/compassview.h | 56 | ||||
-rw-r--r-- | qmapwatchlet/compasswatchlet.cpp | 8 | ||||
-rw-r--r-- | qmapwatchlet/compasswatchlet.h | 10 | ||||
-rw-r--r-- | qmapwatchlet/qmapwatchlet.pro | 8 | ||||
-rw-r--r-- | qmapwatchlet/qmapwatchletplugin.cpp | 22 |
9 files changed, 224 insertions, 51 deletions
diff --git a/qmapwatchlet/map-arrow.png b/qmapwatchlet/arrow.png Binary files differindex f6beadf..f6beadf 100644 --- a/qmapwatchlet/map-arrow.png +++ b/qmapwatchlet/arrow.png diff --git a/qmapwatchlet/compass-metawatch-digital.qml b/qmapwatchlet/compass-metawatch-digital.qml index 9268435..c465e20 100644 --- a/qmapwatchlet/compass-metawatch-digital.qml +++ b/qmapwatchlet/compass-metawatch-digital.qml @@ -4,44 +4,39 @@ import com.javispedro.sowatch.metawatch 1.0 import com.javispedro.sowatch.qmap 1.0 MWPage { - MWTitle { - anchors.top: parent.top - anchors.left: parent.left - anchors.right: parent.right - text: qsTr("Trip computer") - icon.source: "trip-icon.png" - } - - PositionSource { - id: gps - active: watch.active - updateInterval: 2000 - } function formatSpeed(speed) { - if (speed < 10) { - return speed.toFixed(1); + var kmh = speed * 3.6; + if (kmh < 0) { + return ""; + } else if (kmh < 10) { + return kmh.toFixed(1) + " km/h"; } else { - return speed.toFixed(0); + return kmh.toFixed(0) + " km/h"; } } Column { - anchors.verticalCenter: parent.verticalCenter - MWLabel { - text: qsTr("Speed") - } - MWLabel { - id: speedLabel - text: gps.position.speedValid ? formatSpeed(gps.position.speed) : "" - } + anchors.top: parent.top + width: parent.width - MWLabel { - text: qsTr("Altitude") + CompassView { + anchors.horizontalCenter: parent.horizontalCenter + id: compass + updateEnabled: watch.active + updateInterval: 3000 + width: 48 + height: 48 } - } - - Column { + Row { + MWLabel { + text: qsTr("Speed") + " " + } + MWLabel { + id: speedLabel + text: formatSpeed(compass.currentSpeed) + } + } } } diff --git a/qmapwatchlet/compass.png b/qmapwatchlet/compass.png Binary files differnew file mode 100644 index 0000000..a754863 --- /dev/null +++ b/qmapwatchlet/compass.png diff --git a/qmapwatchlet/compassview.cpp b/qmapwatchlet/compassview.cpp new file mode 100644 index 0000000..5de44a5 --- /dev/null +++ b/qmapwatchlet/compassview.cpp @@ -0,0 +1,118 @@ +#include "qmapwatchletplugin.h" +#include "compassview.h" + +using namespace sowatch; +QTM_USE_NAMESPACE + +CompassView::CompassView(QDeclarativeItem *parent) : + QDeclarativeItem(parent), + _enabled(false), + _image(SOWATCH_QML_DIR "/qmapwatchlet/compass.png"), + _posSource(QGeoPositionInfoSource::createDefaultSource(this)), + _direction(-1.0), _speed(-1.0), _altitude(-1.0) +{ + if (_posSource) { + connect(_posSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + SLOT(handlePositionUpdate(QGeoPositionInfo))); + _posSource->lastKnownPosition(); + } else { + qWarning() << "No position source for moving map!"; + } + + setFlag(QGraphicsItem::ItemHasNoContents, false); +} + +bool CompassView::updateEnabled() const +{ + return _enabled; +} + +void CompassView::setUpdateEnabled(bool enabled) +{ + if (_posSource && _enabled != enabled) { + if (enabled) { + qDebug() << "Start position updates"; + _posSource->startUpdates(); + } else { + qDebug() << "Stop position updates"; + _posSource->stopUpdates(); + } + _enabled = enabled; + + emit updateEnabledChanged(); + } + +} + +int CompassView::updateInterval() const +{ + if (_posSource) { + return _posSource->updateInterval(); + } else { + return 0; + } +} + +void CompassView::setUpdateInterval(int msec) +{ + if (_posSource) { + _posSource->setUpdateInterval(msec); + emit updateIntervalChanged(); + } +} + +qreal CompassView::currentSpeed() const +{ + return _speed; +} + +qreal CompassView::currentAltitude() const +{ + return _altitude; +} + +void CompassView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(widget); + // Now render the arrow indicator + const int centerX = _size.width() / 2, centerY = _size.height() / 2; + + if (_direction >= 0.0) { + painter->save(); + painter->translate(centerX, centerY); + painter->rotate(_direction); + painter->drawImage(-_image.width() / 2, -_image.height() / 2, _image); + painter->restore(); + } +} + +void CompassView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + Q_UNUSED(oldGeometry); + _size = newGeometry.size().toSize(); +} + +void CompassView::handlePositionUpdate(const QGeoPositionInfo &info) +{ + qDebug() << "Pos update"; + + qreal newDirection = -1.0; + if (info.hasAttribute(QGeoPositionInfo::Direction)) { + newDirection = info.attribute(QGeoPositionInfo::Direction); + } + qDebug() << "New dir" << newDirection; + if (newDirection != _direction) { + _direction = newDirection; + update(); + } + + qreal newSpeed = -1.0; + if (info.hasAttribute(QGeoPositionInfo::GroundSpeed)) { + newSpeed = info.attribute(QGeoPositionInfo::GroundSpeed); + } + qDebug() << "New speed" << newSpeed; + if (newSpeed != _speed) { + _speed = newSpeed; + emit currentSpeedChanged(); + } +} diff --git a/qmapwatchlet/compassview.h b/qmapwatchlet/compassview.h new file mode 100644 index 0000000..3e87a65 --- /dev/null +++ b/qmapwatchlet/compassview.h @@ -0,0 +1,56 @@ +#ifndef COMPASSVIEW_H +#define COMPASSVIEW_H + +#include <QtGui/QImage> +#include <QtDeclarative/QDeclarativeItem> +#include <QtLocation/QGeoPositionInfoSource> + +using QTM_PREPEND_NAMESPACE(QGeoPositionInfoSource); +using QTM_PREPEND_NAMESPACE(QGeoPositionInfo); + +class CompassView : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(bool updateEnabled READ updateEnabled WRITE setUpdateEnabled NOTIFY updateEnabledChanged) + Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged) + + Q_PROPERTY(qreal currentSpeed READ currentSpeed NOTIFY currentSpeedChanged) + Q_PROPERTY(qreal currentAltitude READ currentAltitude NOTIFY currentAltitudeChanged) + +public: + explicit CompassView(QDeclarativeItem *parent = 0); + + bool updateEnabled() const; + void setUpdateEnabled(bool enabled); + + int updateInterval() const; + void setUpdateInterval(int msec); + + qreal currentSpeed() const; + qreal currentAltitude() const; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + +signals: + void updateEnabledChanged(); + void updateIntervalChanged(); + void currentSpeedChanged(); + void currentAltitudeChanged(); + +protected: + void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); + +private slots: + void handlePositionUpdate(const QGeoPositionInfo& info); + +private: + bool _enabled; + QSize _size; + QImage _image; + QGeoPositionInfoSource *_posSource; + qreal _direction; + qreal _speed; + qreal _altitude; +}; + +#endif // COMPASSVIEW_H diff --git a/qmapwatchlet/compasswatchlet.cpp b/qmapwatchlet/compasswatchlet.cpp index 3101955..cbc19a4 100644 --- a/qmapwatchlet/compasswatchlet.cpp +++ b/qmapwatchlet/compasswatchlet.cpp @@ -1,11 +1,11 @@ -#include "tripwatchlet.h" +#include "compasswatchlet.h" using namespace sowatch; -const QLatin1String TripWatchlet::myId("com.javispedro.sowatch.trip"); +const QLatin1String CompassWatchlet::myId("com.javispedro.sowatch.compass"); -TripWatchlet::TripWatchlet(WatchServer* server) : +CompassWatchlet::CompassWatchlet(WatchServer* server) : DeclarativeWatchlet(server, myId) { - setSource(QUrl(SOWATCH_QML_DIR "/qmapwatchlet/trip-" + server->watch()->model() + ".qml")); + setSource(QUrl(SOWATCH_QML_DIR "/qmapwatchlet/compass-" + server->watch()->model() + ".qml")); } diff --git a/qmapwatchlet/compasswatchlet.h b/qmapwatchlet/compasswatchlet.h index 185205b..88547a2 100644 --- a/qmapwatchlet/compasswatchlet.h +++ b/qmapwatchlet/compasswatchlet.h @@ -1,20 +1,20 @@ -#ifndef TRIPWATCHLET_H -#define TRIPWATCHLET_H +#ifndef COMPASSWATCHLET_H +#define COMPASSWATCHLET_H #include <sowatch.h> namespace sowatch { -class TripWatchlet : public DeclarativeWatchlet +class CompassWatchlet : public DeclarativeWatchlet { Q_OBJECT public: - explicit TripWatchlet(WatchServer* server); + explicit CompassWatchlet(WatchServer* server); static const QLatin1String myId; }; } -#endif // TRIPWATCHLET_H +#endif // COMPASSWATCHLET_H diff --git a/qmapwatchlet/qmapwatchlet.pro b/qmapwatchlet/qmapwatchlet.pro index ab51e30..6ed3fcf 100644 --- a/qmapwatchlet/qmapwatchlet.pro +++ b/qmapwatchlet/qmapwatchlet.pro @@ -6,13 +6,13 @@ CONFIG += mobility MOBILITY += location SOURCES += qmapwatchletplugin.cpp qmapwatchlet.cpp mapview.cpp \ - compasswatchlet.cpp + compasswatchlet.cpp compassview.cpp HEADERS += qmapwatchletplugin.h qmapwatchlet.h mapview.h \ - compasswatchlet.h + compasswatchlet.h compassview.h -qml_files.files = map-metawatch-digital.qml map-icon.png map-arrow.png \ - compass-metawatch-digital.qml compass-icon.png +qml_files.files = map-metawatch-digital.qml map-icon.png arrow.png \ + compass-metawatch-digital.qml compass-icon.png compass.png LIBS += -L$$OUT_PWD/../libsowatch/ -lsowatch INCLUDEPATH += $$PWD/../libsowatch diff --git a/qmapwatchlet/qmapwatchletplugin.cpp b/qmapwatchlet/qmapwatchletplugin.cpp index 5beaf7e..32762d0 100644 --- a/qmapwatchlet/qmapwatchletplugin.cpp +++ b/qmapwatchlet/qmapwatchletplugin.cpp @@ -1,7 +1,8 @@ #include "qmapwatchlet.h" #include "mapview.h" +#include "compassview.h" #include "qmapwatchletplugin.h" -#include "tripwatchlet.h" +#include "compasswatchlet.h" using namespace sowatch; QTM_USE_NAMESPACE @@ -18,6 +19,7 @@ QMapWatchletPlugin::QMapWatchletPlugin(QObject *parent) : _provider = 0; } qmlRegisterType<MapView>("com.javispedro.sowatch.qmap", 1, 0, "MapView"); + qmlRegisterType<CompassView>("com.javispedro.sowatch.qmap", 1, 0, "CompassView"); } QMapWatchletPlugin::~QMapWatchletPlugin() @@ -29,7 +31,7 @@ QMapWatchletPlugin::~QMapWatchletPlugin() QStringList QMapWatchletPlugin::watchlets() { QStringList l; - l << QMapWatchlet::myId; + l << QMapWatchlet::myId << CompassWatchlet::myId; return l; } @@ -38,21 +40,23 @@ WatchletPluginInterface::WatchletInfo QMapWatchletPlugin::describeWatchlet(const WatchletInfo info; if (id == QMapWatchlet::myId) { info.name = tr("Map"); - info.icon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmapwatchlet/icon.png"); - } else if (id == TripWatchlet::myId) { + info.icon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmapwatchlet/map-icon.png"); + } else if (id == CompassWatchlet::myId) { info.name = tr("Trip computer"); - info.icon = + info.icon = QUrl::fromLocalFile(SOWATCH_QML_DIR "/qmapwatchlet/compass-icon.png"); } - if (id != ) return info; - return info; } Watchlet* QMapWatchletPlugin::getWatchlet(const QString &id, ConfigKey *config, WatchServer *server) { Q_UNUSED(config); - if (id != QMapWatchlet::myId) return 0; - return new QMapWatchlet(server); + if (id == QMapWatchlet::myId) { + return new QMapWatchlet(server); + } else if (id == CompassWatchlet::myId) { + return new CompassWatchlet(server); + } + return 0; } QGeoServiceProvider *QMapWatchletPlugin::geoServiceProvider() |