forked from madtreat/cpd-map
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapwidget.cpp
183 lines (150 loc) · 5.72 KB
/
mapwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* File: mapwidget.cpp
* Author: Madison Treat <madison.treat@tamu.edu>
*
* Created on June 15, 2015, 2:36 PM
*/
#include "mapwidget.h"
#include <QDebug>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QResizeEvent>
#include "mapconsts.h"
#include "mapcontroller.h"
#include "mapview.h"
#include "mapsettings.h"
#include "mapoverlay.h"
MapWidget::MapWidget(
MapSettings* _mapSettings,
MapController* _mapC,
ACMap* _acMap,
QFrame* _parent
)
: QFrame(_parent),
mapSettings(_mapSettings),
mapC(_mapC),
acMap(_acMap) {
QVBoxLayout* layout = new QVBoxLayout(this);
// QSizePolicy sp(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
// sp.setHeightForWidth(true);
// setSizePolicy(sp);
view = new MapView(mapSettings, mapC, acMap);
// view->setSizePolicy(sp);
layout->addWidget(view);
connect(view, &MapView::mapLoaded, this, &MapWidget::mapFinishedLoading);
overlay = new MapOverlay(mapSettings, acMap, view);
overlay->setGeometry(view->geometry());
// DO NOT ADD the overlay to the layout; it mirrors the view's geometry,
// therefore it will be placed where it supposed to go on its own.
// Connect CPDController-via-MapController signals to their destinations.
connect(mapC, &MAPC::panToLocation, this, &MapWidget::panToLocation);
connect(mapC, &MAPC::acUpdated, view, &MapView::updateAC);
connect(mapC, &MAPC::setHeading, view, &MapView::setHeading);
connect(mapC, &MAPC::setHeading, overlay, &MapOverlay::setHeading);
setupControls();
layout->addWidget(controls);
setMinimumSize(QSize(DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT));
resize(DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT);
setObjectName("border");
}
//MapWidget::MapWidget(const MapWidget& orig) {
//}
MapWidget::~MapWidget() {
delete view;
}
QSize MapWidget::sizeHint() const {
return QSize(DEFAULT_MAP_WIDTH, DEFAULT_MAP_HEIGHT);
}
void MapWidget::resizeEvent(QResizeEvent* event) {
resize(event->size());
}
void MapWidget::resize(int w, int h) {
resize(QSize(w, h));
}
void MapWidget::resize(const QSize& size) {
QWidget::resize(size);
int hPadding = 2 * MAP_PADDING;
int vPadding = 3 * MAP_PADDING + BUTTON_HEIGHT;
QSize paddedSize(size.width()-hPadding, size.height()-vPadding);
view->resize(paddedSize);
overlay->resize(paddedSize);
}
void MapWidget::mapFinishedLoading(bool success) {
view->displayTraffic(trafficButton->isChecked());
view->showSatMap(terrainButton->isChecked());
}
void MapWidget::orientationButtonClicked(bool checked) {
MapOrientation mo = checked ? NORTH_UP : TRACK_UP;
mapC->setOrientation(mo);
}
void MapWidget::setZoom(int level) {
view->setZoom(level);
overlay->setZoom(level);
}
void MapWidget::panToLocation(float lat, float lon) {
view->panToLocation(lat, lon);
overlay->panToLocation(lat, lon);
overlay->repaint();
}
/*
* Helper function for creating consistent toolbar buttons.
*/
QPushButton* MapWidget::createToolButton(QString text, bool checkable) {
QPushButton* button = new QPushButton(text);
button->setMinimumSize(QSize(BUTTON_WIDTH, BUTTON_HEIGHT));
QSizePolicy sp(QSizePolicy::Fixed, QSizePolicy::Fixed);
button->setSizePolicy(sp);
if (checkable) {
button->setCheckable(true);
}
return button;
}
void MapWidget::setupControls() {
controls = new QFrame(this);
// controls->setObjectName("border-light");
controls->setMaximumHeight(BUTTON_HEIGHT);
QHBoxLayout* controlsLayout = new QHBoxLayout(controls);
controlsLayout->setContentsMargins(0, 0, 0, 0);
controlsLayout->setSpacing(10);
// weatherButton = createToolButton("WX", false);
// weatherButton->setEnabled(false);
// controlsLayout->addWidget(weatherButton);
trafficButton = createToolButton("TFC", true);
trafficButton->setEnabled(true);
connect(trafficButton, SIGNAL(toggled(bool)), view, SLOT(displayTraffic(bool)));
connect(trafficButton, SIGNAL(toggled(bool)), overlay, SLOT(displayTraffic(bool)));
trafficButton->setChecked(true);
controlsLayout->addWidget(trafficButton);
terrainButton = createToolButton("SAT", true);
terrainButton->setEnabled(true);
connect(terrainButton, SIGNAL(toggled(bool)), view, SLOT(showSatMap(bool)));
connect(terrainButton, SIGNAL(toggled(bool)), overlay, SLOT(satButtonClicked(bool)));
terrainButton->setChecked(true);
controlsLayout->addWidget(terrainButton);
orientationButton = createToolButton("North Up", true);
orientationButton->setEnabled(true);
orientationButton->setChecked(true);
if (mapSettings->mapOrientation() == TRACK_UP) {
orientationButton->setChecked(false);
}
connect(orientationButton, SIGNAL(toggled(bool)), this, SLOT(orientationButtonClicked(bool)));
controlsLayout->addWidget(orientationButton);
zoomInButton = createToolButton("Zoom In", false);
zoomInButton->setEnabled(true);
connect(zoomInButton, SIGNAL(clicked()), mapC, SLOT(increaseZoom()));
// If you are at the max zoom (very close shot of ground), disable zoom in button
connect(mapC, SIGNAL(zoomMaxReached(bool)), zoomInButton, SLOT(setDisabled(bool)));
connect(mapC, SIGNAL(zoomEither(bool)), zoomInButton, SLOT(setEnabled(bool)));
controlsLayout->addWidget(zoomInButton);
zoomOutButton = createToolButton("Zoom Out", false);
zoomOutButton->setEnabled(true);
connect(zoomOutButton, SIGNAL(clicked()), mapC, SLOT(decreaseZoom()));
// If you are at the minimum zoom (whole earth), disable zoom out button
connect(mapC, SIGNAL(zoomMinReached(bool)), zoomOutButton, SLOT(setDisabled(bool)));
connect(mapC, SIGNAL(zoomEither(bool)), zoomOutButton, SLOT(setEnabled(bool)));
controlsLayout->addWidget(zoomOutButton);
// No longer using the toolbar directly in the QMainWindow so it can be
// inserted into the LayoutManager.
// this->addToolBar(Qt::RightToolBarArea, toolbar);
}