Merge branch 'master' of https://vcs.maemo.org/git/situare
[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 {
30     MapView *mapView = new MapView(this);
31     m_mapEngine = new MapEngine(this);
32     mapView->setScene(m_mapEngine->scene());
33
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);
38
39     m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
40                                             ZOOM_BUTTON_PANEL_POSITION_Y);
41
42     connect(mapView, SIGNAL(viewScrolled(QPoint)),
43             m_mapEngine, SLOT(setLocation(QPoint)));
44     connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
45             mapView, SLOT(centerToSceneCoordinates(QPoint)));
46     connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
47             mapView, SLOT(setZoomLevel(int)));
48     connect(mapView, SIGNAL(viewResized(QSize)),
49             m_mapEngine, SLOT(viewResized(QSize)));
50     connect(mapView, SIGNAL(viewZoomFinished()),
51             m_mapEngine, SLOT(viewZoomFinished()));
52
53     connect(this, SIGNAL(zoomInKeyPressed()),
54             m_mapEngine, SLOT(zoomIn()));
55     connect(this, SIGNAL(zoomOutKeyPressed()),
56             m_mapEngine, SLOT(zoomOut()));
57
58     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
59             this, SLOT(drawOsmLicense(int, int)));
60     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
61             m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
62     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
63             m_userPanel, SLOT(reDrawUserPanel(int, int)));
64     connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
65             friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
66
67     connect(m_zoomButtonPanel->m_zoomInButton, SIGNAL(clicked()),
68             m_mapEngine, SLOT(zoomIn()));
69     connect(m_zoomButtonPanel->m_zoomOutButton, SIGNAL(clicked()),
70             m_mapEngine, SLOT(zoomOut()));
71     connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
72             m_zoomButtonPanel, SLOT(resetButtons()));
73     connect(m_mapEngine, SIGNAL(maxZoomLevelReached()),
74             m_zoomButtonPanel, SLOT(disableZoomInButton()));
75     connect(m_mapEngine, SIGNAL(minZoomLevelReached()),
76             m_zoomButtonPanel, SLOT(disableZoomOutButton()));
77
78     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
79             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
80     connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
81             m_mapEngine, SLOT(setViewLocation(QPointF)));
82
83     connect(this, SIGNAL(userLocationReady(User*)),
84             m_mapEngine, SLOT(receiveOwnLocation(User*)));
85     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
86             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
87
88     connect(m_mapEngine, SIGNAL(mapScrolledManually()),
89             this, SIGNAL(mapLocationChanged()));
90
91     connect(this, SIGNAL(positionReceived(QPointF,qreal)),
92             m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
93     connect(this, SIGNAL(enableAutoCentering(bool)),
94             m_mapEngine, SLOT(setAutoCentering(bool)));
95     connect(this, SIGNAL(gpsEnabled(bool)),
96             m_mapEngine, SLOT(gpsEnabled(bool)));
97
98     QHBoxLayout *mapViewLayout = new QHBoxLayout;
99
100     m_osmLicense = new QLabel(this);
101     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
102     m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
103     m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
104     m_osmLicense->setFont(QFont("Nokia Sans", 9));
105     m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
106                          m_osmLicense->fontMetrics().height());
107
108     m_friendsListPanel->stackUnder(friendsListPanelSidebar);
109     userPanelSidebar->stackUnder(m_friendsListPanel);
110     m_userPanel->stackUnder(userPanelSidebar);
111     m_zoomButtonPanel->stackUnder(m_userPanel);
112     m_osmLicense->stackUnder(m_zoomButtonPanel);
113     mapView->stackUnder(m_osmLicense);
114
115     mapViewLayout->addWidget(mapView);
116     setLayout(mapViewLayout);
117
118     mapViewLayout->setMargin(0);
119
120     m_mapEngine->init();
121
122     setObjectName("Map view");
123 }
124
125 void MapViewScreen::drawOsmLicense(int width, int height)
126 {
127     qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
128     m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
129                         height - m_osmLicense->fontMetrics().height());
130 }
131