diff --git a/gpxsee.pro b/gpxsee.pro
index a7ec97b3..bb059a35 100644
--- a/gpxsee.pro
+++ b/gpxsee.pro
@@ -28,7 +28,6 @@ HEADERS += src/config.h \
src/units.h \
src/scaleitem.h \
src/waypoint.h \
- src/trackview.h \
src/track.h \
src/graphview.h \
src/trackpoint.h \
@@ -52,7 +51,8 @@ HEADERS += src/config.h \
src/routeitem.h \
src/graphitem.h \
src/graph.h \
- src/pathitem.h
+ src/pathitem.h \
+ src/pathview.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@@ -71,7 +71,6 @@ SOURCES += src/main.cpp \
src/maplist.cpp \
src/downloader.cpp \
src/scaleitem.cpp \
- src/trackview.cpp \
src/track.cpp \
src/graphview.cpp \
src/waypointitem.cpp \
@@ -90,7 +89,9 @@ SOURCES += src/main.cpp \
src/tooltip.cpp \
src/route.cpp \
src/routeitem.cpp \
- src/graphitem.cpp
+ src/graphitem.cpp \
+ src/pathitem.cpp \
+ src/pathview.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx {
diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts
index b14809e2..dff373c4 100644
--- a/lang/gpxsee_cs.ts
+++ b/lang/gpxsee_cs.ts
@@ -10,7 +10,7 @@
Výška
-
+
m
m
@@ -30,7 +30,7 @@
Minimum
-
+
ft
ft
@@ -156,7 +156,7 @@
Otevřít soubor
-
+
Open POI file
Otevřít POI soubor
@@ -363,23 +363,23 @@
Předchozí mapa
-
-
+
+
Date
Datum
-
+
Routes
Trasy
-
+
No GPX files loaded
Nejsou načteny žádné GPX soubory
-
+
%1 files
%1 souborů
@@ -404,7 +404,7 @@
Exportovat do PDF...
-
+
Waypoints
Navigační body
@@ -454,18 +454,18 @@
Soubory GPX (*.gpx);;Všechny soubory (*)
-
-
+
+
Line: %1
Řádka: %1
-
+
GPX files (*.gpx);;CSV files (*.csv);;All files (*)
Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)
-
+
Tracks
Cesty
@@ -492,31 +492,31 @@
-
+
Distance
Vzdálenost
-
+
Time
Čas
-
-
+
+
Error
Chyba
-
+
Error loading GPX file:
%1
Soubor GPX nelze otevřít:
%1
-
+
Error loading POI file:
%1
Soubor POI nelze otevřít:
@@ -526,47 +526,47 @@
GraphView
-
+
m
m
-
+
km
km
-
+
ft
ft
-
+
mi
mi
-
+
s
s
-
+
min
min
-
+
h
h
-
+
Distance
Vzdálenost
-
+
Time
Čas
@@ -623,7 +623,7 @@
RouteItem
-
+
Distance
Vzdálenost
@@ -631,22 +631,22 @@
ScaleItem
-
+
mi
mi
-
+
ft
ft
-
+
km
km
-
+
m
m
@@ -717,17 +717,17 @@
TrackItem
-
+
Distance
Vzdálenost
-
+
Time
Čas
-
+
Date
Datum
diff --git a/src/gui.cpp b/src/gui.cpp
index 40ab159d..332c36c3 100644
--- a/src/gui.cpp
+++ b/src/gui.cpp
@@ -30,7 +30,7 @@
#include "speedgraph.h"
#include "heartrategraph.h"
#include "temperaturegraph.h"
-#include "trackview.h"
+#include "pathview.h"
#include "trackinfo.h"
#include "filebrowser.h"
#include "cpuarch.h"
@@ -56,7 +56,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_browser->setFilter(QStringList("*.gpx"));
QVBoxLayout *layout = new QVBoxLayout;
- layout->addWidget(_track);
+ layout->addWidget(_pathView);
layout->addWidget(_trackGraphs);
layout->setContentsMargins(0, 0, 0, 0);
#ifdef Q_OS_WIN32
@@ -238,11 +238,11 @@ void GUI::createActions()
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_overlapPOIAction = new QAction(tr("Overlap POIs"), this);
_overlapPOIAction->setCheckable(true);
- connect(_overlapPOIAction, SIGNAL(triggered(bool)), _track,
+ connect(_overlapPOIAction, SIGNAL(triggered(bool)), _pathView,
SLOT(setPOIOverlap(bool)));
_showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setCheckable(true);
- connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _track,
+ connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showPOILabels(bool)));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show POIs"), this);
@@ -289,15 +289,15 @@ void GUI::createActions()
SLOT(showRoutes(bool)));
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
_showWaypointsAction->setCheckable(true);
- connect(_showWaypointsAction, SIGNAL(triggered(bool)), _track,
+ connect(_showWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypoints(bool)));
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
_showWaypointLabelsAction->setCheckable(true);
- connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _track,
+ connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showWaypointLabels(bool)));
_showRouteWaypointsAction = new QAction(tr("Route waypoints"), this);
_showRouteWaypointsAction->setCheckable(true);
- connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _track,
+ connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showRouteWaypoints(bool)));
// Graph actions
@@ -457,7 +457,7 @@ void GUI::createToolBars()
void GUI::createTrackView()
{
- _track = new TrackView(this);
+ _pathView = new PathView(this);
#ifdef Q_OS_WIN32
_track->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32
@@ -615,13 +615,13 @@ bool GUI::loadFile(const QString &fileName)
QList paths;
if (gpx.loadFile(fileName)) {
- paths = _track->loadGPX(gpx);
+ paths = _pathView->loadGPX(gpx);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->loadGPX(gpx, paths);
updateGraphTabs();
- _track->setHidden(false);
+ _pathView->setHidden(false);
if (_showPOIAction->isChecked())
- _track->loadPOI(_poi);
+ _pathView->loadPOI(_poi);
for (int i = 0; i < gpx.tracks().count(); i++) {
_trackDistance += gpx.tracks().at(i)->distance();
@@ -678,7 +678,7 @@ bool GUI::openPOIFile(const QString &fileName)
return false;
} else {
_showPOIAction->setChecked(true);
- _track->loadPOI(_poi);
+ _pathView->loadPOI(_poi);
QAction *action = createPOIFileAction(_poi.files().indexOf(fileName));
action->setChecked(true);
_poiFilesMenu->addAction(action);
@@ -695,7 +695,7 @@ void GUI::closePOIFiles()
delete _poiFilesActions[i];
_poiFilesActions.clear();
- _track->clearPOI();
+ _pathView->clearPOI();
_poi.clear();
}
@@ -784,7 +784,7 @@ void GUI::plot(QPrinter *printer)
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
} else
gh = 0;
- _track->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
+ _pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
- (ih + 2*mh + gh)));
}
@@ -800,7 +800,7 @@ void GUI::reloadFile()
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear();
- _track->clear();
+ _pathView->clear();
_sliderPos = 0;
@@ -835,7 +835,7 @@ void GUI::closeFiles()
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear();
- _track->clear();
+ _pathView->clear();
_files.clear();
}
@@ -854,17 +854,17 @@ void GUI::closeAll()
void GUI::showPOI(bool checked)
{
if (checked)
- _track->loadPOI(_poi);
+ _pathView->loadPOI(_poi);
else
- _track->clearPOI();
+ _pathView->clearPOI();
}
void GUI::showMap(bool checked)
{
if (checked)
- _track->setMap(_currentMap);
+ _pathView->setMap(_currentMap);
else
- _track->setMap(0);
+ _pathView->setMap(0);
}
void GUI::showGraphs(bool checked)
@@ -891,7 +891,7 @@ void GUI::showToolbars(bool checked)
void GUI::showFullscreen(bool checked)
{
if (checked) {
- _frameStyle = _track->frameStyle();
+ _frameStyle = _pathView->frameStyle();
_showGraphs = _showGraphsAction->isChecked();
statusBar()->hide();
@@ -899,7 +899,7 @@ void GUI::showFullscreen(bool checked)
showToolbars(false);
showGraphs(false);
_showGraphsAction->setChecked(false);
- _track->setFrameStyle(QFrame::NoFrame);
+ _pathView->setFrameStyle(QFrame::NoFrame);
showFullScreen();
} else {
@@ -910,7 +910,7 @@ void GUI::showFullscreen(bool checked)
_showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs);
- _track->setFrameStyle(_frameStyle);
+ _pathView->setFrameStyle(_frameStyle);
showNormal();
}
@@ -918,7 +918,7 @@ void GUI::showFullscreen(bool checked)
void GUI::showTracks(bool show)
{
- _track->showTracks(show);
+ _pathView->showTracks(show);
for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showTracks(show);
@@ -928,7 +928,7 @@ void GUI::showTracks(bool show)
void GUI::showRoutes(bool show)
{
- _track->showRoutes(show);
+ _pathView->showRoutes(show);
for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showRoutes(show);
@@ -939,7 +939,7 @@ void GUI::showRoutes(bool show)
void GUI::clearMapCache()
{
_currentMap->clearCache();
- _track->redraw();
+ _pathView->redraw();
}
void GUI::updateStatusBarInfo()
@@ -979,7 +979,7 @@ void GUI::mapChanged(int index)
_currentMap = _maps.at(index);
if (_showMapAction->isChecked())
- _track->setMap(_currentMap);
+ _pathView->setMap(_currentMap);
}
void GUI::nextMap()
@@ -1005,9 +1005,9 @@ void GUI::poiFileChecked(int index)
_poi.enableFile(_poi.files().at(index),
_poiFilesActions.at(index)->isChecked());
- _track->clearPOI();
+ _pathView->clearPOI();
if (_showPOIAction->isChecked())
- _track->loadPOI(_poi);
+ _pathView->loadPOI(_poi);
}
void GUI::sliderPositionChanged(qreal pos)
@@ -1072,13 +1072,13 @@ void GUI::updateGraphTabs()
void GUI::updateTrackView()
{
- _track->setHidden(!(_track->trackCount() + _track->routeCount()
- + _track->waypointCount()));
+ _pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount()
+ + _pathView->waypointCount()));
}
void GUI::setUnits(Units units)
{
- _track->setUnits(units);
+ _pathView->setUnits(units);
for (int i = 0; i <_tabs.count(); i++)
_tabs.at(i)->setUnits(units);
updateStatusBarInfo();
@@ -1259,7 +1259,7 @@ void GUI::readSettings()
_mapActions.at(index)->setChecked(true);
_currentMap = _maps.at(index);
if (_showMapAction->isChecked())
- _track->setMap(_currentMap);
+ _pathView->setMap(_currentMap);
} else
_currentMap = 0;
settings.endGroup();
@@ -1278,11 +1278,11 @@ void GUI::readSettings()
settings.beginGroup(POI_SETTINGS_GROUP);
if (settings.value(OVERLAP_POI_SETTING, true).toBool() == false)
- _track->setPOIOverlap(false);
+ _pathView->setPOIOverlap(false);
else
_overlapPOIAction->setChecked(true);
if (settings.value(LABELS_POI_SETTING, true).toBool() == false)
- _track->showPOILabels(false);
+ _pathView->showPOILabels(false);
else
_showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, false).toBool() == true)
@@ -1304,27 +1304,27 @@ void GUI::readSettings()
settings.beginGroup(DATA_SETTINGS_GROUP);
if (settings.value(SHOW_TRACKS_SETTING, true).toBool() == false) {
- _track->showTracks(false);
+ _pathView->showTracks(false);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showTracks(false);
} else
_showTracksAction->setChecked(true);
if (settings.value(SHOW_ROUTES_SETTING, true).toBool() == false) {
- _track->showRoutes(false);
+ _pathView->showRoutes(false);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showRoutes(false);
} else
_showRoutesAction->setChecked(true);
if (settings.value(SHOW_WAYPOINTS_SETTING, true).toBool() == false)
- _track->showWaypoints(false);
+ _pathView->showWaypoints(false);
else
_showWaypointsAction->setChecked(true);
if (settings.value(SHOW_WAYPOINT_LABELS_SETTING, true).toBool() == false)
- _track->showWaypointLabels(false);
+ _pathView->showWaypointLabels(false);
else
_showWaypointLabelsAction->setChecked(true);
if (settings.value(SHOW_ROUTE_WAYPOINTS_SETTING, true).toBool() == false)
- _track->showRouteWaypoints(false);
+ _pathView->showRouteWaypoints(false);
else
_showRouteWaypointsAction->setChecked(true);
settings.endGroup();
diff --git a/src/gui.h b/src/gui.h
index 53806a02..3e46814c 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -21,7 +21,7 @@ class QSignalMapper;
class QPrinter;
class FileBrowser;
class GraphTab;
-class TrackView;
+class PathView;
class Map;
class GUI : public QMainWindow
@@ -162,7 +162,7 @@ private:
QLabel *_distanceLabel;
QLabel *_timeLabel;
- TrackView *_track;
+ PathView *_pathView;
QTabWidget *_trackGraphs;
QList _tabs;
diff --git a/src/pathitem.cpp b/src/pathitem.cpp
new file mode 100644
index 00000000..63d0bd8c
--- /dev/null
+++ b/src/pathitem.cpp
@@ -0,0 +1,104 @@
+#include
+#include
+#include
+#include "tooltip.h"
+#include "pathitem.h"
+
+
+#define PATH_WIDTH 3
+#define HOVER_WIDTH 4
+
+void PathItem::updateShape()
+{
+ QPainterPathStroker s;
+ s.setWidth(HOVER_WIDTH * 1.0/scale());
+ _shape = s.createStroke(_path);
+
+ if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
+ setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+ else
+ setCacheMode(QGraphicsItem::NoCache);
+}
+
+PathItem::PathItem(QGraphicsItem *parent) : QGraphicsObject(parent)
+{
+ QBrush brush(Qt::SolidPattern);
+ _pen = QPen(brush, PATH_WIDTH);
+
+ _units = Metric;
+
+ _marker = new MarkerItem(this);
+
+ setCursor(Qt::ArrowCursor);
+ setAcceptHoverEvents(true);
+}
+
+void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+{
+ Q_UNUSED(option);
+ Q_UNUSED(widget);
+
+ painter->setPen(_pen);
+ painter->drawPath(_path);
+
+/*
+ QPen p = QPen(QBrush(Qt::red), 0);
+ painter->setPen(p);
+ painter->drawRect(boundingRect());
+*/
+}
+
+void PathItem::setScale(qreal scale)
+{
+ prepareGeometryChange();
+
+ _pen.setWidthF(PATH_WIDTH * 1.0/scale);
+ QGraphicsItem::setScale(scale);
+ _marker->setScale(1.0/scale);
+
+ updateShape();
+}
+
+void PathItem::setColor(const QColor &color)
+{
+ _pen.setColor(color);
+ update();
+}
+
+void PathItem::setUnits(enum Units units)
+{
+ _units = units;
+}
+
+void PathItem::moveMarker(qreal distance)
+{
+ if (distance > _distance)
+ _marker->setVisible(false);
+ else {
+ _marker->setVisible(true);
+ _marker->setPos(_path.pointAtPercent(distance / _distance));
+ }
+}
+
+void PathItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+
+ _pen.setWidthF(HOVER_WIDTH * 1.0/scale());
+ setZValue(zValue() + 1.0);
+ update();
+
+ emit selected(true);
+}
+
+void PathItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
+{
+ Q_UNUSED(event);
+
+ _pen.setWidthF(PATH_WIDTH * 1.0/scale());
+ setZValue(zValue() - 1.0);
+ update();
+
+ emit selected(false);
+}
diff --git a/src/pathitem.h b/src/pathitem.h
index 14763c6e..151fe141 100644
--- a/src/pathitem.h
+++ b/src/pathitem.h
@@ -2,21 +2,50 @@
#define PATHITEM_H
#include
+#include
+#include "markeritem.h"
#include "units.h"
+
class PathItem : public QGraphicsObject
{
Q_OBJECT
public:
- PathItem(QGraphicsItem *parent = 0) : QGraphicsObject(parent) {}
- virtual void showMarker(bool show) = 0;
+ PathItem(QGraphicsItem *parent = 0);
+
+ QPainterPath shape() const {return _shape;}
+ QRectF boundingRect() const {return _shape.boundingRect();}
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+
+ const QPainterPath &path() const {return _path;}
+ void showMarker(bool show) {_marker->setVisible(show);}
+ void setScale(qreal scale);
+ void setUnits(enum Units units);
+ void setColor(const QColor &color);
public slots:
- virtual void moveMarker(qreal distance) = 0;
+ void moveMarker(qreal distance);
signals:
void selected(bool);
+
+protected:
+ void updateShape();
+
+ QPainterPath _path;
+ QPainterPath _shape;
+ QPen _pen;
+
+ MarkerItem *_marker;
+
+ Units _units;
+ qreal _distance;
+
+private:
+ void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
+ void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
};
#endif // PATHITEM_H
diff --git a/src/trackview.cpp b/src/pathview.cpp
similarity index 88%
rename from src/trackview.cpp
rename to src/pathview.cpp
index 049cf86b..7924d0ea 100644
--- a/src/trackview.cpp
+++ b/src/pathview.cpp
@@ -9,13 +9,13 @@
#include "routeitem.h"
#include "waypointitem.h"
#include "scaleitem.h"
-#include "trackview.h"
+#include "pathview.h"
#define MARGIN 10.0
#define SCALE_OFFSET 7
-TrackView::TrackView(QWidget *parent)
+PathView::PathView(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new QGraphicsScene(this);
@@ -47,13 +47,13 @@ TrackView::TrackView(QWidget *parent)
_plot = false;
}
-TrackView::~TrackView()
+PathView::~PathView()
{
if (_mapScale->scene() != _scene)
delete _mapScale;
}
-PathItem *TrackView::addTrack(const Track &track)
+PathItem *PathView::addTrack(const Track &track)
{
if (track.isNull()) {
_palette.color();
@@ -72,7 +72,7 @@ PathItem *TrackView::addTrack(const Track &track)
return ti;
}
-PathItem *TrackView::addRoute(const Route &route)
+PathItem *PathView::addRoute(const Route &route)
{
if (route.isNull()) {
_palette.color();
@@ -93,7 +93,7 @@ PathItem *TrackView::addRoute(const Route &route)
return ri;
}
-void TrackView::addWaypoints(const QList &waypoints)
+void PathView::addWaypoints(const QList &waypoints)
{
for (int i = 0; i < waypoints.count(); i++) {
const Waypoint &w = waypoints.at(i);
@@ -112,7 +112,7 @@ void TrackView::addWaypoints(const QList &waypoints)
_scale = mapScale(_zoom);
}
-QList TrackView::loadGPX(const GPX &gpx)
+QList PathView::loadGPX(const GPX &gpx)
{
QList paths;
PathItem *pi;
@@ -149,7 +149,7 @@ QList TrackView::loadGPX(const GPX &gpx)
return paths;
}
-QRectF TrackView::trackBoundingRect() const
+QRectF PathView::trackBoundingRect() const
{
if (_tracks.empty())
return QRectF();
@@ -161,7 +161,7 @@ QRectF TrackView::trackBoundingRect() const
return br;
}
-QRectF TrackView::routeBoundingRect() const
+QRectF PathView::routeBoundingRect() const
{
if (_routes.empty())
return QRectF();
@@ -173,7 +173,7 @@ QRectF TrackView::routeBoundingRect() const
return br;
}
-QRectF TrackView::waypointBoundingRect() const
+QRectF PathView::waypointBoundingRect() const
{
qreal bottom, top, left, right;
@@ -197,7 +197,7 @@ QRectF TrackView::waypointBoundingRect() const
return QRectF(QPointF(left, top), QPointF(right, bottom));
}
-qreal TrackView::trackScale() const
+qreal PathView::trackScale() const
{
if (_tracks.empty())
return mapScale(ZOOM_MAX);
@@ -213,7 +213,7 @@ qreal TrackView::trackScale() const
return qMax(sc.x(), sc.y());
}
-qreal TrackView::routeScale() const
+qreal PathView::routeScale() const
{
if (_routes.empty())
return mapScale(ZOOM_MAX);
@@ -229,7 +229,7 @@ qreal TrackView::routeScale() const
return qMax(sc.x(), sc.y());
}
-qreal TrackView::waypointScale() const
+qreal PathView::waypointScale() const
{
qreal bottom, top, left, right;
@@ -257,12 +257,12 @@ qreal TrackView::waypointScale() const
return qMax(sc.x(), sc.y());
}
-qreal TrackView::mapScale(int zoom) const
+qreal PathView::mapScale(int zoom) const
{
return ((360.0/(qreal)(1<::const_iterator it, jt;
@@ -275,7 +275,7 @@ void TrackView::checkPOIOverlap()
}
}
-void TrackView::rescale(qreal scale)
+void PathView::rescale(qreal scale)
{
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale);
@@ -298,7 +298,7 @@ void TrackView::rescale(qreal scale)
_scale = scale;
}
-void TrackView::addPOI(const QVector &waypoints)
+void PathView::addPOI(const QVector &waypoints)
{
for (int i = 0; i < waypoints.size(); i++) {
const Waypoint &w = waypoints.at(i);
@@ -316,7 +316,7 @@ void TrackView::addPOI(const QVector &waypoints)
}
}
-void TrackView::loadPOI(const POI &poi)
+void PathView::loadPOI(const POI &poi)
{
if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return;
@@ -331,7 +331,7 @@ void TrackView::loadPOI(const POI &poi)
checkPOIOverlap();
}
-void TrackView::setMap(Map *map)
+void PathView::setMap(Map *map)
{
_map = map;
if (_map)
@@ -340,7 +340,7 @@ void TrackView::setMap(Map *map)
resetCachedContent();
}
-void TrackView::setUnits(enum Units units)
+void PathView::setUnits(enum Units units)
{
_units = units;
@@ -358,12 +358,12 @@ void TrackView::setUnits(enum Units units)
it.value()->setUnits(units);
}
-void TrackView::redraw()
+void PathView::redraw()
{
resetCachedContent();
}
-void TrackView::rescale()
+void PathView::rescale()
{
_zoom = qMin(qMin(scale2zoom(trackScale()), scale2zoom(routeScale())),
scale2zoom(waypointScale()));
@@ -372,7 +372,7 @@ void TrackView::rescale()
_mapScale->setZoom(_zoom);
}
-void TrackView::zoom(int z, const QPointF &pos)
+void PathView::zoom(int z, const QPointF &pos)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
@@ -397,7 +397,7 @@ void TrackView::zoom(int z, const QPointF &pos)
resetCachedContent();
}
-void TrackView::wheelEvent(QWheelEvent *event)
+void PathView::wheelEvent(QWheelEvent *event)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
@@ -409,7 +409,7 @@ void TrackView::wheelEvent(QWheelEvent *event)
zoom(z, pos);
}
-void TrackView::keyPressEvent(QKeyEvent *event)
+void PathView::keyPressEvent(QKeyEvent *event)
{
int z = -1;
@@ -424,7 +424,7 @@ void TrackView::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event);
}
-void TrackView::plot(QPainter *painter, const QRectF &target)
+void PathView::plot(QPainter *painter, const QRectF &target)
{
QRect orig, adj;
qreal ratio, diff;
@@ -458,7 +458,7 @@ void TrackView::plot(QPainter *painter, const QRectF &target)
setUpdatesEnabled(true);
}
-void TrackView::clearPOI()
+void PathView::clearPOI()
{
QHash::const_iterator it;
@@ -470,7 +470,7 @@ void TrackView::clearPOI()
_pois.clear();
}
-void TrackView::clear()
+void PathView::clear()
{
if (_mapScale->scene() == _scene)
_scene->removeItem(_mapScale);
@@ -488,7 +488,7 @@ void TrackView::clear()
_scene->setSceneRect(QRectF());
}
-void TrackView::showTracks(bool show)
+void PathView::showTracks(bool show)
{
_showTracks = show;
@@ -496,7 +496,7 @@ void TrackView::showTracks(bool show)
_tracks.at(i)->setVisible(show);
}
-void TrackView::showRoutes(bool show)
+void PathView::showRoutes(bool show)
{
_showRoutes = show;
@@ -504,7 +504,7 @@ void TrackView::showRoutes(bool show)
_routes.at(i)->setVisible(show);
}
-void TrackView::showWaypoints(bool show)
+void PathView::showWaypoints(bool show)
{
_showWaypoints = show;
@@ -512,7 +512,7 @@ void TrackView::showWaypoints(bool show)
_waypoints.at(i)->setVisible(show);
}
-void TrackView::showWaypointLabels(bool show)
+void PathView::showWaypointLabels(bool show)
{
_showWaypointLabels = show;
@@ -523,7 +523,7 @@ void TrackView::showWaypointLabels(bool show)
_routes.at(i)->showWaypointLabels(show);
}
-void TrackView::showRouteWaypoints(bool show)
+void PathView::showRouteWaypoints(bool show)
{
_showRouteWaypoints = show;
@@ -531,7 +531,7 @@ void TrackView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(show);
}
-void TrackView::showPOILabels(bool show)
+void PathView::showPOILabels(bool show)
{
_showPOILabels = show;
@@ -542,7 +542,7 @@ void TrackView::showPOILabels(bool show)
setPOIOverlap(_overlapPOIs);
}
-void TrackView::setPOIOverlap(bool overlap)
+void PathView::setPOIOverlap(bool overlap)
{
_overlapPOIs = overlap;
@@ -554,7 +554,7 @@ void TrackView::setPOIOverlap(bool overlap)
checkPOIOverlap();
}
-void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
+void PathView::drawBackground(QPainter *painter, const QRectF &rect)
{
if ((_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
|| !_map) {
@@ -586,7 +586,7 @@ void TrackView::drawBackground(QPainter *painter, const QRectF &rect)
}
}
-void TrackView::resizeEvent(QResizeEvent *e)
+void PathView::resizeEvent(QResizeEvent *e)
{
if (_tracks.isEmpty() && _routes.isEmpty() && _waypoints.isEmpty())
return;
@@ -612,7 +612,7 @@ void TrackView::resizeEvent(QResizeEvent *e)
resetCachedContent();
}
-void TrackView::paintEvent(QPaintEvent *e)
+void PathView::paintEvent(QPaintEvent *e)
{
QPointF scenePos = mapToScene(rect().bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
diff --git a/src/trackview.h b/src/pathview.h
similarity index 96%
rename from src/trackview.h
rename to src/pathview.h
index 0ba48946..39b8b8c1 100644
--- a/src/trackview.h
+++ b/src/pathview.h
@@ -20,13 +20,13 @@ class WaypointItem;
class ScaleItem;
class PathItem;
-class TrackView : public QGraphicsView
+class PathView : public QGraphicsView
{
Q_OBJECT
public:
- TrackView(QWidget *parent = 0);
- ~TrackView();
+ PathView(QWidget *parent = 0);
+ ~PathView();
QList loadGPX(const GPX &gpx);
diff --git a/src/routeitem.cpp b/src/routeitem.cpp
index bc1cb968..7cea8dae 100644
--- a/src/routeitem.cpp
+++ b/src/routeitem.cpp
@@ -8,9 +8,6 @@
#include "routeitem.h"
-#define ROUTE_WIDTH 3
-#define HOVER_WIDTH 4
-
QString RouteItem::toolTip()
{
ToolTip tt;
@@ -21,18 +18,6 @@ QString RouteItem::toolTip()
return tt.toString();
}
-void RouteItem::updateShape()
-{
- QPainterPathStroker s;
- s.setWidth(HOVER_WIDTH * 1.0/scale());
- _shape = s.createStroke(_path);
-
- if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
- setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- else
- setCacheMode(QGraphicsItem::NoCache);
-}
-
RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
: PathItem(parent)
{
@@ -48,74 +33,32 @@ RouteItem::RouteItem(const Route &route, QGraphicsItem *parent)
new WaypointItem(r.at(i), this);
}
- _units = Metric;
- _distance = route.distance();
-
- setToolTip(toolTip());
- setCursor(Qt::ArrowCursor);
- setAcceptHoverEvents(true);
-
updateShape();
- QBrush brush(Qt::SolidPattern);
- _pen = QPen(brush, ROUTE_WIDTH, Qt::DotLine);
+ _distance = route.distance();
- _marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0));
-}
-void RouteItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget)
-{
- Q_UNUSED(option);
- Q_UNUSED(widget);
+ _pen.setStyle(Qt::DotLine);
- painter->setPen(_pen);
- painter->drawPath(_path);
-
-/*
- QPen p = QPen(QBrush(Qt::red), 0);
- painter->setPen(p);
- painter->drawRect(boundingRect());
-*/
+ setToolTip(toolTip());
}
void RouteItem::setScale(qreal scale)
{
- prepareGeometryChange();
-
- _pen.setWidthF(ROUTE_WIDTH * 1.0/scale);
- QGraphicsItem::setScale(scale);
-
QList childs = childItems();
for (int i = 0; i < childs.count(); i++)
childs.at(i)->setScale(1.0/scale);
- updateShape();
-}
-
-void RouteItem::setColor(const QColor &color)
-{
- _pen.setColor(color);
- update();
+ PathItem::setScale(scale);
}
void RouteItem::setUnits(enum Units units)
{
- _units = units;
+ PathItem::setUnits(units);
setToolTip(toolTip());
}
-void RouteItem::moveMarker(qreal distance)
-{
- if (distance > _distance)
- _marker->setVisible(false);
- else {
- _marker->setVisible(true);
- _marker->setPos(_path.pointAtPercent(distance / _distance));
- }
-}
-
void RouteItem::showWaypoints(bool show)
{
QList childs = childItems();
@@ -134,25 +77,3 @@ void RouteItem::showWaypointLabels(bool show)
}
}
}
-
-void RouteItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
-{
- Q_UNUSED(event);
-
- _pen.setWidthF(HOVER_WIDTH * 1.0/scale());
- setZValue(zValue() + 1.0);
- update();
-
- emit selected(true);
-}
-
-void RouteItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
-{
- Q_UNUSED(event);
-
- _pen.setWidthF(ROUTE_WIDTH * 1.0/scale());
- setZValue(zValue() - 1.0);
- update();
-
- emit selected(false);
-}
diff --git a/src/routeitem.h b/src/routeitem.h
index e987b8de..62ea4fdd 100644
--- a/src/routeitem.h
+++ b/src/routeitem.h
@@ -1,11 +1,8 @@
#ifndef ROUTEITEM_H
#define ROUTEITEM_H
-#include
#include "pathitem.h"
-#include "markeritem.h"
#include "route.h"
-#include "units.h"
class RouteItem : public PathItem
@@ -15,38 +12,14 @@ class RouteItem : public PathItem
public:
RouteItem(const Route &route, QGraphicsItem *parent = 0);
- QPainterPath shape() const {return _shape;}
- QRectF boundingRect() const {return _shape.boundingRect();}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget);
-
- const QPainterPath &path() const {return _path;}
-
- void setScale(qreal scale);
- void setColor(const QColor &color);
void setUnits(enum Units units);
-
- void showMarker(bool show) {_marker->setVisible(show);}
- void moveMarker(qreal distance);
+ void setScale(qreal scale);
void showWaypoints(bool show);
void showWaypointLabels(bool show);
private:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
-
- void updateShape();
QString toolTip();
-
- QPainterPath _path;
- QPainterPath _shape;
- QPen _pen;
-
- MarkerItem *_marker;
-
- Units _units;
- qreal _distance;
};
#endif // ROUTEITEM_H
diff --git a/src/trackitem.cpp b/src/trackitem.cpp
index 9d095d17..cc065f4d 100644
--- a/src/trackitem.cpp
+++ b/src/trackitem.cpp
@@ -7,9 +7,6 @@
#include "trackitem.h"
-#define TRACK_WIDTH 3
-#define HOVER_WIDTH 4
-
QString TrackItem::toolTip()
{
ToolTip tt;
@@ -25,18 +22,6 @@ QString TrackItem::toolTip()
return tt.toString();
}
-void TrackItem::updateShape()
-{
- QPainterPathStroker s;
- s.setWidth(HOVER_WIDTH * 1.0/scale());
- _shape = s.createStroke(_path);
-
- if (qMax(boundingRect().width(), boundingRect().height()) * scale() <= 768)
- setCacheMode(QGraphicsItem::DeviceCoordinateCache);
- else
- setCacheMode(QGraphicsItem::NoCache);
-}
-
TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
: PathItem(parent)
{
@@ -50,91 +35,19 @@ TrackItem::TrackItem(const Track &track, QGraphicsItem *parent)
_path.lineTo(ll2mercator(QPointF(p.x(), -p.y())));
}
- _units = Metric;
+ updateShape();
+
_date = track.date();
_distance = track.distance();
_time = track.time();
- setToolTip(toolTip());
- setCursor(Qt::ArrowCursor);
- setAcceptHoverEvents(true);
-
- updateShape();
-
- QBrush brush(Qt::SolidPattern);
- _pen = QPen(brush, TRACK_WIDTH);
-
- _marker = new MarkerItem(this);
_marker->setPos(_path.pointAtPercent(0));
-}
-void TrackItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget)
-{
- Q_UNUSED(option);
- Q_UNUSED(widget);
-
- painter->setPen(_pen);
- painter->drawPath(_path);
-
-/*
- QPen p = QPen(QBrush(Qt::red), 0);
- painter->setPen(p);
- painter->drawRect(boundingRect());
-*/
-}
-
-void TrackItem::setScale(qreal scale)
-{
- prepareGeometryChange();
-
- _pen.setWidthF(TRACK_WIDTH * 1.0/scale);
- QGraphicsItem::setScale(scale);
- _marker->setScale(1.0/scale);
-
- updateShape();
-}
-
-void TrackItem::setColor(const QColor &color)
-{
- _pen.setColor(color);
- update();
+ setToolTip(toolTip());
}
void TrackItem::setUnits(enum Units units)
{
- _units = units;
+ PathItem::setUnits(units);
setToolTip(toolTip());
}
-
-void TrackItem::moveMarker(qreal distance)
-{
- if (distance > _distance)
- _marker->setVisible(false);
- else {
- _marker->setVisible(true);
- _marker->setPos(_path.pointAtPercent(distance / _distance));
- }
-}
-
-void TrackItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
-{
- Q_UNUSED(event);
-
- _pen.setWidthF(HOVER_WIDTH * 1.0/scale());
- setZValue(zValue() + 1.0);
- update();
-
- emit selected(true);
-}
-
-void TrackItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
-{
- Q_UNUSED(event);
-
- _pen.setWidthF(TRACK_WIDTH * 1.0/scale());
- setZValue(zValue() - 1.0);
- update();
-
- emit selected(false);
-}
diff --git a/src/trackitem.h b/src/trackitem.h
index 11e694fd..d0c1d5dd 100644
--- a/src/trackitem.h
+++ b/src/trackitem.h
@@ -3,10 +3,8 @@
#include
#include
-#include "pathitem.h"
-#include "units.h"
#include "track.h"
-#include "markeritem.h"
+#include "pathitem.h"
class TrackItem : public PathItem
@@ -16,37 +14,13 @@ class TrackItem : public PathItem
public:
TrackItem(const Track &track, QGraphicsItem *parent = 0);
- QPainterPath shape() const {return _shape;}
- QRectF boundingRect() const {return _shape.boundingRect();}
- void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
- QWidget *widget);
-
- const QPainterPath &path() const {return _path;}
-
- void setScale(qreal scale);
void setUnits(enum Units units);
- void setColor(const QColor &color);
-
- void showMarker(bool show) {_marker->setVisible(show);}
- void moveMarker(qreal distance);
private:
- void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
- void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
-
- void updateShape();
QString toolTip();
- QPainterPath _path;
- QPainterPath _shape;
- QPen _pen;
-
- MarkerItem *_marker;
-
- Units _units;
QDateTime _date;
qreal _time;
- qreal _distance;
};
#endif // TRACKITEM_H