From: Katri Kaikkonen Date: Mon, 2 Aug 2010 13:46:46 +0000 (+0300) Subject: Merge branch 'master' into indicator X-Git-Tag: v2.0b-1~38^2~33 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=806b3f6b21d22d17c8dde04036c6f11329d26e7a;p=situare Merge branch 'master' into indicator Conflicts: src/map/mapengine.cpp src/ui/indicatorbutton.cpp src/ui/mainwindow.cpp --- 806b3f6b21d22d17c8dde04036c6f11329d26e7a diff --cc src/map/mapengine.cpp index b6dc498,5eb4bca..56f91f7 --- a/src/map/mapengine.cpp +++ b/src/map/mapengine.cpp @@@ -177,31 -176,6 +177,20 @@@ QPoint MapEngine::convertSceneCoordinat 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()) { @@@ -259,36 -233,22 +248,24 @@@ void MapEngine::gpsPositionUpdate(GeoCo { 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__; @@@ -464,10 -413,8 +430,10 @@@ void MapEngine::setCenterPosition(Scene 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) @@@ -538,48 -485,6 +504,24 @@@ void MapEngine::setTilesGridSize(const 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__; @@@ -639,8 -551,8 +590,8 @@@ void MapEngine::zoomed( 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() diff --cc src/map/mapscene.cpp index 5c5c00a,3c74c60..7330f9f --- a/src/map/mapscene.cpp +++ b/src/map/mapscene.cpp @@@ -146,9 -163,11 +163,11 @@@ void MapScene::removeOutOfViewTiles(QRe // if view is near east limit of the map, then there is duplicate tiles also on the opposite // side of the world which are removed from allTiles - if (tilesGrid.right() > (MapEngine::tileMaxIndex(zoomLevel) - tilesGridWidthHalf + MAP_GRID_PADDING)) { + if (tilesGrid.right() > ((MapTile::lastTileIndex(zoomLevel) + - tilesGridWidthHalf + + MAP_GRID_PADDING))) { QRect oppositeRect = m_tilesSceneRect; - oppositeRect.translate(-OMS_MAP_PIXELS_X, 0); + oppositeRect.translate(-OSM_MAP_PIXELS_X, 0); QList oppositeItems = items(oppositeRect, Qt::IntersectsItemBoundingRect); foreach (QGraphicsItem *item, oppositeItems) allItems.removeOne(item); diff --cc src/ui/indicatorbutton.cpp index 46f3a13,f6c2aeb..5c7a28f --- a/src/ui/indicatorbutton.cpp +++ b/src/ui/indicatorbutton.cpp @@@ -43,27 -41,23 +43,27 @@@ const qreal M_TO_KM = 1000 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); @@@ -181,17 -168,18 +181,18 @@@ void IndicatorButton::mouseReleaseEvent 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) diff --cc src/ui/mainwindow.cpp index 0f3803c,f585010..6dda179 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@@ -183,16 -181,16 +183,19 @@@ void MainWindow::buildIndicatorButtonPa { 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)