mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-03-16 11:37:46 +01:00
Fixed special cases scene rect computation
This commit is contained in:
parent
c8a39a607b
commit
5a8250ed63
@ -180,10 +180,13 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
|
|||||||
wi->setVisible(_showWaypoints);
|
wi->setVisible(_showWaypoints);
|
||||||
_scene->addItem(wi);
|
_scene->addItem(wi);
|
||||||
|
|
||||||
if (!_wr.isNull())
|
if (_wr.isNull()) {
|
||||||
|
if (_wp.isNull())
|
||||||
|
_wp = wi->coordinates();
|
||||||
|
else
|
||||||
|
_wr = qrectf(_wp, wi->coordinates());
|
||||||
|
} else
|
||||||
unite(_wr, wi->coordinates());
|
unite(_wr, wi->coordinates());
|
||||||
else if (i > 1)
|
|
||||||
_wr = qrectf(_waypoints.last()->coordinates(), wi->coordinates());
|
|
||||||
|
|
||||||
_waypoints.append(wi);
|
_waypoints.append(wi);
|
||||||
}
|
}
|
||||||
@ -215,14 +218,11 @@ QList<PathItem *> PathView::loadData(const Data &data)
|
|||||||
else
|
else
|
||||||
updatePOIVisibility();
|
updatePOIVisibility();
|
||||||
|
|
||||||
qreal scale = mapScale(_zoom);
|
QRectF sr = contentsSceneRect();
|
||||||
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
|
_scene->setSceneRect(sr);
|
||||||
QRectF ba = br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
|
centerOn(sr.center());
|
||||||
Tile::size());
|
|
||||||
_scene->setSceneRect(ba);
|
|
||||||
centerOn(ba.center());
|
|
||||||
|
|
||||||
_mapScale->setZoom(_zoom, -(br.center().ry() * mapScale(_zoom)));
|
_mapScale->setZoom(_zoom, -(sr.center().ry() * mapScale(_zoom)));
|
||||||
if (_mapScale->scene() != _scene)
|
if (_mapScale->scene() != _scene)
|
||||||
_scene->addItem(_mapScale);
|
_scene->addItem(_mapScale);
|
||||||
|
|
||||||
@ -242,6 +242,19 @@ qreal PathView::contentsScale() const
|
|||||||
return qMax(sc.x(), sc.y());
|
return qMax(sc.x(), sc.y());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF PathView::contentsSceneRect() const
|
||||||
|
{
|
||||||
|
qreal scale = mapScale(_zoom);
|
||||||
|
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
|
||||||
|
|
||||||
|
if (br.isNull())
|
||||||
|
return QRectF(QPointF(_wp.x() / scale - Tile::size()/2,
|
||||||
|
_wp.y() /scale - Tile::size()/2), QSizeF(Tile::size(), Tile::size()));
|
||||||
|
else
|
||||||
|
return br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
|
||||||
|
Tile::size());
|
||||||
|
}
|
||||||
|
|
||||||
void PathView::updatePOIVisibility()
|
void PathView::updatePOIVisibility()
|
||||||
{
|
{
|
||||||
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
|
||||||
@ -395,17 +408,15 @@ void PathView::zoom(int z, const QPoint &pos)
|
|||||||
_zoom = z;
|
_zoom = z;
|
||||||
|
|
||||||
rescale(_zoom);
|
rescale(_zoom);
|
||||||
qreal scale = mapScale(_zoom);
|
|
||||||
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
|
|
||||||
QRectF ba = br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
|
|
||||||
Tile::size());
|
|
||||||
_scene->setSceneRect(ba);
|
|
||||||
|
|
||||||
if (br.width() < viewport()->size().width()
|
QRectF sr = contentsSceneRect();
|
||||||
&& br.height() < viewport()->size().height())
|
_scene->setSceneRect(sr);
|
||||||
centerOn(br.center());
|
|
||||||
|
if (sr.width() < viewport()->size().width()
|
||||||
|
&& sr.height() < viewport()->size().height())
|
||||||
|
centerOn(sr.center());
|
||||||
else
|
else
|
||||||
centerOn((spos * (os/scale)) - offset);
|
centerOn((spos * (os/mapScale(_zoom))) - offset);
|
||||||
|
|
||||||
_mapScale->setZoom(_zoom);
|
_mapScale->setZoom(_zoom);
|
||||||
|
|
||||||
@ -494,6 +505,7 @@ void PathView::clear()
|
|||||||
|
|
||||||
_zoom = ZOOM_MAX;
|
_zoom = ZOOM_MAX;
|
||||||
_tr = QRectF(); _rr = QRectF(); _wr = QRectF();
|
_tr = QRectF(); _rr = QRectF(); _wr = QRectF();
|
||||||
|
_wp = QPointF();
|
||||||
|
|
||||||
_scene->setSceneRect(QRectF());
|
_scene->setSceneRect(QRectF());
|
||||||
}
|
}
|
||||||
@ -610,23 +622,20 @@ void PathView::resizeEvent(QResizeEvent *event)
|
|||||||
|
|
||||||
rescale();
|
rescale();
|
||||||
|
|
||||||
qreal scale = mapScale(_zoom);
|
QRectF sr = contentsSceneRect();
|
||||||
QRectF br = scaled(_tr | _rr | _wr, 1.0/scale);
|
|
||||||
QRectF ba = br.adjusted(-Tile::size(), -Tile::size(), Tile::size(),
|
|
||||||
Tile::size());
|
|
||||||
|
|
||||||
if (ba.width() < event->size().width()) {
|
if (sr.width() < event->size().width()) {
|
||||||
qreal diff = event->size().width() - ba.width();
|
qreal diff = event->size().width() - sr.width();
|
||||||
ba.adjust(-diff/2, 0, diff/2, 0);
|
sr.adjust(-diff/2, 0, diff/2, 0);
|
||||||
}
|
}
|
||||||
if (ba.height() < event->size().height()) {
|
if (sr.height() < event->size().height()) {
|
||||||
qreal diff = event->size().height() - ba.height();
|
qreal diff = event->size().height() - sr.height();
|
||||||
ba.adjust(0, -diff/2, 0, diff/2);
|
sr.adjust(0, -diff/2, 0, diff/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
_scene->setSceneRect(ba);
|
_scene->setSceneRect(sr);
|
||||||
|
centerOn(sr.center());
|
||||||
|
|
||||||
centerOn(br.center());
|
|
||||||
resetCachedContent();
|
resetCachedContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ private:
|
|||||||
void clearPOI();
|
void clearPOI();
|
||||||
|
|
||||||
qreal contentsScale() const;
|
qreal contentsScale() const;
|
||||||
|
QRectF contentsSceneRect() const;
|
||||||
void rescale(int zoom);
|
void rescale(int zoom);
|
||||||
void rescale();
|
void rescale();
|
||||||
void zoom(int z, const QPoint &pos);
|
void zoom(int z, const QPoint &pos);
|
||||||
@ -87,6 +88,7 @@ private:
|
|||||||
|
|
||||||
int _zoom;
|
int _zoom;
|
||||||
QRectF _tr, _rr, _wr;
|
QRectF _tr, _rr, _wr;
|
||||||
|
QPointF _wp;
|
||||||
|
|
||||||
Map *_map;
|
Map *_map;
|
||||||
POI *_poi;
|
POI *_poi;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user