2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@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,
22 #include "mapviewscreen.h"
23 #include "map/mapview.h"
24 #include "panelcommon.h"
25 #include "panelsidebar.h"
27 MapViewScreen::MapViewScreen(QWidget *parent)
29 m_autoCenteringEnabled(false)
31 MapView *mapView = new MapView(this);
32 m_mapEngine = new MapEngine(this);
33 mapView->setScene(m_mapEngine->scene());
35 m_friendsListPanel = new FriendListPanel(this);
36 m_userPanel = new UserInfoPanel(this);
37 PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
38 PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
40 m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
41 ZOOM_BUTTON_PANEL_POSITION_Y);
43 m_ownLocationCrosshair = 0;
45 connect(mapView, SIGNAL(viewScrolled(QPoint)),
46 m_mapEngine, SLOT(setLocation(QPoint)));
47 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
48 mapView, SLOT(centerToSceneCoordinates(QPoint)));
49 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
50 mapView, SLOT(setZoomLevel(int)));
51 connect(mapView, SIGNAL(viewResized(QSize)),
52 m_mapEngine, SLOT(viewResized(QSize)));
53 connect(mapView, SIGNAL(updateViewContent(QRect)),
54 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
55 connect(mapView, SIGNAL(viewZoomFinished()),
56 m_mapEngine, SLOT(viewZoomFinished()));
58 connect(this, SIGNAL(zoomInKeyPressed()),
59 m_mapEngine, SLOT(zoomIn()));
60 connect(this, SIGNAL(zoomOutKeyPressed()),
61 m_mapEngine, SLOT(zoomOut()));
63 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
64 this, SLOT(drawOsmLicense(int, int)));
65 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
66 m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
67 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
68 m_userPanel, SLOT(reDrawUserPanel(int, int)));
69 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
70 friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
72 connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
73 m_mapEngine, SLOT(zoomIn()));
74 connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
75 m_mapEngine, SLOT(zoomOut()));
77 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
78 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
79 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
80 m_mapEngine, SLOT(setViewLocation(QPointF)));
82 connect(this, SIGNAL(userLocationReady(User*)),
83 m_mapEngine, SLOT(receiveOwnLocation(User*)));
84 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
85 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
87 connect(m_mapEngine, SIGNAL(mapScrolled()),
88 this, SLOT(locationChanged()));
90 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
91 this, SLOT(drawOwnLocationCrosshair(int, int)));
93 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
94 this, SLOT(setViewPortSize(int, int)));
96 connect(m_mapEngine, SIGNAL(requestToGetViewPortContents()),
97 mapView, SLOT(viewportContent()));
98 connect(mapView, SIGNAL(updateViewContent(QRect)),
99 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
100 connect(this, SIGNAL(requestOwnLocation()),
101 m_mapEngine, SLOT(ownLocation()));
102 connect(m_mapEngine, SIGNAL(ownLocation(QPointF)),
103 this, SIGNAL(ownLocation(QPointF)));
105 QHBoxLayout *mapViewLayout = new QHBoxLayout;
107 m_osmLicense = new QLabel(this);
108 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
109 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
110 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
111 m_osmLicense->setFont(QFont("Nokia Sans", 9));
112 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
113 m_osmLicense->fontMetrics().height());
115 m_friendsListPanel->stackUnder(friendsListPanelSidebar);
116 userPanelSidebar->stackUnder(m_friendsListPanel);
117 m_userPanel->stackUnder(userPanelSidebar);
118 m_zoomButtonPanel->stackUnder(m_userPanel);
119 m_osmLicense->stackUnder(m_zoomButtonPanel);
120 mapView->stackUnder(m_osmLicense);
122 mapViewLayout->addWidget(mapView);
123 setLayout(mapViewLayout);
125 mapViewLayout->setMargin(0);
129 setObjectName("Map view");
132 void MapViewScreen::drawOsmLicense(int width, int height)
134 qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
135 m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
136 height - m_osmLicense->fontMetrics().height());
139 void MapViewScreen::locationChanged()
141 qDebug() << __PRETTY_FUNCTION__;
143 if (m_autoCenteringEnabled)
144 emit mapLocationChanged();
147 void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
149 qDebug() << __PRETTY_FUNCTION__;
151 if (m_autoCenteringEnabled)
152 m_mapEngine->setViewLocation(position);
155 void MapViewScreen::enableAutoCentering(bool enabled)
157 qDebug() << __PRETTY_FUNCTION__;
159 m_autoCenteringEnabled = enabled;
160 m_mapEngine->setAutoCentering(enabled);
163 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
165 qDebug() << __PRETTY_FUNCTION__;
167 if (m_drawOwnLocationCrosshair) {
168 m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
169 height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
173 void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
175 if (visibility == false) {
177 if (m_ownLocationCrosshair == 0) {
178 m_ownLocationCrosshair = new QLabel(this);
179 QPixmap crosshairImage(":/res/images/sight.png");
180 m_ownLocationCrosshair->setPixmap(crosshairImage);
181 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
184 m_ownLocationCrosshair->show();
185 m_drawOwnLocationCrosshair = true;
186 drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
190 m_ownLocationCrosshair->hide();
191 m_drawOwnLocationCrosshair = false;
195 void MapViewScreen::setViewPortSize(int width, int height)
197 m_viewPortWidth = width;
198 m_viewPortHeight = height;