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