Fixed a few merge problems
[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 "panelcommon.h"
26 #include "panelsidebar.h"
27
28 MapViewScreen::MapViewScreen(QWidget *parent)
29    : QWidget(parent),
30      m_autoCenteringEnabled(false)
31 {
32     MapView *mapView = new MapView(this);
33     m_mapEngine = new MapEngine(this);
34     mapView->setScene(m_mapEngine->scene());
35
36     m_friendsListPanel = new FriendListPanel(this);
37     m_userPanel = new UserInfoPanel(this);
38     PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
39     PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
40
41     m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
42                                             ZOOM_BUTTON_PANEL_POSITION_Y);
43
44     connect(mapView, SIGNAL(viewScrolled(QPoint)),
45             m_mapEngine, SLOT(setLocation(QPoint)));
46     connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
47             mapView, SLOT(centerToSceneCoordinates(QPoint)));
48     connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
49             mapView, SLOT(setZoomLevel(int)));
50     connect(mapView, SIGNAL(viewResized(QSize)),
51             m_mapEngine, SLOT(viewResized(QSize)));
52     connect(mapView, SIGNAL(viewContentChanged(QPoint)),
53             m_mapEngine, SLOT(alignImmovableItems(QPoint)));
54     connect(mapView, SIGNAL(viewZoomFinished()),
55             m_mapEngine, SLOT(viewZoomFinished()));
56
57     connect(this, SIGNAL(zoomInKeyPressed()),
58             m_mapEngine, SLOT(zoomIn()));
59     connect(this, SIGNAL(zoomOutKeyPressed()),
60             m_mapEngine, SLOT(zoomOut()));
61
62     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
63             this, SLOT(drawOsmLicense(int, int)));
64     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
65             m_friendsListPanel, SLOT(reDrawFriendsPanel(int,int)));
66     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
67             m_userPanel, SLOT(reDrawUserPanel(int,int)));
68     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
69             friendsListPanelSidebar, SLOT(reDrawSidebar(int,int)));
70
71     connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
72             m_mapEngine, SLOT(zoomIn()));
73     connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
74             m_mapEngine, SLOT(zoomOut()));
75
76     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
77             m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
78     connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
79             m_mapEngine, SLOT(setViewLocation(QPointF)));
80
81     connect(this, SIGNAL(userLocationReady(User*)),
82             m_mapEngine, SLOT(receiveOwnLocation(User*)));
83     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
84             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
85
86     connect(m_mapEngine, SIGNAL(mapScrolled()),
87             this, SLOT(locationChanged()));
88
89     QHBoxLayout *mapViewLayout = new QHBoxLayout;
90
91     m_osmLicense = new QLabel(this);
92     m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
93     m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
94     m_osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
95     m_osmLicense->setFont(QFont("Nokia Sans", 9));
96     m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
97                          m_osmLicense->fontMetrics().height());
98
99     m_friendsListPanel->stackUnder(friendsListPanelSidebar);
100     userPanelSidebar->stackUnder(m_friendsListPanel);
101     m_userPanel->stackUnder(userPanelSidebar);
102     m_zoomButtonPanel->stackUnder(m_userPanel);
103     m_osmLicense->stackUnder(m_zoomButtonPanel);
104     mapView->stackUnder(m_osmLicense);
105
106     mapViewLayout->addWidget(mapView);
107     setLayout(mapViewLayout);
108
109     mapViewLayout->setMargin(0);
110
111     m_mapEngine->init();
112
113     setObjectName("Map view");
114 }
115
116 void MapViewScreen::drawOsmLicense(int width, int height)
117 {
118     qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
119     m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
120                         height - m_osmLicense->fontMetrics().height());
121 }
122
123 void MapViewScreen::locationChanged()
124 {
125     qDebug() << __PRETTY_FUNCTION__;
126
127     if (m_autoCenteringEnabled)
128         emit mapLocationChanged();
129 }
130
131 void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
132 {
133     qDebug() << __PRETTY_FUNCTION__;
134
135     if (m_autoCenteringEnabled)
136         m_mapEngine->setViewLocation(position);
137 }
138
139 void MapViewScreen::enableAutoCentering(bool enabled)
140 {
141     qDebug() << __PRETTY_FUNCTION__;
142
143     m_autoCenteringEnabled = enabled;
144     m_mapEngine->setAutoCentering(enabled);
145 }