1
/***************************************************************************
2
* Copyright (C) 2007 by Kai Winter *
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, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to the *
17
* Free Software Foundation, Inc., *
18
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19
***************************************************************************/
24
Point::Point(const Point& point)
25
:Geometry(point.getName()), X(point.getLongitude()), Y(point.getLatitude())
27
visible = point.isVisible();
30
this->pen = point.pen;
32
minsize = QSize(-1,-1);
33
maxsize = QSize(-1,-1);
36
Point::Point(double x, double y, QString name, enum Alignment alignment)
37
: Geometry(name), X(x), Y(y), alignment(alignment)
39
GeometryType = "Point";
44
minsize = QSize(-1,-1);
45
maxsize = QSize(-1,-1);
48
Point::Point(double x, double y, QWidget* widget, QString name, enum Alignment alignment)
49
: Geometry(name), X(x), Y(y), mywidget(widget), alignment(alignment)
51
// Point(x, y, name, alignment);
52
GeometryType = "Point";
55
size = widget->size();
57
minsize = QSize(-1,-1);
58
maxsize = QSize(-1,-1);
61
Point::Point(double x, double y, QPixmap* pixmap, QString name, enum Alignment alignment)
62
: Geometry(name), X(x), Y(y), mypixmap(pixmap), alignment(alignment)
64
GeometryType = "Point";
67
size = pixmap->size();
69
minsize = QSize(-1,-1);
70
maxsize = QSize(-1,-1);
73
Point& Point::operator=(const Point& rhs)
83
mywidget = rhs.mywidget;
84
mypixmap = rhs.mypixmap;
85
alignment = rhs.alignment;
86
homelevel = rhs.homelevel;
87
minsize = rhs.minsize;
88
maxsize = rhs.maxsize;
98
void Point::setVisible(bool visible)
100
this->visible = visible;
103
mywidget->setVisible(visible);
107
QRectF Point::getBoundingBox()
109
//TODO: have to be calculated in relation to alignment...
110
return QRectF(QPointF(X, Y), displaysize);
113
double Point::getLongitude() const
117
double Point::getLatitude() const
121
QPointF Point::getCoordinate() const
123
return QPointF(X, Y);
126
void Point::draw(QPainter* painter, const MapAdapter* mapadapter, const QRect &viewport, const QPoint offset)
134
int currentzoom = mapadapter->getMaxZoom() < mapadapter->getMinZoom() ? mapadapter->getMinZoom() - mapadapter->getZoom() : mapadapter->getZoom();
136
// int currentzoom = mapadapter->getZoom();
137
int diffzoom = homelevel-currentzoom;
138
int viewheight = size.height();
139
int viewwidth = size.width();
140
viewheight = int(viewheight / pow(2, diffzoom+0.0));
141
viewwidth = int(viewwidth / pow(2, diffzoom+0.0));
143
if (minsize.height()!= -1 && viewheight < minsize.height())
144
viewheight = minsize.height();
145
else if (maxsize.height() != -1 && viewheight > maxsize.height())
146
viewheight = maxsize.height();
149
if (minsize.width()!= -1 && viewwidth < minsize.width())
150
viewwidth = minsize.width();
151
else if (maxsize.width() != -1 && viewwidth > maxsize.width())
152
viewwidth = maxsize.width();
155
displaysize = QSize(viewwidth, viewheight);
165
const QPointF c = QPointF(X, Y);
166
QPoint point = mapadapter->coordinateToDisplay(c);
168
if (viewport.contains(point))
170
QPoint alignedtopleft = getAlignedPoint(point);
171
painter->drawPixmap(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height(), *mypixmap);
175
else if (mywidget!=0)
177
drawWidget(mapadapter, offset);
182
void Point::drawWidget(const MapAdapter* mapadapter, const QPoint offset)
184
const QPointF c = QPointF(X, Y);
185
QPoint point = mapadapter->coordinateToDisplay(c);
188
QPoint alignedtopleft = getAlignedPoint(point);
189
mywidget->setGeometry(alignedtopleft.x(), alignedtopleft.y(), displaysize.width(), displaysize.height());
192
QPoint Point::getAlignedPoint(const QPoint point) const
194
QPoint alignedtopleft;
195
if (alignment == Middle)
197
alignedtopleft.setX(point.x()-displaysize.width()/2);
198
alignedtopleft.setY(point.y()-displaysize.height()/2);
200
else if (alignment == TopLeft)
202
alignedtopleft.setX(point.x());
203
alignedtopleft.setY(point.y());
205
else if (alignment == TopRight)
207
alignedtopleft.setX(point.x()-displaysize.width());
208
alignedtopleft.setY(point.y());
210
else if (alignment == BottomLeft)
212
alignedtopleft.setX(point.x());
213
alignedtopleft.setY(point.y()-displaysize.height());
215
else if (alignment == BottomRight)
217
alignedtopleft.setX(point.x()-displaysize.width());
218
alignedtopleft.setY(point.y()-displaysize.height());
220
return alignedtopleft;
224
bool Point::Touches(Point* p, const MapAdapter* mapadapter)
226
if (this->isVisible() == false)
231
QPointF c = p->getCoordinate();
232
// coordinate nach pixel umrechnen
233
QPoint pxOfPoint = mapadapter->coordinateToDisplay(c);
234
// size/2 Pixel toleranz aufaddieren
241
p1 = pxOfPoint - QPoint(displaysize.width()/2,displaysize.height()/2);
242
p2 = pxOfPoint + QPoint(displaysize.width()/2,displaysize.height()/2);
245
p1 = pxOfPoint - QPoint(displaysize.width(),displaysize.height());
249
p1 = pxOfPoint - QPoint(0, displaysize.height());
250
p2 = pxOfPoint + QPoint(displaysize.width(),0);
253
p1 = pxOfPoint - QPoint(displaysize.width(), 0);
254
p2 = pxOfPoint + QPoint(0, displaysize.height());
258
p2 = pxOfPoint + QPoint(displaysize.width(), displaysize.height());
262
// "Bounding Box" in koordinate umrechnen
263
QPointF c1 = mapadapter->displayToCoordinate(p1);
264
QPointF c2 = mapadapter->displayToCoordinate(p2);
267
if(this->getLongitude()>=c1.x() && this->getLongitude()<=c2.x())
269
if (this->getLatitude()<=c1.y() && this->getLatitude()>=c2.y())
271
emit(geometryClickEvent(this, QPoint(0,0)));
278
void Point::setCoordinate(QPointF point)
280
// emit(updateRequest(this));
281
// emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
284
// emit(updateRequest(this));
285
emit(updateRequest(QRectF(X, Y, size.width(), size.height())));
287
emit(positionChanged(this));
289
QList<Point*> Point::getPoints()
291
//TODO: assigning temp?!
292
QList<Point*> points;
297
QWidget* Point::getWidget()
302
QPixmap* Point::getPixmap()
307
void Point::setBaselevel(int zoomlevel)
309
homelevel = zoomlevel;
311
void Point::setMinsize(QSize minsize)
313
this->minsize = minsize;
315
void Point::setMaxsize(QSize maxsize)
317
this->maxsize = maxsize;
319
Point::Alignment Point::getAlignment() const