Modified GPS & map related signals and slots
[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 "../map/mapengine.h"
25 #include "friendlistpanel.h"
26 #include "userpanel.h"
27 #include "panelcommon.h"
28
29 #include "panelsidebar.h"
30
31 MapViewScreen::MapViewScreen(QWidget *parent)
32    : QWidget(parent)
33 {
34     MapView *mapView = new MapView(this);
35     mapEngine = new MapEngine(this);
36     mapView->setScene(mapEngine->scene());
37
38     FriendListPanel *friendsListPanel = new FriendListPanel(this);
39     UserInfoPanel *userPanel = new UserInfoPanel(this);
40     PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
41     PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
42
43     connect(mapView, SIGNAL(viewScrolled(QPoint)),
44             mapEngine, SLOT(setLocation(QPoint)));
45     connect(mapEngine, SIGNAL(locationChanged(QPoint)),
46             mapView, SLOT(centerToSceneCoordinates(QPoint)));
47     connect(mapEngine, SIGNAL(zoomLevelChanged(int)),
48             mapView, SLOT(setZoomLevel(int)));
49     connect(mapView, SIGNAL(viewResized(QSize)),
50             mapEngine, SLOT(viewResized(QSize)));
51     connect(mapView, SIGNAL(viewContentChanged(QPoint)),
52             mapEngine, SLOT(alignImmovableItems(QPoint)));
53     connect(mapView, SIGNAL(viewZoomFinished()),
54             mapEngine, SLOT(viewZoomFinished()));
55
56     connect(this, SIGNAL(zoomInKeyPressed()),
57             mapEngine, SLOT(zoomIn()));
58     connect(this, SIGNAL(zoomOutKeyPressed()),
59             mapEngine, SLOT(zoomOut()));
60
61     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
62             this, SLOT(drawOsmLicense(int, int)));
63
64     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
65             friendsListPanel, SLOT(reDrawFriendsPanel(int,int)));
66     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
67             userPanel, SLOT(reDrawUserPanel(int,int)));
68     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
69             friendsListPanelSidebar, SLOT(reDrawSidebar(int,int)));
70
71     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
72             friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
73     connect(friendsListPanel, SIGNAL(findFriend(QPointF)),
74             mapEngine, SLOT(setViewLocation(QPointF)));
75
76     connect(this, SIGNAL(userLocationReady(User*)),
77             mapEngine, SLOT(receiveOwnLocation(User*)));
78     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
79             mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
80
81     connect(mapEngine, SIGNAL(mapScrolledManually()),
82             this, SIGNAL(mapLocationChanged()));
83
84     connect(this, SIGNAL(positionReceived(QPointF,qreal)),
85             mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
86     connect(this, SIGNAL(enableAutoCentering(bool)),
87             mapEngine, SLOT(setAutoCentering(bool)));
88
89     QHBoxLayout *mapViewLayout = new QHBoxLayout;
90
91     osmLicense = new QLabel(this);
92     osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
93     osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
94     osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
95     osmLicense->setFont(QFont("Nokia Sans", 9));
96     osmLicense->resize(osmLicense->fontMetrics().width(OSM_LICENSE),
97                        osmLicense->fontMetrics().height());
98
99     friendsListPanel->stackUnder(friendsListPanelSidebar);
100     userPanelSidebar->stackUnder(friendsListPanel);
101     userPanel->stackUnder(userPanelSidebar);
102     osmLicense->stackUnder(userPanel);
103     mapView->stackUnder(osmLicense);
104
105     mapViewLayout->addWidget(mapView);
106     setLayout(mapViewLayout);
107
108     mapViewLayout->setMargin(0);
109
110     mapEngine->init();
111
112     setObjectName("Map view");
113 }
114
115 void MapViewScreen::drawOsmLicense(int width, int height)
116 {
117     qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
118     osmLicense->move(width - osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
119                      height - osmLicense->fontMetrics().height());
120 }