Subversion Repositories Projects

Rev

Rev 305 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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