95f5acd330f568810cfd496fa296164c3b883a20
[situare] / src / map / baselocationitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Ville Tiensuu - ville.tiensuu@ixonos.com
6        Sami Rämö - sami.ramo@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <QDebug>
24
25 #include "mapcommon.h"
26
27 #include "baselocationitem.h"
28
29 BaseLocationItem::BaseLocationItem(QObject *parent)
30     : QObject(parent)
31 {
32     qDebug() << __PRETTY_FUNCTION__;
33
34     setFlag(QGraphicsItem::ItemIgnoresTransformations);
35 }
36
37 QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
38 {
39     qDebug() << __PRETTY_FUNCTION__;
40
41     QRect rect = sceneBoundingRect().toRect();
42
43     // returned rect size is size of original image and not scaled to size of currently presented
44     // image because of using ItemIgnoresTransformations flag. Thus the rect must be scaled
45
46     int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
47
48     int heightDelta = (rect.height() * multiplier - rect.height()) / 2;
49     int widthDelta = (rect.width() * multiplier - rect.width()) / 2;
50
51     return rect.adjusted(-widthDelta, -heightDelta, widthDelta, heightDelta);
52 }