Added some graphics to the panels. Very rudimentary implementation at
[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 #include "panelcommon.h"
30
31 #include "panelsidebar.h"
32
33 MapViewScreen::MapViewScreen(QWidget *parent)
34    : QWidget(parent)
35 {
36     MapView *mapView = new MapView(this);
37     mapEngine = new MapEngine(this);
38     mapView->setScene(mapEngine->scene());
39
40     FriendListPanel *friendsListPanel = new FriendListPanel(this);
41     UserInfoPanel *userPanel = new UserInfoPanel(this);
42     PanelSideBar *userPanelSidebar = new PanelSideBar(this, "left");
43     PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, "right");
44
45     connect(mapView, SIGNAL(viewScrolled(QPoint)),
46             mapEngine, SLOT(setLocation(QPoint)));
47     connect(mapEngine, SIGNAL(locationChanged(QPoint)),
48             mapView, SLOT(centerToSceneCoordinates(QPoint)));
49     connect(mapEngine, SIGNAL(zoomLevelChanged(int)),
50             mapView, SLOT(setZoomLevel(int)));
51     connect(mapView, SIGNAL(viewResized(QSize)),
52             mapEngine, SLOT(viewResized(QSize)));
53     connect(mapView, SIGNAL(viewContentChanged(QPoint)),
54             mapEngine, SLOT(alignImmovableItems(QPoint)));
55     connect(mapView, SIGNAL(viewZoomFinished()),
56             mapEngine, SLOT(viewZoomFinished()));
57
58     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
59             this, SLOT(drawOsmLicense(int, int)));
60
61     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
62             friendsListPanel, SLOT(reDrawFriendsPanel(int,int)));
63     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
64             userPanel, SLOT(reDrawUserPanel(int,int)));
65     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
66             friendsListPanelSidebar, SLOT(reDrawSidebar(int,int)));
67
68
69     connect(this, SIGNAL(SIG_friendsLocationsReady(QList<User*>&)),
70             friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
71
72
73     QHBoxLayout *mapViewLayout = new QHBoxLayout;
74     //DEBUG
75 //    QVBoxLayout *mapControlLayout = new QVBoxLayout;
76 //    QWidget *mapControl = new QWidget(this);
77 //    mapControl->setLayout(mapControlLayout);
78 //    search = new QPushButton("Search", this);
79 //    zoomOut = new QPushButton("-", this);
80 //    zoomIn = new QPushButton("+", this);
81 //    mapControlLayout->addWidget(&latLine);
82 //    mapControlLayout->addWidget(&lonLine);
83 //    mapControlLayout->addWidget(search);
84 //    mapControlLayout->addWidget(zoomIn);
85 //    mapControlLayout->addWidget(zoomOut);
86 //    mapViewLayout->addWidget(mapControl);
87 //    connect(search, SIGNAL(clicked()), this, SLOT(searchMap()));
88 //    connect(zoomIn, SIGNAL(clicked()), mapEngine, SLOT(zoomIn()));
89 //    connect(zoomOut, SIGNAL(clicked()), mapEngine, SLOT(zoomOut()));
90     //DEBUG
91
92     osmLicense = new QLabel(this);
93     osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
94     osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
95     osmLicense->setText("<font color='black'>"+OSM_LICENSE+"</font>");
96     osmLicense->setFont(QFont("Nokia Sans", 9));
97     osmLicense->resize(osmLicense->fontMetrics().width(OSM_LICENSE),
98                        osmLicense->fontMetrics().height());
99
100     friendsListPanel->stackUnder(friendsListPanelSidebar);
101     userPanelSidebar->stackUnder(friendsListPanel);
102     userPanel->stackUnder(userPanelSidebar);
103     osmLicense->stackUnder(userPanel);
104     mapView->stackUnder(osmLicense);
105
106     mapViewLayout->addWidget(mapView);
107     setLayout(mapViewLayout);
108
109     mapViewLayout->setMargin(0);
110
111     mapEngine->init();
112
113     setObjectName("Map view");
114 }
115
116 void MapViewScreen::searchMap()
117 {
118     qreal lat = latLine.text().toFloat();
119     qreal lon = lonLine.text().toFloat();
120
121     qDebug() << lat << "," << lon;
122
123     mapEngine->setViewLocation(QPointF(lon, lat));
124 }
125
126 void MapViewScreen::userLocationReady(User *user)
127 {
128     qDebug() << __PRETTY_FUNCTION__;
129     mapEngine->receiveOwnLocation(user);
130 }
131
132 void MapViewScreen::friendsLocationsReady(QList<User *> &friendsList)
133 {
134     qDebug() << __PRETTY_FUNCTION__;
135     mapEngine->receiveFriendLocations(friendsList);
136 }
137
138 void MapViewScreen::drawOsmLicense(int width, int height)
139 {
140     qWarning() << __PRETTY_FUNCTION__ << width << "x" << height;
141     osmLicense->move(width - osmLicense->fontMetrics().width(OSM_LICENSE) - PANEL_PEEK_AMOUNT,
142                      height - osmLicense->fontMetrics().height());
143 }