fixed dogygen documentetion on mapEngine.
[situare] / src / ui / mapviewscreen.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Kaj Wallin - kaj.wallin@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include "mapviewscreen.h"
23 #include "map/mapview.h"
24 #include "panelcommon.h"
25 #include "panelsidebar.h"
26
27 MapViewScreen::MapViewScreen(QWidget *parent)
28    : QWidget(parent),
29      m_drawOwnLocationCrosshair(false)
30 {
31     MapView *mapView = new MapView(this);
32     m_mapEngine = new MapEngine(this);
33     mapView->setScene(m_mapEngine->scene());
34
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);
39
40     m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
41                                             ZOOM_BUTTON_PANEL_POSITION_Y);   
42
43     m_ownLocationCrosshair = 0;
44
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()));
57
58     connect(this, SIGNAL(zoomInKeyPressed()),
59             m_mapEngine, SLOT(zoomIn()));
60     connect(this, SIGNAL(zoomOutKeyPressed()),
61             m_mapEngine, SLOT(zoomOut()));
62
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)));
71
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()));
82
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)));
87
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*>&)));
94
95     connect(m_mapEngine, SIGNAL(mapScrolledManually()),
96             this, SIGNAL(mapLocationChanged()));
97
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)));
104
105     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
106             this, SLOT(drawOwnLocationCrosshair(int, int)));
107
108     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
109              this, SLOT(setViewPortSize(int, int)));
110
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)));
119
120     connect(this, SIGNAL(userLocationReady(User*)),
121             m_userPanel, SLOT(userDataReceived(User*)));
122
123     connect(m_userPanel, SIGNAL(requestReverseGeo()),
124             this, SIGNAL(requestReverseGeo()));
125
126     connect(this, SIGNAL(reverseGeoReady(QString)),
127             m_userPanel, SIGNAL(reverseGeoReady(QString)));
128
129     connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
130             this, SIGNAL(statusUpdate(QString,bool)));
131
132     connect(m_userPanel, SIGNAL(refreshUserData()),
133             this, SIGNAL(refreshUserData()));
134
135     QHBoxLayout *mapViewLayout = new QHBoxLayout;
136
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());
144
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();
150
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);
158
159     mapViewLayout->addWidget(mapView);
160     setLayout(mapViewLayout);
161
162     mapViewLayout->setMargin(0);
163
164     m_mapEngine->init();
165
166     setObjectName("Map view");
167 }
168
169 void MapViewScreen::drawOsmLicense(int width, int height)
170 {
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());
174 }
175
176
177 void MapViewScreen::drawOwnLocationCrosshair(int width, int height)
178 {
179     qDebug() << __PRETTY_FUNCTION__;
180
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);
184     }
185 }
186
187 void MapViewScreen::setOwnLocationCrosshairVisibility(bool visibility)
188 {   
189     if (visibility == false) {
190         m_ownLocationCrosshair->show();
191         m_drawOwnLocationCrosshair = true;
192         drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
193     }
194
195     else {
196         m_ownLocationCrosshair->hide();
197         m_drawOwnLocationCrosshair = false;
198     }
199 }
200
201 void MapViewScreen::setViewPortSize(int width, int height)
202 {
203     m_viewPortWidth = width;
204     m_viewPortHeight = height;
205 }