2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 #include <QGraphicsScene>
30 * @brief Map scene for storing MapTile items
32 * @author Sami Rämö - sami.ramo (at) ixonos.com
34 class MapScene : public QGraphicsScene
41 * Scene size is set to the amount of pixels on closest zoom level
42 * @param parent Parent
44 MapScene(QObject *parent = 0);
46 /*******************************************************************************
47 * MEMBER FUNCTIONS AND SLOTS
48 ******************************************************************************/
51 * @brief Create and add new MapTile to MapScene
53 * If there is a tile with same parameters already in the scene, it will be removed
54 * before adding the new tile.
56 * @param zoomLevel Zoom level of the new tile
57 * @param tileNumber X & Y indexes of the tile
58 * @param image Map tile picture
59 * @param viewZoomLevel Current view zoom level (for setting the zValue)
61 void addTile(int zoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel);
64 * @brief Enqueue stacked tiles removal request
66 * Removal is triggered after events have been processed so the UI
67 * stays more responsive
68 * @param newTile New tile, which area under it is inspected
70 void enqueueRemoveStackedTiles(MapTile *newTile);
73 * @brief Returns tile mathcing given hash key
76 * @return Returns tile matching given hash key, or 0 if no match found
78 MapTile* tileInScene(QString hashKey);
81 * @brief Remove tiles which are out of view bounds.
84 void removeOutOfViewTiles(QRect tilesGrid, int zoomLevel);
87 * @brief Remove tiles which are stacked.
89 * Iterate through tiles which are under this map tile and remove tiles which
90 * are fully obscured by this new tile. Tiles which are only partially
91 * obscured by this new tile are not checked, and thus deleted, because of
92 * the required complexity of the algorithm and processing power. Those tiles
93 * will be removed when they go out of the view area caused by scrolling or
96 * @param newTile new tile covering old tiles
98 void removeStackedTiles(MapTile *newTile);
101 * @brief Remove tile.
103 * Removes tile from scene and list of current tiles in scene.
104 * @param tile MapTile to remove
106 void removeTile(MapTile *tile);
109 * @brief Set allowed amount of exceeding the world vertical limits
111 * Limit is set so that vertical limits of the world can be scrolled to middle of
114 * @param viewHeight Height of the view
115 * @param zoomLevel Current zoom level
117 void setSceneVerticalOverlap(int viewHeight, int zoomLevel);
120 * @brief Set drawing order of all tiles in the scene
122 * Check MapTile::setSceneLevel for more information.
123 * @param zoomLevel Current zoom level
125 void setTilesDrawingLevels(int zoomLevel);
127 void setTilesGrid(QRect grid);
129 void setZoomLevel(int zoomLevel);
131 void spanItems(int zoomLevel, QPoint sceneCoordinate, QSize viewSize);
134 * @brief Save new tiles scene rect
136 * Tiles scene rect must be saved to local scope whenever it changes because
137 * it is used by removal algorithms and some of the algorithms are run
138 * delayed so the actual tiles scene rect may change before the cleanup
141 * @param tilesSceneRect New view rect
143 void tilesSceneRectUpdated(QRect tilesSceneRect);
147 * @brief Move map items horizontally in the scene (not MapTile items)
149 * MapTile items are not moved!
151 * Move items which intersect the given rect.
153 * @param from Items colliding given rect are moved
154 * @param distance How much to move each item
156 void moveIntersectingItemsHorizontally(QRect from, int distance);
159 void removeOtherLevelTiles();
162 * @brief Slot for running next queued removal of stacked tiles
165 void runNextStackedTilesRemoval();
167 /*******************************************************************************
169 ******************************************************************************/
171 bool m_isRemoveStackedTilesRunning; ///< Is singleshot timer already running
173 QHash<QString, MapTile *> m_mapTilesInScene; ///< List of map tiles in map scene
174 QList<MapTile *> m_removeStackedTilesList; ///< "Queue" for stacked tiles removal requests
175 QRect m_tilesSceneRect; ///< Current viewable area
176 QRect m_viewTilesGrid;