Subversion Repositories Projects

Rev

Rev 338 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
305 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
#include "dlg_Map.h"
20
 
21
dlg_Map::dlg_Map(QWidget *parent) : QDialog(parent)
22
{
23
    setupUi(this);
24
 
334 KeyOz 25
    cb_Maps->removeItem(5);
26
    cb_Maps->removeItem(4);
27
    cb_Maps->removeItem(3);
28
    cb_Maps->removeItem(2);
29
 
306 KeyOz 30
    pb_Add->setEnabled(false);
31
    pb_Goto->setEnabled(false);
32
}
33
 
34
// Karte erstellen und anzeigen
35
void dlg_Map::create_Map(cSettings *t_Settings)
36
{
37
    o_Settings = t_Settings;
38
 
39
    cb_CenterPos->setChecked(o_Settings->Map.GotoPosition);
40
    cb_ShowRoute->setChecked(o_Settings->Map.ShowTrack);
41
 
305 KeyOz 42
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
306 KeyOz 43
    connect(pb_Add,    SIGNAL(clicked()), this, SLOT(slot_AddWayPoint()));
44
    connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWayPoints()));
45
    connect(pb_Goto,   SIGNAL(clicked()), this, SLOT(slot_GotoTarget()));
358 KeyOz 46
    connect(pb_SendWaypoints, SIGNAL(clicked()), this, SLOT(slot_SendWayPoints()));
305 KeyOz 47
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
306 KeyOz 48
    connect(this,      SIGNAL(rejected()), this, SLOT(slot_Close()));
305 KeyOz 49
 
50
    o_Map = new MapControl(w_Map->size());
306 KeyOz 51
    o_Map->enablePersistentCache(o_Settings->DIR.Cache);
52
    o_Map->showScale(true);
305 KeyOz 53
 
54
    o_Adapter = new OSMMapAdapter();
55
 
56
    o_Layer = new MapLayer("MapLayer", o_Adapter);
57
    o_Click = new GeometryLayer("Click", o_Adapter);
58
    o_Route = new GeometryLayer("Poute", o_Adapter);
59
 
60
    o_Map->addLayer(o_Layer);
61
    o_Map->addLayer(o_Click);
62
    o_Map->addLayer(o_Route);
63
 
64
    o_Map->setZoom(17);
65
    o_Map->setView(QPointF(13.5,52.5));
66
 
67
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
68
 
69
    l_Map->addWidget(o_Map);
70
 
71
    sl_Zoom->setValue(17);
72
 
73
    Pen[0] = new QPen(QColor(0,0,255,255));
74
    Pen[0]->setWidth(2);
75
    Pen[1] = new QPen(QColor(255,0,0,255));
76
    Pen[1]->setWidth(2);
77
}
78
 
306 KeyOz 79
// Position zum Flug-Track hinzufügen
305 KeyOz 80
void dlg_Map::add_Position(double x, double y)
81
{
306 KeyOz 82
    sWayPoint WayPoint;
83
 
84
    WayPoint.Longitude = x;
85
    WayPoint.Latitude = y;
358 KeyOz 86
//    WayPoint.Time = sb_Time->value();
306 KeyOz 87
 
358 KeyOz 88
    l_Track.append(WayPoint);
306 KeyOz 89
 
305 KeyOz 90
    o_Route->removeGeometry(l_RouteFL);
91
    p_RouteFL.append(new Point(x,y));
92
 
93
    o_Click->removeGeometry(LastPos);
94
 
95
    Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]);
96
    LastPos = P;
97
    P->setBaselevel(17);
98
    o_Click->addGeometry(P);
99
 
100
    if (cb_CenterPos->isChecked())
101
    {
102
        o_Map->setView(QPointF(x, y));
103
    }
104
 
105
    if (cb_ShowRoute->isChecked())
106
    {
107
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
108
 
109
        o_Route->addGeometry(l_RouteFL);
110
    }
111
    o_Map->updateRequestNew();
112
}
113
 
306 KeyOz 114
// Zoom der Karte ändern
115
void dlg_Map::slot_Zoom(int t_Zoom)
305 KeyOz 116
{
306 KeyOz 117
    o_Map->setZoom(t_Zoom);
305 KeyOz 118
}
119
 
306 KeyOz 120
// Waypoint zur Liste hinzufügen
121
void dlg_Map::slot_AddWayPoint()
305 KeyOz 122
{
358 KeyOz 123
    sWayPoint WayPoint;
124
 
125
    WayPoint.Longitude = LastClick->longitude();
126
    WayPoint.Latitude = LastClick->latitude();
127
    WayPoint.Time = sb_Time->value();
128
 
129
    l_WayPoints.append(WayPoint);
130
 
305 KeyOz 131
    o_Route->removeGeometry(l_RouteWP);
132
 
133
    p_RouteWP.append(LastClick);
134
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
135
 
136
    o_Route->addGeometry(l_RouteWP);
137
    o_Map->updateRequestNew();
358 KeyOz 138
 
139
    pb_SendWaypoints->setEnabled(true);
305 KeyOz 140
}
141
 
306 KeyOz 142
// Waypoint-Liste löschen
143
void dlg_Map::slot_DeleteWayPoints()
305 KeyOz 144
{
145
    o_Route->removeGeometry(l_RouteWP);
146
    p_RouteWP.clear();
358 KeyOz 147
    l_WayPoints.clear();
305 KeyOz 148
    o_Map->updateRequestNew();
149
}
150
 
