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 ownLocationCrosshair = new QLabel(this);
44 QPixmap crosshairImage(":/res/images/sight.png");
45 ownLocationCrosshair->setPixmap(crosshairImage);
46 ownLocationCrosshair->setFixedSize(crosshairImage.size());
47 ownLocationCrosshair->hide();
49 connect(mapView, SIGNAL(viewScrolled(QPoint)),
50 m_mapEngine, SLOT(setLocation(QPoint)));
51 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
52 mapView, SLOT(centerToSceneCoordinates(QPoint)));
53 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
54 mapView, SLOT(setZoomLevel(int)));
55 connect(mapView, SIGNAL(viewResized(QSize)),
56 m_mapEngine, SLOT(viewResized(QSize)));
57 // connect(mapView, SIGNAL(viewContentChanged(QRect)),
58 // m_mapEngine, SLOT(alignImmovableItems(QRect)));
59 connect(mapView, SIGNAL(updateViewContent(QRect)),
60 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
61 connect(mapView, SIGNAL(viewZoomFinished()),
62 m_mapEngine, SLOT(viewZoomFinished()));
64 connect(this, SIGNAL(zoomInKeyPressed()),
65 m_mapEngine, SLOT(zoomIn()));
66 connect(this, SIGNAL(zoomOutKeyPressed()),
67 m_mapEngine, SLOT(zoomOut()));
69 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
70 this, SLOT(drawOsmLicense(int, int)));
71 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
72 m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
73 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
74 m_userPanel, SLOT(reDrawUserPanel(int, int)));
75 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
76 friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
78 connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
79 m_mapEngine, SLOT(zoomIn()));
80 connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
81 m_mapEngine, SLOT(zoomOut()));
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(friendsLocationsReady(QList<User*>&)),
91 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
93 connect(m_mapEngine, SIGNAL(mapScrolled()),
94 this, SLOT(locationChanged()));
96 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
97 this, SLOT(drawOwnLocationCrosshair(int, int)));
99 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
100 this, SLOT(setViewPortSize(int, int)));
102 connect(m_mapEngine, SIGNAL(requestToGetViewPortContents()),
103 mapView, SLOT(viewportContent()));
104 connect(mapView, SIGNAL(viewContentChanged(QRect)),
105 m_mapEngine, SLOT(receiveViewSceneRect(QRect)));
106 connect(this, SIGNAL(requestOwnLocation()),
107 m_mapEngine, SLOT(ownLocation()));
108 connect(m_mapEngine, SIGNAL(ownLocation(QPointF)),
109 this, SIGNAL(ownLocation(QPointF)));
111 QHBoxLayout *mapViewLayout = new QHBoxLayout;
113 m_osmLicense = new QLabel(this);
114 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
115 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
116 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
117 m_osmLicense->setFont(QFont("Nokia Sans", 9));
118 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
119 m_osmLicense->fontMetrics().height());
121 m_friendsListPanel->stackUnder(friendsListPanelSidebar);
122 userPanelSidebar->stackUnder(m_friendsListPanel);
123 m_userPanel->stackUnder(userPanelSidebar);
124 m_zoomButtonPanel->stackUnder(m_userPanel);
125 m_osmLicense->stackUnder(m_zoomButtonPanel);
126 mapView->stackUnder(m_osmLicense);
128 mapViewLayout->addWidget(mapView);
129 setLayout(mapViewLayout);
131 mapViewLayout->setMargin(0);
135 setObjectName("Map view");
138 void MapViewScreen::drawOsmLicense(int width, int height)
140 qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
141 m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
142 height - m_osmLicense->fontMetrics().height());
145 void MapViewScreen::locationChanged()
147 qDebug() << __PRETTY_FUNCTION__;
149 if (m_autoCenteringEnabled)
150 emit mapLocationChanged();
153 void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
155 qDebug() << __PRETTY_FUNCTION__;
157 if (m_autoCenteringEnabled)
158 m_mapEngine->setViewLocation(position);
161 void MapViewScreen::enableAutoCentering(bool enabled)
163 qDebug() << __PRETTY_FUNCTION__;
165 m_autoCenteringEnabled = enabled;
166 m_mapEngine->setAutoCentering(enabled);
169 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
171 qWarning() << __PRETTY_FUNCTION__;
172 qWarning() << "widht: " << width << "height: " << height;
174 if (m_drawOwnLocationCrosshair) {
175 ownLocationCrosshair->move(width/2 - ownLocationCrosshair->pixmap()->width()/2,
176 height/2 - ownLocationCrosshair->pixmap()->height()/2);
179 qWarning() << "ownLocation test: " << m_mapEngine->ownLocation().x()
180 << m_mapEngine->ownLocation().y();
184 void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
186 if (visibility == false) {
187 ownLocationCrosshair->show();
188 m_drawOwnLocationCrosshair = true;
189 drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
193 ownLocationCrosshair->hide();
194 m_drawOwnLocationCrosshair = false;
198 void MapViewScreen::setViewPortSize(int width, int height)
200 m_viewPortWidth = width;
201 m_viewPortHeight = height;