Created implemented resize slots for the panels
[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     //DEBUG
67 //    QVBoxLayout *mapControlLayout = new QVBoxLayout;
68 //    QWidget *mapControl = new QWidget(this);
69 //    mapControl->setLayout(mapControlLayout);
70 //    search = new QPushButton("Search", this);
71 //    zoomOut = new QPushButton("-", this);
72 //    zoomIn = new QPushButton("+", this);
73 //    mapControlLayout->addWidget(&latLine);
74 //    mapControlLayout->addWidget(&lonLine);
75 //    mapControlLayout->addWidget(search);
76 //    mapControlLayout->addWidget(zoomIn);
77 //    mapControlLayout->addWidget(zoomOut);
78 //    mapViewLayout->addWidget(mapControl);
79 //    connect(search, SIGNAL(clicked()), this, SLOT(searchMap()));
80 //    connect(zoomIn, SIGNAL(clicked()), mapEngine, SLOT(zoomIn()));
81 //    connect(zoomOut, SIGNAL(clicked()), mapEngine, SLOT(zoomOut()));
82     //DEBUG
83
84     osmLicense = new QLabel(this);
85     osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
86     osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
87     osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
88     osmLicense->setFont(QFont("Nokia Sans", 9));
89     osmLicense->resize(osmLicense->fontMetrics().width(OSM_LICENSE),
90                        osmLicense->fontMetrics().height());
91
92     userPanel->stackUnder(friendsListPanel);
93     osmLicense->stackUnder(userPanel);
94     mapView->stackUnder(osmLicense);
95
96     mapViewLayout->addWidget(mapView);
97     setLayout(mapViewLayout);
98
99     mapViewLayout->setMargin(0);
100
101     mapEngine->init();
102
103     setObjectName("Map view");
104 }
105
106 void MapViewScreen::searchMap()
107 {
108     qreal lat = latLine.text().toFloat();
109     qreal lon = lonLine.text().toFloat();
110
111     qDebug() << lat << "," << lon;
112
113     mapEngine->setViewLocation(QPointF(lon, lat));
114 }
115
116 void MapViewScreen::userLocationReady(User *user)
117 {
118     qDebug() << __PRETTY_FUNCTION__;
119     mapEngine->receiveOwnLocation(user);
120 }
121
122 void MapViewScreen::friendsLocationsReady(QList<User *> &friendsList)
123 {
124     qDebug() << __PRETTY_FUNCTION__;
125     mapEngine->receiveFriendLocations(friendsList);
126 }
127
128 void MapViewScreen::drawOsmLicense(int width, int height)
129 {
130     qWarning() << __PRETTY_FUNCTION__ << width << "x" << height;
131     osmLicense->move(width-osmLicense->fontMetrics().width(OSM_LICENSE),
132                      height-osmLicense->fontMetrics().height());
133 }