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