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