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)
30 MapView *mapView = new MapView(this);
31 m_mapEngine = new MapEngine(this);
32 mapView->setScene(m_mapEngine->scene());
34 m_friendsListPanel = new FriendListPanel(this);
35 m_userPanel = new UserInfoPanel(this);
36 PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
37 PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
39 m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
40 ZOOM_BUTTON_PANEL_POSITION_Y);
42 m_ownLocationCrosshair = 0;
44 connect(mapView, SIGNAL(viewScrolled(QPoint)),
45 m_mapEngine, SLOT(setLocation(QPoint)));
46 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
47 mapView, SLOT(centerToSceneCoordinates(QPoint)));
48 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
49 mapView, SLOT(setZoomLevel(int)));
50 connect(mapView, SIGNAL(viewResized(QSize)),
51 m_mapEngine, SLOT(viewResized(QSize)));
52 connect(mapView, SIGNAL(updateViewContent(QRect)),
53 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
54 connect(mapView, SIGNAL(viewZoomFinished()),
55 m_mapEngine, SLOT(viewZoomFinished()));
57 connect(this, SIGNAL(zoomInKeyPressed()),
58 m_mapEngine, SLOT(zoomIn()));
59 connect(this, SIGNAL(zoomOutKeyPressed()),
60 m_mapEngine, SLOT(zoomOut()));
62 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
63 this, SLOT(drawOsmLicense(int, int)));
64 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
65 m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
66 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
67 m_userPanel, SLOT(reDrawUserPanel(int, int)));
68 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
69 friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
71 connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
72 m_mapEngine, SLOT(zoomIn()));
73 connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
74 m_mapEngine, SLOT(zoomOut()));
75 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
76 m_zoomButtonPanel, SLOT(resetButtons()));
77 connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
78 m_zoomButtonPanel, SLOT(disableZoomInButton()));
79 connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
80 m_zoomButtonPanel, SLOT(disableZoomOutButton()));
82 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
83 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
84 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
85 m_mapEngine, SLOT(setViewLocation(QPointF)));
87 connect(this, SIGNAL(userLocationReady(User*)),
88 m_mapEngine, SLOT(receiveOwnLocation(User*)));
89 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
90 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
92 connect(m_mapEngine, SIGNAL(mapScrolledManually()),
93 this, SIGNAL(mapLocationChanged()));
95 connect(this, SIGNAL(positionReceived(QPointF,qreal)),
96 m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
97 connect(this, SIGNAL(enableAutoCentering(bool)),
98 m_mapEngine, SLOT(setAutoCentering(bool)));
99 connect(this, SIGNAL(gpsEnabled(bool)),
100 m_mapEngine, SLOT(gpsEnabled(bool)));
102 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
103 this, SLOT(drawOwnLocationCrosshair(int, int)));
105 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
106 this, SLOT(setViewPortSize(int, int)));
108 connect(m_mapEngine, SIGNAL(requestToGetViewPortContents()),
109 mapView, SLOT(viewportContent()));
110 connect(mapView, SIGNAL(updateViewContent(QRect)),
111 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
112 connect(this, SIGNAL(requestOwnLocation()),
113 m_mapEngine, SLOT(ownLocation()));
114 connect(m_mapEngine, SIGNAL(ownLocation(QPointF)),
115 this, SIGNAL(ownLocation(QPointF)));
117 QHBoxLayout *mapViewLayout = new QHBoxLayout;
119 m_osmLicense = new QLabel(this);
120 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
121 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
122 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
123 m_osmLicense->setFont(QFont("Nokia Sans", 9));
124 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
125 m_osmLicense->fontMetrics().height());
127 m_friendsListPanel->stackUnder(friendsListPanelSidebar);
128 userPanelSidebar->stackUnder(m_friendsListPanel);
129 m_userPanel->stackUnder(userPanelSidebar);
130 m_zoomButtonPanel->stackUnder(m_userPanel);
131 m_osmLicense->stackUnder(m_zoomButtonPanel);
132 mapView->stackUnder(m_osmLicense);
134 mapViewLayout->addWidget(mapView);
135 setLayout(mapViewLayout);
137 mapViewLayout->setMargin(0);
141 setObjectName("Map view");
144 void MapViewScreen::drawOsmLicense(int width, int height)
146 qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
147 m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
148 height - m_osmLicense->fontMetrics().height());
152 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
154 qDebug() << __PRETTY_FUNCTION__;
156 if (m_drawOwnLocationCrosshair) {
157 m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
158 height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
162 void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
164 if (visibility == false) {
166 if (m_ownLocationCrosshair == 0) {
167 m_ownLocationCrosshair = new QLabel(this);
168 QPixmap crosshairImage(":/res/images/sight.png");
169 m_ownLocationCrosshair->setPixmap(crosshairImage);
170 m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
173 m_ownLocationCrosshair->show();
174 m_drawOwnLocationCrosshair = true;
175 drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
179 m_ownLocationCrosshair->hide();
180 m_drawOwnLocationCrosshair = false;
184 void MapViewScreen::setViewPortSize(int width, int height)
186 m_viewPortWidth = width;
187 m_viewPortHeight = height;