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_drawOwnLocationCrosshair(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_zoomInButton, SIGNAL(clicked()),
73 m_mapEngine, SLOT(zoomIn()));
74 connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
75 m_mapEngine, SLOT(zoomOut()));
76 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
77 m_zoomButtonPanel, SLOT(resetButtons()));
78 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
79 m_zoomButtonPanel, SLOT(disableZoomInButton()));
80 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
81 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
83 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
84 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
85 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
86 m_mapEngine, SLOT(setViewLocation(QPointF)));
88 connect(this, SIGNAL(userLocationReady(User*)),
89 m_mapEngine, SLOT(receiveOwnLocation(User*)));
90 connect(this, SIGNAL(userLocationReady(User*)),
91 m_mapEngine, SLOT(receiveOwnLocation(User*)));
92 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
93 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
95 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
96 this, SIGNAL(mapLocationChanged()));
98 connect(this, SIGNAL(positionReceived(QPointF,qreal)),
99 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
100 connect(this, SIGNAL(enableAutoCentering(bool)),
101 m_mapEngine, SLOT(setAutoCentering(bool)));
102 connect(this, SIGNAL(gpsEnabled(bool)),
103 m_mapEngine, SLOT(gpsEnabled(bool)));
105 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
106 this, SLOT(drawOwnLocationCrosshair(int, int)));
108 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
109 this, SLOT(setViewPortSize(int, int)));
111 connect(m_mapEngine, SIGNAL(requestToGetViewPortContents()),
112 mapView, SLOT(viewportContent()));
113 connect(mapView, SIGNAL(updateViewContent(QRect)),
114 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
115 connect(this, SIGNAL(requestOwnLocation()),
116 m_mapEngine, SLOT(ownLocation()));
117 connect(m_mapEngine, SIGNAL(ownLocation(QPointF)),
118 this, SIGNAL(ownLocation(QPointF)));
120 connect(this, SIGNAL(userLocationReady(User*)),
121 m_userPanel, SLOT(userDataReceived(User*)));
123 connect(m_userPanel, SIGNAL(requestReverseGeo()),
124 this, SIGNAL(requestReverseGeo()));
126 connect(this, SIGNAL(reverseGeoReady(QString)),
127 m_userPanel, SIGNAL(reverseGeoReady(QString)));
129 connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
130 this, SIGNAL(statusUpdate(QString,bool)));
132 connect(m_userPanel, SIGNAL(refreshUserData()),
133 this, SIGNAL(refreshUserData()));
135 QHBoxLayout *mapViewLayout = new QHBoxLayout;
137 m_osmLicense = new QLabel(this);
138 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
139 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
140 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
141 m_osmLicense->setFont(QFont("Nokia Sans", 9));
142 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
143 m_osmLicense->fontMetrics().height());
145 m_ownLocationCrosshair = new QLabel(this);
146 QPixmap crosshairImage(":/res/images/sight.png");
147 m_ownLocationCrosshair->setPixmap(crosshairImage);
148 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
149 m_ownLocationCrosshair->hide();
151 m_friendsListPanel->stackUnder(friendsListPanelSidebar);
152 userPanelSidebar->stackUnder(m_friendsListPanel);
153 m_userPanel->stackUnder(userPanelSidebar);
154 m_zoomButtonPanel->stackUnder(m_userPanel);
155 m_osmLicense->stackUnder(m_zoomButtonPanel);
156 m_ownLocationCrosshair->stackUnder(m_osmLicense);
157 mapView->stackUnder(m_ownLocationCrosshair);
159 mapViewLayout->addWidget(mapView);
160 setLayout(mapViewLayout);
162 mapViewLayout->setMargin(0);
166 setObjectName("Map view");
169 void MapViewScreen::drawOsmLicense(int width, int height)
171 qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
172 m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
173 height - m_osmLicense->fontMetrics().height());
177 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
179 qDebug() << __PRETTY_FUNCTION__;
181 if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
182 m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
183 height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
187 void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
189 if (visibility == false) {
190 m_ownLocationCrosshair->show();
191 m_drawOwnLocationCrosshair = true;
192 drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
196 m_ownLocationCrosshair->hide();
197 m_drawOwnLocationCrosshair = false;
201 void MapViewScreen::setViewPortSize(int width, int height)
203 m_viewPortWidth = width;
204 m_viewPortHeight = height;