Subversion Repositories Projects

Rev

Go to most recent revision | Details | 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
 
25
    connect(sl_Zoom,   SIGNAL(valueChanged(int)), this, SLOT(slot_Zoom(int)));
26
    connect(pb_Add,    SIGNAL(clicked()), this, SLOT(slot_AddWP()));
27
    connect(pb_Delete, SIGNAL(clicked()), this, SLOT(slot_DeleteWP()));
28
    connect(cb_Maps,   SIGNAL(currentIndexChanged(int)), this, SLOT(slot_ChangeMap(int)));
29
 
30
//    o_Map = new MapControl(QSize(500,300));
31
    o_Map = new MapControl(w_Map->size());
32
 
33
    o_Adapter = new OSMMapAdapter();
34
//    o_Adapter = new GoogleMapAdapter();
35
 
36
    o_Layer = new MapLayer("MapLayer", o_Adapter);
37
    o_Click = new GeometryLayer("Click", o_Adapter);
38
    o_Route = new GeometryLayer("Poute", o_Adapter);
39
 
40
    o_Map->addLayer(o_Layer);
41
    o_Map->addLayer(o_Click);
42
    o_Map->addLayer(o_Route);
43
 
44
    o_Map->setZoom(17);
45
//    o_Map->setView(QPointF(13.85615670,52.50787020));
46
    o_Map->setView(QPointF(13.5,52.5));
47
 
48
    connect(o_Map, SIGNAL(mouseEventCoordinate(const QMouseEvent*, const QPointF)), this, SLOT(slot_Click(const QMouseEvent*, const QPointF)));
49
 
50
    l_Map->addWidget(o_Map);
51
 
52
    sl_Zoom->setValue(17);
53
 
54
    QDir path = QDir::homePath() + "/.QMK-Cache";
55
    o_Map->enablePersistentCache(path);
56
 
57
    Pen[0] = new QPen(QColor(0,0,255,255));
58
    Pen[0]->setWidth(2);
59
    Pen[1] = new QPen(QColor(255,0,0,255));
60
    Pen[1]->setWidth(2);
61
 
62
}
63
 
64
void dlg_Map::add_Position(double x, double y)
65
{
66
    o_Route->removeGeometry(l_RouteFL);
67
    p_RouteFL.append(new Point(x,y));
68
 
69
    o_Click->removeGeometry(LastPos);
70
 
71
    Point* P = new CirclePoint(x, y, "P1", Point::Middle, Pen[0]);
72
    LastPos = P;
73
    P->setBaselevel(17);
74
    o_Click->addGeometry(P);
75
 
76
    if (cb_CenterPos->isChecked())
77
    {
78
        o_Map->setView(QPointF(x, y));
79
    }
80
 
81
    if (cb_ShowRoute->isChecked())
82
    {
83
        l_RouteFL = new LineString(p_RouteFL, "", Pen[1]);
84
 
85
        o_Route->addGeometry(l_RouteFL);
86
    }
87
    o_Map->updateRequestNew();
88
}
89
 
90
void dlg_Map::slot_Zoom(int i_Zoom)
91
{
92
    o_Map->setZoom(i_Zoom);
93
}
94
 
95
void dlg_Map::slot_AddWP()
96
{
97
    o_Route->removeGeometry(l_RouteWP);
98
 
99
    p_RouteWP.append(LastClick);
100
    l_RouteWP = new LineString(p_RouteWP, "", Pen[0]);
101
 
102
    o_Route->addGeometry(l_RouteWP);
103
    o_Map->updateRequestNew();
104
}
105
 
106
void dlg_Map::slot_DeleteWP()
107
{
108
    o_Route->removeGeometry(l_RouteWP);
109
    p_RouteWP.clear();
110
    o_Map->updateRequestNew();
111
}
112
 
113
void dlg_Map::slot_Click(const QMouseEvent* Event, const QPointF Coord)
114
{
115
    if ((Event->type() == QEvent::MouseButtonPress) && ((Event->button() == Qt::RightButton) || (Event->button() == Qt::MidButton)))
116
    {
117
        sl_Zoom->setValue(o_Adapter->adaptedZoom());
118
    }
119
 
120
    if ((Event->type() == QEvent::MouseButtonPress) && (Event->button() == Qt::LeftButton))
121
    {
122
        o_Click->removeGeometry(LastPoint);
123
 
124
        Point* P = new CirclePoint(Coord.x(), Coord.y(), 3, "P1", Point::Middle, Pen[1]);
125
        LastPoint = P;
126
 
127
        LastClick = new Point(Coord.x(), Coord.y());
128
 
129
        P->setBaselevel(o_Adapter->adaptedZoom());
130
        o_Click->addGeometry(P);
131
    }
132
    o_Map->updateRequestNew();
133
}
134
 
135
void dlg_Map::resizeEvent ( QResizeEvent * event )
136
{
137
//    o_Map->resize(event->size());
138
    o_Map->resize(w_Map->size() - QSize(20,20));
139
}
140
 
141
void dlg_Map::slot_ChangeMap(int Set)
142
{
143
   switch(Set)
144
   {
145
       case 0 :
146
       {
147
            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
       {
159
            int zoom = o_Adapter->adaptedZoom();
160
            o_Map->setZoom(0);
161
 
162
            o_Adapter = new YahooMapAdapter();
163
            o_Layer->setMapAdapter(o_Adapter);
164
 
165
            o_Map->updateRequestNew();
166
            o_Map->setZoom(zoom);
167
       }
168
       break;
169
       case 2 :
170
       {
171
            int zoom = o_Adapter->adaptedZoom();
172
            QPointF a = o_Map->currentCoordinate();
173
 
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
 
179
            o_Map->updateRequestNew();
180
            o_Map->setZoom(zoom);
181
       }
182
       break;
183
       case 3 :
184
       {
185
            int zoom = o_Adapter->adaptedZoom();
186
            QPointF a = o_Map->currentCoordinate();
187
 
188
            o_Map->setZoom(0);
189
 
190
            o_Adapter = new GoogleMapAdapter();
191
            o_Layer->setMapAdapter(o_Adapter);
192
 
193
            o_Map->updateRequestNew();
194
            o_Map->setZoom(zoom);
195
       }
196
       break;
197
   }
198
}