1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 23:03:22 +02:00
GPXSee/src/pathview.cpp

658 lines
14 KiB
C++
Raw Normal View History

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QWheelEvent>
#include "ll.h"
2016-02-12 10:23:14 +01:00
#include "poi.h"
#include "gpx.h"
2016-02-12 10:09:17 +01:00
#include "map.h"
#include "trackitem.h"
2016-08-09 01:16:19 +02:00
#include "routeitem.h"
2016-02-19 21:34:55 +01:00
#include "waypointitem.h"
#include "scaleitem.h"
2016-09-26 21:01:58 +02:00
#include "pathview.h"
#define MARGIN 10.0
#define SCALE_OFFSET 7
2016-09-26 21:01:58 +02:00
PathView::PathView(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new QGraphicsScene(this);
setScene(_scene);
setCacheMode(QGraphicsView::CacheBackground);
setDragMode(QGraphicsView::ScrollHandDrag);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
2016-02-28 10:58:25 +01:00
setRenderHints(QPainter::Antialiasing);
2016-10-04 10:16:46 +02:00
setAcceptDrops(false);
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
2016-03-15 01:20:24 +01:00
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
_map = 0;
2016-10-08 14:53:10 +02:00
_poi = 0;
2016-07-25 19:32:36 +02:00
_units = Metric;
2016-08-09 01:16:19 +02:00
_showTracks = true;
_showRoutes = true;
_showWaypoints = true;
_showWaypointLabels = true;
2016-10-08 14:53:10 +02:00
_showPOI = true;
2016-08-09 01:16:19 +02:00
_showPOILabels = true;
_overlapPOIs = true;
2016-08-09 10:47:49 +02:00
_showRouteWaypoints = true;
2016-08-09 01:16:19 +02:00
_plot = false;
}
2016-09-26 21:01:58 +02:00
PathView::~PathView()
{
2016-05-12 09:03:05 +02:00
if (_mapScale->scene() != _scene)
delete _mapScale;
}
2016-09-26 21:01:58 +02:00
PathItem *PathView::addTrack(const Track &track)
{
if (track.isNull()) {
2016-03-23 20:49:40 +01:00
_palette.color();
2016-09-19 00:56:10 +02:00
return 0;
2016-03-23 20:49:40 +01:00
}
2016-08-09 01:16:19 +02:00
TrackItem *ti = new TrackItem(track);
_tracks.append(ti);
2016-03-15 01:20:24 +01:00
_zoom = qMin(_zoom, scale2zoom(trackScale()));
_scale = mapScale(_zoom);
2016-08-09 01:16:19 +02:00
ti->setScale(1.0/_scale);
ti->setColor(_palette.color());
ti->setVisible(_showTracks);
_scene->addItem(ti);
2016-09-19 00:56:10 +02:00
2016-10-08 14:53:10 +02:00
if (_poi)
addPOI(_poi->points(ti));
2016-09-19 00:56:10 +02:00
return ti;
2016-03-03 09:15:56 +01:00
}
2016-09-26 21:01:58 +02:00
PathItem *PathView::addRoute(const Route &route)
2016-08-09 01:16:19 +02:00
{
if (route.isNull()) {
_palette.color();
2016-09-19 00:56:10 +02:00
return 0;
2016-08-09 01:16:19 +02:00
}
RouteItem *ri = new RouteItem(route);
_routes.append(ri);
_zoom = qMin(_zoom, scale2zoom(routeScale()));
_scale = mapScale(_zoom);
ri->setScale(1.0/_scale);
ri->setColor(_palette.color());
ri->setVisible(_showRoutes);
2016-08-09 10:47:49 +02:00
ri->showWaypoints(_showRouteWaypoints);
ri->showWaypointLabels(_showWaypointLabels);
2016-08-09 01:16:19 +02:00
_scene->addItem(ri);
2016-09-19 00:56:10 +02:00
2016-10-08 14:53:10 +02:00
if (_poi)
addPOI(_poi->points(ri));
2016-09-19 00:56:10 +02:00
return ri;
2016-08-09 01:16:19 +02:00
}
2016-09-26 21:01:58 +02:00
void PathView::addWaypoints(const QList<Waypoint> &waypoints)
2016-03-15 01:20:24 +01:00
{
for (int i = 0; i < waypoints.count(); i++) {
2016-03-19 09:06:43 +01:00
const Waypoint &w = waypoints.at(i);
2016-03-15 01:20:24 +01:00
WaypointItem *wi = new WaypointItem(w);
2016-08-02 00:28:56 +02:00
wi->setScale(1.0/_scale);
2016-03-15 01:20:24 +01:00
wi->setZValue(1);
2016-08-09 01:16:19 +02:00
wi->showLabel(_showWaypointLabels);
wi->setVisible(_showWaypoints);
2016-03-15 01:20:24 +01:00
_scene->addItem(wi);
_waypoints.append(wi);
2016-03-15 01:20:24 +01:00
}
2016-10-08 14:53:10 +02:00
if (_poi)
addPOI(_poi->points(waypoints));
2016-03-15 01:20:24 +01:00
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
_scale = mapScale(_zoom);
}
2016-09-26 21:01:58 +02:00
QList<PathItem *> PathView::loadGPX(const GPX &gpx)
2016-03-03 09:15:56 +01:00
{
2016-09-19 00:56:10 +02:00
QList<PathItem *> paths;
2016-03-15 01:20:24 +01:00
int zoom = _zoom;
for (int i = 0; i < gpx.tracks().count(); i++)
paths.append(addTrack(*(gpx.tracks().at(i))));
for (int i = 0; i < gpx.routes().count(); i++)
paths.append(addRoute(*(gpx.routes().at(i))));
2016-03-15 01:20:24 +01:00
addWaypoints(gpx.waypoints());
2016-08-09 01:16:19 +02:00
if (_tracks.empty() && _routes.empty() && _waypoints.empty())
2016-09-19 00:56:10 +02:00
return paths;
2016-03-15 01:20:24 +01:00
2016-09-26 10:09:56 +02:00
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom))
2016-03-03 09:15:56 +01:00
rescale(_scale);
2016-10-08 14:53:10 +02:00
else
updatePOIVisibility();
2016-08-09 01:16:19 +02:00
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
2016-03-03 09:15:56 +01:00
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
centerOn(ba.center());
2016-09-11 17:15:23 +02:00
_mapScale->setZoom(_zoom, -(br.center().ry() * _scale));
2016-03-03 09:15:56 +01:00
if (_mapScale->scene() != _scene)
_scene->addItem(_mapScale);
2016-09-19 00:56:10 +02:00
return paths;
}
2016-09-26 21:01:58 +02:00
QRectF PathView::trackBoundingRect() const
{
2016-08-09 01:16:19 +02:00
if (_tracks.empty())
return QRectF();
QRectF br = _tracks.at(0)->sceneBoundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->sceneBoundingRect();
return br;
}
2016-09-26 21:01:58 +02:00
QRectF PathView::routeBoundingRect() const
2016-08-09 01:16:19 +02:00
{
if (_routes.empty())
2016-03-03 09:15:56 +01:00
return QRectF();
2016-08-09 01:16:19 +02:00
QRectF br = _routes.at(0)->sceneBoundingRect();
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->sceneBoundingRect();
return br;
}
2016-09-26 21:01:58 +02:00
QRectF PathView::waypointBoundingRect() const
2016-03-15 01:20:24 +01:00
{
qreal bottom, top, left, right;
if (_waypoints.empty())
2016-03-15 01:20:24 +01:00
return QRectF();
const QPointF &p = _waypoints.at(0)->pos();
bottom = p.y();
top = p.y();
left = p.x();
right = p.x();
for (int i = 1; i < _waypoints.size(); i++) {
const QPointF &p = _waypoints.at(i)->pos();
bottom = qMax(bottom, p.y());
top = qMin(top, p.y());
right = qMax(right, p.x());
left = qMin(left, p.x());
2016-03-15 01:20:24 +01:00
}
return QRectF(QPointF(left, top), QPointF(right, bottom));
}
2016-09-26 21:01:58 +02:00
qreal PathView::trackScale() const
{
2016-08-09 01:16:19 +02:00
if (_tracks.empty())
return mapScale(ZOOM_MAX);
QRectF br = _tracks.at(0)->path().boundingRect();
for (int i = 1; i < _tracks.size(); i++)
br |= _tracks.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
2016-09-26 21:01:58 +02:00
qreal PathView::routeScale() const
2016-08-09 01:16:19 +02:00
{
if (_routes.empty())
2016-03-15 01:20:24 +01:00
return mapScale(ZOOM_MAX);
2016-08-09 01:16:19 +02:00
QRectF br = _routes.at(0)->path().boundingRect();
2016-08-09 01:16:19 +02:00
for (int i = 1; i < _routes.size(); i++)
br |= _routes.at(i)->path().boundingRect();
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
2016-09-26 21:01:58 +02:00
qreal PathView::waypointScale() const
{
2016-03-15 01:20:24 +01:00
qreal bottom, top, left, right;
if (_waypoints.size() < 2)
2016-03-15 01:20:24 +01:00
return mapScale(ZOOM_MAX);
const QPointF &p = _waypoints.at(0)->coordinates();
bottom = p.y();
top = p.y();
left = p.x();
right = p.x();
for (int i = 1; i < _waypoints.size(); i++) {
const QPointF &p = _waypoints.at(i)->coordinates();
bottom = qMax(bottom, p.y());
top = qMin(top, p.y());
right = qMax(right, p.x());
left = qMin(left, p.x());
2016-03-15 01:20:24 +01:00
}
QRectF br(QPointF(left, top), QPointF(right, bottom));
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
2016-09-26 21:01:58 +02:00
qreal PathView::mapScale(int zoom) const
2016-03-15 01:20:24 +01:00
{
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
}
2016-10-08 14:53:10 +02:00
void PathView::updatePOIVisibility()
{
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
2016-10-08 14:53:10 +02:00
if (!_showPOI)
return;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->show();
if (!_overlapPOIs) {
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it.value()->isVisible() && jt.value()->isVisible()
&& it != jt && it.value()->collidesWithItem(jt.value()))
jt.value()->hide();
}
}
}
}
2016-09-26 21:01:58 +02:00
void PathView::rescale(qreal scale)
{
2016-10-08 14:53:10 +02:00
_scale = scale;
2016-08-09 01:16:19 +02:00
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->setScale(1.0/scale);
for (int i = 0; i < _waypoints.size(); i++)
2016-08-02 00:28:56 +02:00
_waypoints.at(i)->setScale(1.0/scale);
2016-03-15 01:20:24 +01:00
QHash<Waypoint, WaypointItem*>::const_iterator it;
2016-10-08 14:53:10 +02:00
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
2016-08-02 00:28:56 +02:00
it.value()->setScale(1.0/scale);
2016-10-08 14:53:10 +02:00
updatePOIVisibility();
}
void PathView::setPOI(POI *poi)
{
2016-10-09 23:46:30 +02:00
if (_poi)
2016-10-11 00:19:42 +02:00
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
2016-10-09 23:46:30 +02:00
2016-10-08 14:53:10 +02:00
_poi = poi;
2016-10-09 23:46:30 +02:00
if (_poi)
2016-10-11 00:19:42 +02:00
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
updatePOI();
2016-10-08 14:53:10 +02:00
}
2016-10-09 23:46:30 +02:00
void PathView::updatePOI()
2016-10-08 14:53:10 +02:00
{
2016-10-09 23:46:30 +02:00
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
_scene->removeItem(it.value());
delete it.value();
}
_pois.clear();
2016-10-08 14:53:10 +02:00
if (!_poi)
return;
for (int i = 0; i < _tracks.size(); i++)
addPOI(_poi->points(_tracks.at(i)));
for (int i = 0; i < _routes.size(); i++)
addPOI(_poi->points(_routes.at(i)));
addPOI(_poi->points(_waypoints));
updatePOIVisibility();
}
2016-09-26 21:01:58 +02:00
void PathView::addPOI(const QVector<Waypoint> &waypoints)
{
for (int i = 0; i < waypoints.size(); i++) {
2016-03-19 09:06:43 +01:00
const Waypoint &w = waypoints.at(i);
if (_pois.contains(w))
continue;
WaypointItem *pi = new WaypointItem(w);
2016-08-02 00:28:56 +02:00
pi->setScale(1.0/_scale);
pi->setZValue(1);
2016-08-09 01:16:19 +02:00
pi->showLabel(_showPOILabels);
2016-10-08 14:53:10 +02:00
pi->setVisible(_showPOI);
_scene->addItem(pi);
2016-03-19 09:06:43 +01:00
_pois.insert(w, pi);
}
}
2016-09-26 21:01:58 +02:00
void PathView::setMap(Map *map)
{
if (_map)
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
resetCachedContent();
}
2016-09-26 21:01:58 +02:00
void PathView::setUnits(enum Units units)
{
2016-07-25 19:32:36 +02:00
_units = units;
_mapScale->setUnits(units);
2016-07-25 19:32:36 +02:00
2016-08-09 01:16:19 +02:00
for (int i = 0; i < _tracks.count(); i++)
_tracks[i]->setUnits(units);
for (int i = 0; i < _routes.count(); i++)
_routes[i]->setUnits(units);
2016-08-02 00:28:56 +02:00
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->setUnits(units);
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setUnits(units);
}
2016-09-26 21:01:58 +02:00
void PathView::redraw()
{
resetCachedContent();
}
2016-09-26 21:01:58 +02:00
void PathView::rescale()
2016-04-05 09:10:19 +02:00
{
2016-08-09 01:16:19 +02:00
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale()));
2016-04-05 09:10:19 +02:00
rescale(mapScale(_zoom));
_mapScale->setZoom(_zoom);
}
2016-09-26 21:01:58 +02:00
void PathView::zoom(int z, const QPointF &pos)
{
2016-08-09 01:16:19 +02:00
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
qreal scale = _scale;
_zoom = z;
2016-03-15 01:20:24 +01:00
rescale(mapScale(_zoom));
2016-08-09 01:16:19 +02:00
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
_scene->setSceneRect(ba);
if (br.width() < viewport()->size().width()
&& br.height() < viewport()->size().height())
centerOn(br.center());
else
centerOn(pos * scale/_scale);
_mapScale->setZoom(_zoom);
resetCachedContent();
}
2016-09-26 21:01:58 +02:00
void PathView::wheelEvent(QWheelEvent *event)
{
2016-08-09 01:16:19 +02:00
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
QPointF pos = mapToScene(event->pos());
int z = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
zoom(z, pos);
}
2016-09-26 21:01:58 +02:00
void PathView::keyPressEvent(QKeyEvent *event)
{
int z = -1;
if (event->matches(QKeySequence::ZoomIn))
z = qMin(_zoom + 1, ZOOM_MAX);
if (event->matches(QKeySequence::ZoomOut))
z = qMax(_zoom - 1, ZOOM_MIN);
if (z >= 0)
zoom(z, mapToScene(QRect(QPoint(), size()).center()));
else
QWidget::keyPressEvent(event);
}
2016-09-26 21:01:58 +02:00
void PathView::plot(QPainter *painter, const QRectF &target)
{
QRect orig, adj;
qreal ratio, diff;
2016-05-20 22:44:03 +02:00
2016-05-15 13:19:07 +02:00
orig = viewport()->rect();
2016-05-27 22:45:58 +02:00
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
ratio = target.height()/target.width();
2016-05-27 22:45:58 +02:00
diff = (orig.width() * ratio) - orig.height();
adj = orig.adjusted(0, -diff/2, 0, diff/2);
2016-05-27 22:45:58 +02:00
} else {
ratio = target.width() / target.height();
diff = (orig.height() * ratio) - orig.width();
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
}
2016-05-20 22:44:03 +02:00
setUpdatesEnabled(false);
_plot = true;
2016-05-20 22:44:03 +02:00
QPointF pos = _mapScale->pos();
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
render(painter, target, adj);
2016-05-20 22:44:03 +02:00
_mapScale->setPos(pos);
_plot = false;
2016-05-20 22:44:03 +02:00
setUpdatesEnabled(true);
}
2016-09-26 21:01:58 +02:00
void PathView::clear()
{
if (_mapScale->scene() == _scene)
_scene->removeItem(_mapScale);
_pois.clear();
2016-08-09 01:16:19 +02:00
_tracks.clear();
_routes.clear();
_waypoints.clear();
_scene->clear();
2016-03-02 09:34:39 +01:00
_palette.reset();
2016-03-15 01:20:24 +01:00
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
2016-03-03 09:15:56 +01:00
_scene->setSceneRect(QRectF());
}
2016-09-26 21:01:58 +02:00
void PathView::showTracks(bool show)
2016-08-09 01:16:19 +02:00
{
_showTracks = show;
for (int i = 0; i < _tracks.count(); i++)
_tracks.at(i)->setVisible(show);
}
2016-09-26 21:01:58 +02:00
void PathView::showRoutes(bool show)
2016-08-09 01:16:19 +02:00
{
_showRoutes = show;
for (int i = 0; i < _routes.count(); i++)
_routes.at(i)->setVisible(show);
}
2016-09-26 21:01:58 +02:00
void PathView::showWaypoints(bool show)
2016-08-09 01:16:19 +02:00
{
_showWaypoints = show;
for (int i = 0; i < _waypoints.count(); i++)
_waypoints.at(i)->setVisible(show);
}
2016-09-26 21:01:58 +02:00
void PathView::showWaypointLabels(bool show)
2016-08-09 01:16:19 +02:00
{
_showWaypointLabels = show;
for (int i = 0; i < _waypoints.size(); i++)
_waypoints.at(i)->showLabel(show);
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypointLabels(show);
2016-08-09 01:16:19 +02:00
}
2016-09-26 21:01:58 +02:00
void PathView::showRouteWaypoints(bool show)
2016-08-09 10:47:49 +02:00
{
_showRouteWaypoints = show;
for (int i = 0; i < _routes.size(); i++)
_routes.at(i)->showWaypoints(show);
}
2016-10-08 14:53:10 +02:00
void PathView::showPOI(bool show)
{
_showPOI = show;
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setVisible(show);
updatePOIVisibility();
}
2016-09-26 21:01:58 +02:00
void PathView::showPOILabels(bool show)
2016-08-09 01:16:19 +02:00
{
_showPOILabels = show;
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->showLabel(show);
2016-10-08 14:53:10 +02:00
updatePOIVisibility();
2016-08-09 01:16:19 +02:00
}
2016-09-26 21:01:58 +02:00
void PathView::setPOIOverlap(bool overlap)
{
2016-08-09 01:16:19 +02:00
_overlapPOIs = overlap;
2016-10-08 14:53:10 +02:00
updatePOIVisibility();
}
2016-09-26 21:01:58 +02:00
void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
2016-08-09 01:16:19 +02:00
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) {
painter->fillRect(rect, Qt::white);
return;
}
QRectF rr(rect.topLeft() * _scale, rect.size());
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
_zoom);
QPointF tm = tile2mercator(tile, _zoom);
2016-05-15 13:19:07 +02:00
QPoint tl = mapToScene(mapFromScene(QPointF(tm.x() / _scale,
-tm.y() / _scale))).toPoint();
QList<Tile> tiles;
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
}
}
_map->loadTiles(tiles, _plot);
for (int i = 0; i < tiles.count(); i++) {
Tile &t = tiles[i];
QPoint tp(tl.x() + (t.xy().x() - tile.x()) * TILE_SIZE,
tl.y() + (t.xy().y() - tile.y()) * TILE_SIZE);
painter->drawPixmap(tp, t.pixmap());
}
}
2016-09-26 21:01:58 +02:00
void PathView::resizeEvent(QResizeEvent *e)
{
2016-08-09 01:16:19 +02:00
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
2016-04-05 09:10:19 +02:00
rescale();
2016-08-09 01:16:19 +02:00
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
QRectF ba = br.adjusted(-TILE_SIZE, -TILE_SIZE, TILE_SIZE, TILE_SIZE);
if (ba.width() < e->size().width()) {
qreal diff = e->size().width() - ba.width();
ba.adjust(-diff/2, 0, diff/2, 0);
}
if (ba.height() < e->size().height()) {
qreal diff = e->size().height() - ba.height();
ba.adjust(0, -diff/2, 0, diff/2);
}
_scene->setSceneRect(ba);
centerOn(br.center());
resetCachedContent();
}
2016-09-26 21:01:58 +02:00
void PathView::paintEvent(QPaintEvent *e)
{
2016-05-20 22:44:03 +02:00
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
-(SCALE_OFFSET + _mapScale->boundingRect().height())));
if (_mapScale->pos() != scenePos && !_plot)
_mapScale->setPos(scenePos);
QGraphicsView::paintEvent(e);
}