return QPoint(x, y);
}
- SceneCoordinate MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileNumber)
- {
- qDebug() << __PRETTY_FUNCTION__;
-
- int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
- int x = tileNumber.x() * OSM_TILE_SIZE_X * pow;
- int y = tileNumber.y() * OSM_TILE_SIZE_Y * pow;
-
- return SceneCoordinate(x, y);
- }
-
+QRectF MapEngine::currentViewSceneRect() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ const QPoint ONE_PIXEL = QPoint(1, 1);
+
+ QGraphicsView *view = m_mapScene->views().at(0);
+ QPointF sceneTopLeft = view->mapToScene(0, 0);
+ QPoint viewBottomRight = QPoint(view->size().width(), view->size().height()) - ONE_PIXEL;
+ QPointF sceneBottomRight = view->mapToScene(viewBottomRight);
+
+ return QRectF(sceneTopLeft, sceneBottomRight);
+}
+
void MapEngine::disableAutoCenteringIfRequired(SceneCoordinate coordinate)
{
if (isAutoCenteringEnabled()) {
{
qDebug() << __PRETTY_FUNCTION__;
- m_gpsLocationItem->updatePosition(SceneCoordinate(position), accuracy);
- m_gpsPosition = position;
- m_mapScene->spanItems(currentViewSceneRect());
+ // update GPS location item (but only if accuracy is a valid number)
+ if (!isnan(accuracy)) {
+ qreal resolution = MapScene::horizontalResolutionAtLatitude(position.latitude());
+ m_gpsLocationItem->updateItem(SceneCoordinate(position).toPointF(), accuracy, resolution);
+ }
- m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
++m_mapScene->spanItems(currentViewSceneRect());
+
+ // do automatic centering (if enabled)
if (m_autoCenteringEnabled) {
m_lastAutomaticPosition = SceneCoordinate(position);
m_scrollStartedByGps = true;
scrollToPosition(m_lastAutomaticPosition);
}
+
+ updateDirectionIndicator();
}
- qreal MapEngine::greatCircleDistance(GeoCoordinate firstLocation, GeoCoordinate secondLocation)
- {
- qDebug() << __PRETTY_FUNCTION__;
-
- const qreal TO_RAD = (M_PI / 180);
-
- qreal dLat = (secondLocation.latitude() - firstLocation.latitude()) * TO_RAD;
- qreal dLon = (secondLocation.longitude() - firstLocation.longitude()) * TO_RAD;
- qreal a = pow(sin(dLat / 2), 2)
- + cos(firstLocation.latitude() * TO_RAD)
- * cos(secondLocation.latitude() * TO_RAD)
- * pow(sin(dLon / 2), 2);
- qreal c = 2 * atan2(sqrt(a), sqrt(1 - a));
-
- return (EARTH_RADIUS * c);
- }
-
void MapEngine::init()
{
qDebug() << __PRETTY_FUNCTION__;
m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
}
- m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+ m_mapScene->spanItems(currentViewSceneRect());
- emit newMapResolution(sceneResolution());
+ emit newMapResolution(viewResolution());
+
+ updateDirectionIndicator();
}
void MapEngine::setGPSEnabled(bool enabled)
m_tilesGridSize.setWidth(gridWidth);
}
- int MapEngine::tileMaxIndex(int zoomLevel)
- {
- qDebug() << __PRETTY_FUNCTION__;
-
- // subtract one because first tile index is zero
- return tilesPerSide(zoomLevel) - 1;
- }
-
- QString MapEngine::tilePath(int zoomLevel, int x, int y)
- {
- qDebug() << __PRETTY_FUNCTION__;
-
- QString tilePathString(QString::number(zoomLevel) + "/");
- tilePathString.append(QString::number(x) + "/");
- tilePathString.append(QString::number(y));
-
- return tilePathString;
- }
-
- int MapEngine::tilesPerSide(int zoomLevel)
- {
- return (1 << zoomLevel);
- }
-
+void MapEngine::updateDirectionIndicator()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ /// @todo implement distance calculation
+ qreal distance = greatCircleDistance(m_gpsPosition, m_sceneCoordinate);
+
+ qreal direction = m_sceneCoordinate.azimuthTo(SceneCoordinate(m_gpsPosition));
+
+ // direction indicator triangle should be drawn only if the gps location item is not currently
+ // visible on the view
+ bool drawDirectionIndicatorTriangle = true;
+ if (currentViewSceneRect().contains(m_gpsLocationItem->pos()))
+ drawDirectionIndicatorTriangle = false;
+
+ emit directionIndicatorValuesUpdate(direction, distance, drawDirectionIndicatorTriangle);
+}
+
void MapEngine::updateViewTilesSceneRect()
{
qDebug() << __PRETTY_FUNCTION__;
m_mapScene->setZoomLevel(m_zoomLevel);
getTiles(m_sceneCoordinate);
m_mapScene->setSceneVerticalOverlap(m_viewSize.height(), m_zoomLevel);
- m_mapScene->spanItems(m_zoomLevel, m_sceneCoordinate, m_viewSize);
+ m_mapScene->spanItems(currentViewSceneRect());
- emit newMapResolution(sceneResolution());
+ emit newMapResolution(viewResolution());
}
void MapEngine::zoomIn()
IndicatorButton::IndicatorButton(QWidget *parent)
: QToolButton(parent),
- m_isDraggable(false)
+ m_drawTriangle(false),
+// m_isDraggable(false),
+ m_direction(0),
+ m_distance(0),
+ m_distanceText("")
{
- m_indicatorLeds[OFF].load(":res/images/led_red.png");
- m_indicatorLeds[ON].load(":res/images/led_red_s.png");
+ m_indicatorLeds[OFF].load(":res/images/gps_position.png");
+ m_indicatorLeds[ON].load(":res/images/gps_position_s.png");
setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
- QPoint(DIRECTION_INDICATOR_POSITION_X,
- DIRECTION_INDICATOR_POSITION_Y)).toPoint();
+// QSettings settings(DIRECTORY_NAME, FILE_NAME);
+// QPoint savedLocation = settings.value(DIRECTION_INDICATOR_BUTTON_POSITION,
+// QPoint(DIRECTION_INDICATOR_POSITION_X,
+// DIRECTION_INDICATOR_POSITION_Y)).toPoint();
- if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
- savedLocation.rx() = DIRECTION_INDICATOR_POSITION_X;
- savedLocation.ry() = DIRECTION_INDICATOR_POSITION_Y;
- }
+// if(savedLocation.x() > DEFAULT_SCREEN_WIDTH || savedLocation.y() > DEFAULT_SCREEN_HEIGHT) {
+// savedLocation.rx() = DIRECTION_INDICATOR_POSITION_X;
+// savedLocation.ry() = DIRECTION_INDICATOR_POSITION_Y;
+// }
- move(savedLocation);
+// move(savedLocation);
// Normal background
m_normalColor = new QColor(Qt::black);
void IndicatorButton::setDraggable(bool mode, QPoint eventPosition)
{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_isDraggable = mode;
-
- if(mode) {
- emit draggingModeTriggered();
- m_forceReleaseTimer->start();
- m_dragPosition = eventPosition;
- } else {
- m_forceReleaseTimer->stop();
- }
- update();
+// qDebug() << __PRETTY_FUNCTION__;
+
+// m_isDraggable = mode;
+
+// if(mode) {
++// emit draggingModeTriggered();
+// m_forceReleaseTimer->start();
+// m_dragPosition = eventPosition;
+// } else {
+// m_forceReleaseTimer->stop();
+// }
+// update();
}
void IndicatorButton::screenResized(const QSize &newSize)
{
qDebug() << __PRETTY_FUNCTION__;
- m_indicatorButton = new IndicatorButton(this);
+ m_indicatorButtonPanel = new IndicatorButtonPanel(this);
- connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
- this, SIGNAL(autoCenteringTriggered(bool)));
+// connect(m_indicatorButton, SIGNAL(autoCenteringTriggered(bool)),
+// this, SIGNAL(autoCenteringTriggered(bool)));
- connect(m_mapView, SIGNAL(viewResized(QSize)),
- m_indicatorButton, SLOT(screenResized(QSize)));
+// connect(m_mapView, SIGNAL(viewResized(QSize)),
+// m_indicatorButton, SLOT(screenResized(QSize)));
- connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
- this, SIGNAL(draggingModeTriggered()));
+// connect(this, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+// m_indicatorButton, SLOT(updateValues(qreal, qreal, bool)));
++
++// connect(m_indicatorButton, SIGNAL(draggingModeTriggered()),
++// this, SIGNAL(draggingModeTriggered()));
}
void MainWindow::buildInformationBox(const QString &message, bool modal)