mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-27 21:24:47 +01:00
Zooming & scrolling improvements
This commit is contained in:
parent
0c002bc1e9
commit
f54ca1529a
10
src/ll.cpp
10
src/ll.cpp
@ -58,5 +58,13 @@ QPointF tile2mercator(const QPoint &tile, int z)
|
||||
|
||||
int scale2zoom(qreal scale)
|
||||
{
|
||||
return (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
int zoom;
|
||||
|
||||
zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
|
||||
|
||||
if (zoom < ZOOM_MIN)
|
||||
return ZOOM_MIN;
|
||||
if (zoom > ZOOM_MAX)
|
||||
return ZOOM_MAX;
|
||||
return zoom;
|
||||
}
|
||||
|
2
src/ll.h
2
src/ll.h
@ -4,6 +4,8 @@
|
||||
#include <QPointF>
|
||||
|
||||
#define TILE_SIZE 256
|
||||
#define ZOOM_MAX 18
|
||||
#define ZOOM_MIN 3
|
||||
|
||||
QPointF ll2mercator(const QPointF &ll);
|
||||
qreal llDistance(const QPointF &p1, const QPointF &p2);
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
#define MARGIN 10.0
|
||||
#define TRACK_WIDTH 3
|
||||
#define ZOOM_MAX 19
|
||||
#define ZOOM_MIN 0
|
||||
|
||||
|
||||
Track::Track(QWidget *parent)
|
||||
@ -23,8 +21,10 @@ Track::Track(QWidget *parent)
|
||||
{
|
||||
_scene = new QGraphicsScene(this);
|
||||
setScene(_scene);
|
||||
setResizeAnchor(QGraphicsView::AnchorViewCenter);
|
||||
setCacheMode(QGraphicsView::CacheBackground);
|
||||
setDragMode(QGraphicsView::ScrollHandDrag);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
||||
_zoom = -1;
|
||||
_scale = 1.0;
|
||||
@ -120,10 +120,20 @@ void Track::rescale(qreal scale)
|
||||
_trackPaths.at(i)->setPen(pen);
|
||||
}
|
||||
|
||||
QHash<Entry, POIItem*>::const_iterator it;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
|
||||
QHash<Entry, POIItem*>::const_iterator it, jt;
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
it.value()->setPos(QPointF(it.value()->entry().coordinates.x()
|
||||
* 1.0/scale, -it.value()->entry().coordinates.y() * 1.0/scale));
|
||||
it.value()->show();
|
||||
}
|
||||
|
||||
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
|
||||
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
|
||||
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
|
||||
&& it.value()->collidesWithItem(jt.value()))
|
||||
jt.value()->hide();
|
||||
}
|
||||
}
|
||||
|
||||
_scale = scale;
|
||||
}
|
||||
@ -175,11 +185,15 @@ void Track::redraw()
|
||||
|
||||
void Track::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
QPointF pos = mapToScene(event->pos());
|
||||
qreal scale = _scale;
|
||||
|
||||
_zoom = (event->delta() > 0) ?
|
||||
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
|
||||
|
||||
rescale(mapScale());
|
||||
_scene->setSceneRect(_scene->itemsBoundingRect());
|
||||
centerOn(pos * scale/_scale);
|
||||
resetCachedContent();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user