QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
{
QRect rect = sceneBoundingRect().toRect();
-
- // returned rect size is size of original image and not scaled to size of currently presented
- // image because of using ItemIgnoresTransformations flag. Thus the rect must be scaled
-
int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
- rect.adjust(-widthDelta, -heightDelta, widthDelta, heightDelta);
-
- // if rectangle goes over west side limit of the world then move it to east side
- // so collision check does work if items are on boths edges of the world
- if (rect.left() < 0)
-;// rect.translate(WORLD_PIXELS_X, 0);
-
- return rect;
+ return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
}
#include "friendgroupitem.h"
#include "friendlocationitem.h"
-#include "mapcommon.h"
#include "mapengine.h"
#include "mapscene.h"
#include "user/user.h"
checkAllFriendsForCollidingFriends();
}
-void FriendItemsHandler::spanFriendItems(QRect viewSceneRect)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- foreach (FriendGroupItem *item, m_friendGroupItems) {
- if (item->pos().x() < viewSceneRect.left()) {
- qWarning() << __PRETTY_FUNCTION__ << "span item to right";
- item->pos().setX(item->pos().x() + WORLD_PIXELS_X);
- }
- else if (item->pos().x() > viewSceneRect.right()) {
- qWarning() << __PRETTY_FUNCTION__ << "span item to left";
- item->pos().setX(item->pos().x() - WORLD_PIXELS_X);
- }
- }
-
- foreach (FriendLocationItem *item, m_friendItems) {
- /// @todo DUPLICATE CODE
- if (item->pos().x() < viewSceneRect.left()) {
- qWarning() << __PRETTY_FUNCTION__ << "span item to right";
- item->pos().setX(item->pos().x() + WORLD_PIXELS_X);
- }
- else if (item->pos().x() > viewSceneRect.right()) {
- qWarning() << __PRETTY_FUNCTION__ << "span item to left";
- item->pos().setX(item->pos().x() - WORLD_PIXELS_X);
- }
- }
-}
-
void FriendItemsHandler::updateFriendItem(FriendLocationItem *friendItem, User *friendData)
{
qDebug() << __PRETTY_FUNCTION__;
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-public:
- void spanFriendItems(QRect viewSceneRect);
-
private:
/**
* @brief Add new FriendLocationItem
{
qDebug() << __PRETTY_FUNCTION__;
- int horizontalPadding = GRID_PADDING;
- if (m_zoomLevel <= 2)
- horizontalPadding = 0;
-
QPoint tileCoordinate = convertSceneCoordinateToTileNumber(m_zoomLevel, sceneCoordinate);
- int gridWidth = (m_viewSize.width() / TILE_SIZE_X + 1) + (horizontalPadding * 2);
+ int gridWidth = (m_viewSize.width() / TILE_SIZE_X + 1) + (GRID_PADDING * 2);
int gridHeight = (m_viewSize.height() / TILE_SIZE_Y + 1) + (GRID_PADDING * 2);
int topLeftX = tileCoordinate.x() - (gridWidth / 2);
int topLeftY = tileCoordinate.y() - (gridHeight / 2);
m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
-// qWarning() << __PRETTY_FUNCTION__ << topLeftX << topLeftY << "->"
-// << topLeftX + gridWidth << topLeftY + gridHeight;
-
return QRect(topLeftX, topLeftY, gridWidth, gridHeight);
}
qDebug() << __PRETTY_FUNCTION__;
m_viewTilesGrid = calculateTileGrid(sceneCoordinate);
- QRect tilesSceneRect = updateViewTilesSceneRect();
+ updateViewTilesSceneRect();
int topLeftX = m_viewTilesGrid.topLeft().x();
int topLeftY = m_viewTilesGrid.topLeft().y();
int tileMaxVal = tileMaxValue(m_zoomLevel);
-// qWarning() << __PRETTY_FUNCTION__ << "topleft:" << topLeftX << topLeftY
-// << "bottomright:" << bottomRightX << bottomRightY;
-
for (int x = topLeftX; x <= bottomRightX; ++x) {
for (int y = topLeftY; y <= bottomRightY; ++y) {
int tileX = x;
int tileY = y;
- int requestedX = x;
-
// span in horizontal direction if world limits has been reached
- if (tileX < 0) {
+ if (tileX < 0)
tileX += tileMaxVal + 1;
-// qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
- }
- else if (tileX > tileMaxVal) {
+ else if (tileX > tileMaxVal)
tileX -= tileMaxVal + 1;
-// qWarning() << __PRETTY_FUNCTION__ << "x value:" << requestedX << "->" << tileX;
- }
// map doesn't span in vertical direction
if (tileY < 0 || tileY > tileMaxVal)
continue;
- MapTile *tile;
- if (!(tile = m_mapScene->tileInScene(tilePath(m_zoomLevel, tileX, tileY)))) {
+ if (!m_mapScene->tileInScene(tilePath(m_zoomLevel, tileX, tileY)))
emit fetchImage(m_zoomLevel, tileX, tileY);
- }
- else {
- // tile was already in the scene, maybe it should be moved?
-// qWarning() << __PRETTY_FUNCTION__ << "tile was already in the scene";
-// m_mapScene->spanItem(tile, tilesSceneRect);
- }
}
}
-// m_friendItemsHandler->spanFriendItems(tilesSceneRect);
-
m_mapScene->spanItems(m_scrollDirection);
}
void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image)
{
- qDebug() << __PRETTY_FUNCTION__ << "x:" << x << "y:" << y;
+ qDebug() << __PRETTY_FUNCTION__;
QString hashKey = tilePath(zoomLevel, x, y);
if (!m_mapScene->tileInScene(hashKey)) {
m_mapScene->enqueueRemoveStackedTiles(mapTile);
}
else {
- qCritical() << __PRETTY_FUNCTION__ << "WARNING: Received tile which already is in the scene";
+ qCritical() << __PRETTY_FUNCTION__ << "CRITICAL: Received tile which already is in the scene";
}
}
void MapEngine::setLocation(QPoint sceneCoordinate)
{
- qWarning() << __PRETTY_FUNCTION__ << "X:" << sceneCoordinate.x();
+ qWarning() << __PRETTY_FUNCTION__;
- if (sceneCoordinate.x() < 0) {
-// qWarning() << __PRETTY_FUNCTION__ << "World west limit reached";
+ // jump to opposite side of the world if world limit is exceeded
+ if (sceneCoordinate.x() < 0)
sceneCoordinate.setX(sceneCoordinate.x() + WORLD_PIXELS_X);
- }
- else if (sceneCoordinate.x() > WORLD_PIXELS_X - 1) {
-// qWarning() << __PRETTY_FUNCTION__ << "World east limit reached";
+ else if (sceneCoordinate.x() > WORLD_PIXELS_X - 1)
sceneCoordinate.setX(sceneCoordinate.x() - WORLD_PIXELS_X);
- }
if (sceneCoordinate.x() > m_sceneCoordinate.x())
m_scrollDirection = SCROLL_EAST;
return tilePathString;
}
-QRect MapEngine::updateViewTilesSceneRect()
+void MapEngine::updateViewTilesSceneRect()
{
qDebug() << __PRETTY_FUNCTION__;
QPoint bottomRight = convertTileNumberToSceneCoordinate(m_zoomLevel,
m_viewTilesGrid.bottomRight()
+ ONE_TILE) - ONE_PIXEL;
- QRect rect(topLeft, bottomRight);
- m_mapScene->viewRectUpdated(rect);
- return rect;
+ m_mapScene->viewRectUpdated(QRect(topLeft, bottomRight));
}
void MapEngine::viewResized(const QSize &size)
*
* Calculates tiles rect in scene based on m_viewTilesGrid and
* calls MapScene::viewRectUpdated()
- *
- * @return New tiles scene rect
*/
- QRect updateViewTilesSceneRect();
+ void updateViewTilesSceneRect();
void zoomed();
qDebug() << __PRETTY_FUNCTION__;
m_mapTilesInScene.insert(hashKey, mapTile);
- setTilePosition(mapTile);
addItem(mapTile);
}
setSceneRect(rect);
}
-void MapScene::setTilePosition(MapTile *tile)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- const int maxTileNumber = (1 << tile->zoomLevel()) - 1;
-
- if ((tile->zoomLevel() >= MIN_MAP_ZOOM_LEVEL) && (tile->zoomLevel() <= MAX_MAP_ZOOM_LEVEL)
- && (tile->tileNumber().x() >= 0) && (tile->tileNumber().x() <= maxTileNumber)
- && (tile->tileNumber().y() >= 0) && (tile->tileNumber().y() <= maxTileNumber)) {
-
- tile->setPos(MapEngine::convertTileNumberToSceneCoordinate(tile->zoomLevel(),
- tile->tileNumber()));
- }
- else {
- tile->setPos(UNDEFINED, UNDEFINED);
- qCritical() << __PRETTY_FUNCTION__ << "Tile position is undefined";
- }
-}
-
void MapScene::setTilesDrawingLevels(int zoomLevel)
{
qDebug() << __PRETTY_FUNCTION__ << "zoomLevel:" << zoomLevel;
}
}
-void MapScene::spanItem(QGraphicsItem *item, QRect tilesSceneRect)
-{
- if (item->pos().x() < tilesSceneRect.left())
- item->moveBy(WORLD_PIXELS_X, 0);
- else if (item->pos().x() > tilesSceneRect.right())
- item->moveBy(-WORLD_PIXELS_X, 0);
-}
-
void MapScene::spanItems(ScrollDirection direction)
{
qDebug() << __PRETTY_FUNCTION__;
QRect spanRect;
int delta;
- qWarning() << __PRETTY_FUNCTION__ << "m_viewRect:" << m_viewRect.topLeft().x()
- << m_viewRect.topLeft().y() << ","
- << m_viewRect.bottomRight().x()
- << m_viewRect.bottomRight().y();
if (direction == SCROLL_WEST) {
spanRect = m_viewRect;
spanRect.setTop(0);
spanRect.setRight(sceneRect().right());
delta = -WORLD_PIXELS_X;
}
- else { // if (m_viewRect.right() > WORLD_PIXELS_X - 1) {
+ else {
spanRect = m_viewRect;
spanRect.setTop(0);
spanRect.setBottom(WORLD_PIXELS_Y);
if (!spanRect.isNull()) {
/// @todo ADD TRANSFORM PARAMETER
QList<QGraphicsItem *> spanItems = items(spanRect, Qt::IntersectsItemShape, Qt::DescendingOrder);
- qWarning() << __PRETTY_FUNCTION__ << "spanItems count:" << spanItems.count();
- qWarning() << __PRETTY_FUNCTION__ << "spanRect:" << spanRect.topLeft().x()
- << spanRect.topLeft().y() << ","
- << spanRect.bottomRight().x()
- << spanRect.bottomRight().y();
+
foreach (QGraphicsItem *item, spanItems) {
item->moveBy(delta, 0);
}
void setSceneVerticalOverlap(int viewHeight, int zoomLevel);
/**
- * @brief Set position of the tile in the MapScene coordinate system
- *
- * Does set the position based on the tiles' m_zoomLevel and m_TileNumber and the current
- * m_viewRect. Position is set to (UNDEFINED, UNDEFINED) if there is something wrong with zoom
- * level or tile numbers. If tile is out of the current view rect, then it is moved to opposite
- * side of the world to make spanning over world limit work.
- */
- void setTilePosition(MapTile *tile);
-
- /**
* @brief Set drawing order of all tiles in the scene
*
* Check MapTile::setSceneLevel for more information.
*/
void setTilesDrawingLevels(int zoomLevel);
- static void spanItem(QGraphicsItem *item, QRect tilesSceneRect);
-
void spanItems(ScrollDirection direction);
/**
qDebug() << __PRETTY_FUNCTION__;
m_zoomLevel = tileZoomLevel;
+ setPosition();
setSceneLevel(currentViewZoomLevel);
qDebug() << __PRETTY_FUNCTION__;
m_tileNumber = tileNumber;
+ setPosition();
}
+
+void MapTile::setPosition()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ const int maxTileNumber = (1 << m_zoomLevel) - 1;
+
+ if ((m_zoomLevel >= MIN_MAP_ZOOM_LEVEL) && (m_zoomLevel <= MAX_MAP_ZOOM_LEVEL)
+ && (m_tileNumber.x() >= 0) && (m_tileNumber.x() <= maxTileNumber)
+ && (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= maxTileNumber))
+
+ setPos(MapEngine::convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber));
+ else
+ setPos(UNDEFINED, UNDEFINED);
+}
+
*/
int zoomLevel();
+private:
+ /**
+ * @brief Set position of the tile in the MapScene coordinate system
+ *
+ * Does set the position based on the m_zoomLevel and the m_TileNumber. Position is set to
+ * (UNDEFINED, UNDEFINED) if there is something wrong with zoom level or tile numbers
+ */
+ void setPosition();
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
#include <QtGui>
#include <QtWebKit>
-#ifdef Q_WS_MAEMO_5
-#include <QtMaemo5/QMaemo5InformationBox>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#endif // Q_WS_MAEMO_5
-
#include "common.h"
#include "facebookservice/facebookauthentication.h"
#include "friendlistpanel.h"
#include "mainwindow.h"
-#include <QtGui/QX11Info>
+#ifdef Q_WS_MAEMO_5
+ #include <QtGui/QX11Info>
+ #include <QtMaemo5/QMaemo5InformationBox>
+ #include <X11/Xatom.h>
+ #include <X11/Xlib.h>
+#endif // Q_WS_MAEMO_5
// values for setting screen size in desktop matching N900 screen size
const int N900_APP_WIDTH = 800;