2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Kaj Wallin - kaj.wallin@ixonos.com
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.
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.
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,
22 #include "mapviewscreen.h"
23 #include "map/mapview.h"
24 #include "panelcommon.h"
25 #include "panelsidebar.h"
27 MapViewScreen::MapViewScreen(QWidget *parent)
29 m_autoCenteringEnabled(false)
31 MapView *mapView = new MapView(this);
32 m_mapEngine = new MapEngine(this);
33 mapView->setScene(m_mapEngine->scene());
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);
40 m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
41 ZOOM_BUTTON_PANEL_POSITION_Y);
43 connect(mapView, SIGNAL(viewScrolled(QPoint)),
44 m_mapEngine, SLOT(setLocation(QPoint)));
45 connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
46 mapView, SLOT(centerToSceneCoordinates(QPoint)));
47 connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
48 mapView, SLOT(setZoomLevel(int)));
49 connect(mapView, SIGNAL(viewResized(QSize)),
50 m_mapEngine, SLOT(viewResized(QSize)));
51 connect(mapView, SIGNAL(viewContentChanged(QPoint)),
52 m_mapEngine, SLOT(alignImmovableItems(QPoint)));
53 connect(mapView, SIGNAL(viewZoomFinished()),
54 m_mapEngine, SLOT(viewZoomFinished()));
56 connect(this, SIGNAL(zoomInKeyPressed()),
57 m_mapEngine, SLOT(zoomIn()));
58 connect(this, SIGNAL(zoomOutKeyPressed()),
59 m_mapEngine, SLOT(zoomOut()));
61 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
62 this, SLOT(drawOsmLicense(int, int)));
63 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
64 m_friendsListPanel, SLOT(reDrawFriendsPanel(int, int)));
65 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
66 m_userPanel, SLOT(reDrawUserPanel(int, int)));
67 connect(mapView, SIGNAL(viewResizedNewSize(int, int)),
68 friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
70 connect(m_zoomButtonPanel->m_zoomInBtn, SIGNAL(clicked()),
71 m_mapEngine, SLOT(zoomIn()));
72 connect(m_zoomButtonPanel->m_zoomOutBtn, SIGNAL(clicked()),
73 m_mapEngine, SLOT(zoomOut()));
75 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
76 m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
77 connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
78 m_mapEngine, SLOT(setViewLocation(QPointF)));
80 connect(this, SIGNAL(userLocationReady(User*)),
81 m_mapEngine, SLOT(receiveOwnLocation(User*)));
82 connect(this, SIGNAL(userLocationReady(User*)),
83 m_mapEngine, SLOT(receiveOwnLocation(User*)));
84 connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
85 m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
87 connect(m_mapEngine, SIGNAL(mapScrolled()),
88 this, SLOT(locationChanged()));
90 connect(this, SIGNAL(userLocationReady(User*)),
91 m_userPanel, SLOT(receiveUserData(User*)));
93 QHBoxLayout *mapViewLayout = new QHBoxLayout;
95 m_osmLicense = new QLabel(this);
96 m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
97 m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
98 m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
99 m_osmLicense->setFont(QFont("Nokia Sans", 9));
100 m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
101 m_osmLicense->fontMetrics().height());
103 m_friendsListPanel->stackUnder(friendsListPanelSidebar);
104 userPanelSidebar->stackUnder(m_friendsListPanel);
105 m_userPanel->stackUnder(userPanelSidebar);
106 m_zoomButtonPanel->stackUnder(m_userPanel);
107 m_osmLicense->stackUnder(m_zoomButtonPanel);
108 mapView->stackUnder(m_osmLicense);
110 mapViewLayout->addWidget(mapView);
111 setLayout(mapViewLayout);
113 mapViewLayout->setMargin(0);
117 setObjectName("Map view");
120 void MapViewScreen::drawOsmLicense(int width, int height)
122 qDebug() << __PRETTY_FUNCTION__ << width << "x" << height;
123 m_osmLicense->move(width - m_osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
124 height - m_osmLicense->fontMetrics().height());
127 void MapViewScreen::locationChanged()
129 qDebug() << __PRETTY_FUNCTION__;
131 if (m_autoCenteringEnabled)
132 emit mapLocationChanged();
135 void MapViewScreen::positionReceived(QPointF position, qreal accuracy)
137 qDebug() << __PRETTY_FUNCTION__;
139 if (m_autoCenteringEnabled)
140 m_mapEngine->setViewLocation(position);
143 void MapViewScreen::enableAutoCentering(bool enabled)
145 qDebug() << __PRETTY_FUNCTION__;
147 m_autoCenteringEnabled = enabled;
148 m_mapEngine->setAutoCentering(enabled);