358 KeyOz 151
void dlg_Map::slot_SendWayPoints()
152
{
153
    emit(set_WayPoints(l_WayPoints));
154
}
155
 
306 KeyOz 156
// Zum Zielpunkt fliegen
157
void dlg_Map::slot_GotoTarget()
158
{
159
    sWayPoint Target;
160
 
161
    Target.Longitude = LastClick->longitude();
162
    Target.Latitude = LastClick->latitude();
163
    Target.Time = sb_Time->value();
164
 
165
    emit(set_Target(Target));
166
}
167
 
168
// Click in der Karte
305 KeyOz 169
void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord)
170
{
171
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
172
    {
173
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
174
    }
175
 
306 KeyOz 176
    // Überwachen ob Karte verschoben wird
305 KeyOz 177
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
178
    {
306 KeyOz 179
        MapCenter = o_Map->currentCoordinate();
180
    }
305 KeyOz 181
 
306 KeyOz 182
    // Nur wenn nicht Verschoben dann einen Punkt setzen
183
    if ((Event->type() == QEvent::MouseButtonRelease) && (Event->button() == Qt::LeftButton))
184
    {
185
        if (o_Map->currentCoordinate() == MapCenter)
186
        {
187
            pb_Add->setEnabled(true);
188
            pb_Goto->setEnabled(true);
305 KeyOz 189
 
306 KeyOz 190
            o_Click->removeGeometry(ClickPoint);
305 KeyOz 191
 
306 KeyOz 192
            ClickPoint = new CirclePoint(Coord.x(), Coord.y(), 6, "P1", Point::Middle, Pen[1]);
193
//            LastPoint = P;
194
 
195
            LastClick = new Point(Coord.x(), Coord.y());
196
 
197
            ClickPoint->setBaselevel(o_Adapter->adaptedZoom());
198
            o_Click->addGeometry(ClickPoint);
199
        }
305 KeyOz 200
    }
306 KeyOz 201
 
305 KeyOz 202
    o_Map->updateRequestNew();
306 KeyOz 203
//    qDebug(QString("%1").arg(Coord.x()).toLatin1().data());
204
//    qDebug(QString("%1").arg(Coord.y()).toLatin1().data());
305 KeyOz 205
}
206
 
306 KeyOz 207
// auf Veränderung der Fenstergröße reagieren
305 KeyOz 208
void dlg_Map::resizeEvent ( QResizeEvent * event )
209
{
306 KeyOz 210
    event = event;
305 KeyOz 211
    o_Map->resize(w_Map->size() - QSize(20,20));
212
}
213
 
306 KeyOz 214
// Karte wechseln
215
void dlg_Map::slot_ChangeMap(int t_Set)
305 KeyOz 216
{
306 KeyOz 217
    int zoom = o_Adapter->adaptedZoom();
218
    QPointF a = o_Map->currentCoordinate();
305 KeyOz 219
 
306 KeyOz 220
    o_Map->setZoom(0);
221
 
222
    switch(t_Set)
223
    {
224
        case 0 : // OpenStreetMap
225
        {
305 KeyOz 226
            o_Adapter = new OSMMapAdapter();
306 KeyOz 227
        }
228
        break;
334 KeyOz 229
        case 1 : // Yahoo Sat
306 KeyOz 230
        {
338 KeyOz 231
            o_Adapter = new TileMapAdapter("tile.openaerialmap.org", "/tiles/1.0.0/openaerialmap-900913/%1/%2/%3.png", 256, 0, 17);
334 KeyOz 232
        }
233
        break;
234
        case 2 : // Google Maps
235
        {
306 KeyOz 236
            o_Adapter = new GoogleMapAdapter();
237
        }
238
        break;
334 KeyOz 239
        case 3 : // Google Sat
306 KeyOz 240
        {
241
            o_Adapter = new GoogleSatMapAdapter();
242
        }
243
        break;
334 KeyOz 244
        case 4 : // Yahoo Maps
306 KeyOz 245
        {
305 KeyOz 246
            o_Adapter = new YahooMapAdapter();
306 KeyOz 247
        }
248
        break;
334 KeyOz 249
        case 5 : // Yahoo Sat
306 KeyOz 250
        {
305 KeyOz 251
            o_Adapter = new YahooMapAdapter("us.maps3.yimg.com", "/aerial.maps.yimg.com/png?v=1.7&t=a&s=256&x=%2&y=%3&z=%1");
306 KeyOz 252
        }
253
        break;
254
    }
305 KeyOz 255
 
306 KeyOz 256
    o_Layer->setMapAdapter(o_Adapter);
257
    o_Click->setMapAdapter(o_Adapter);
258
    o_Route->setMapAdapter(o_Adapter);
305 KeyOz 259
 
306 KeyOz 260
    o_Map->updateRequestNew();
261
    o_Map->setZoom(zoom);
262
}
305 KeyOz 263
 
306 KeyOz 264
// Fenster wird geschlossen.
265
void dlg_Map::slot_Close()
266
{
267
    o_Settings->Map.GotoPosition = cb_CenterPos->isChecked();
268
    o_Settings->Map.ShowTrack    = cb_ShowRoute->isChecked();
269
    emit set_Settings(o_Settings);
270
}
305 KeyOz 271