Updated list_item images with new ones.
[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
30 MapViewScreen::MapViewScreen(QWidget *parent)
31    : QWidget(parent)
32 {
33     MapView *mapView = new MapView(this);
34     mapEngine = new MapEngine(this);
35     mapView->setScene(mapEngine->scene());
36
37     FriendListPanel *friendsListPanel = new FriendListPanel(this);
38     UserInfoPanel *userPanel = new UserInfoPanel(this);
39
40     connect(mapView, SIGNAL(viewScrolled(QPoint)),
41             mapEngine, SLOT(setLocation(QPoint)));
42     connect(mapEngine, SIGNAL(locationChanged(QPoint)),
43             mapView, SLOT(centerToSceneCoordinates(QPoint)));
44     connect(mapEngine, SIGNAL(zoomLevelChanged(int)),
45             mapView, SLOT(setZoomLevel(int)));
46     connect(mapView, SIGNAL(viewResized(QSize)),
47             mapEngine, SLOT(viewResized(QSize)));
48     connect(mapView, SIGNAL(viewContentChanged(QPoint)),
49             mapEngine, SLOT(alignImmovableItems(QPoint)));
50     connect(mapView, SIGNAL(viewZoomFinished()),
51             mapEngine, SLOT(viewZoomFinished()));
52
53     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
54             this, SLOT(drawOsmLicense(int, int)));
55
56     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
57             friendsListPanel, SLOT(reDrawFriendsPanel(int,int)));
58     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
59             userPanel, SLOT(reDrawUserPanel(int,int)));
60
61     connect(this, SIGNAL(SIG_friendsLocationsReady(QList<User*>&)),
62             friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
63
64
65     QHBoxLayout *mapViewLayout = new QHBoxLayout;
66
67     osmLicense = new QLabel(this);
68     osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
69     osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
70     osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
71     osmLicense->setFont(QFont("Nokia Sans", 9));
72     osmLicense->resize(osmLicense->fontMetrics().width(OSM_LICENSE),
73                        osmLicense->fontMetrics().height());
74
75     userPanel->stackUnder(friendsListPanel);
76     osmLicense->stackUnder(userPanel);
77     mapView->stackUnder(osmLicense);
78
79     mapViewLayout->addWidget(mapView);
80     setLayout(mapViewLayout);
81
82     mapViewLayout->setMargin(0);
83
84     mapEngine->init();
85
86     setObjectName("Map view");
87 }
88
89 void MapViewScreen::searchMap()
90 {
91     qreal lat = latLine.text().toFloat();
92     qreal lon = lonLine.text().toFloat();
93
94     qDebug() << lat << "," << lon;
95
96     mapEngine->setViewLocation(QPointF(lon, lat));
97 }
98
99 void MapViewScreen::userLocationReady(User *user)
100 {
101     qDebug() << __PRETTY_FUNCTION__;
102     mapEngine->receiveOwnLocation(user);
103 }
104
105 void MapViewScreen::friendsLocationsReady(QList<User *> &friendsList)
106 {
107     qDebug() << __PRETTY_FUNCTION__;
108     mapEngine->receiveFriendLocations(friendsList);
109 }
110
111 void MapViewScreen::drawOsmLicense(int width, int height)
112 {
113     qWarning() << __PRETTY_FUNCTION__ << width << "x" << height;
114     osmLicense->move(width-osmLicense->fontMetrics().width(OSM_LICENSE),
115                      height-osmLicense->fontMetrics().height());
116 }