1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-08 03:03:02 +02:00

Compare commits

..

No commits in common. "c23c4470a791a11c41aab5cfcb62e96a35322a6b" and "466c538e179e742797c7a60bb4e9f96cc7ae6abc" have entirely different histories.

14 changed files with 69 additions and 209 deletions

View File

@ -23,7 +23,6 @@ greaterThan(QT_MAJOR_VERSION, 5) {
CONFIG += object_parallel_to_source CONFIG += object_parallel_to_source
INCLUDEPATH += ./src INCLUDEPATH += ./src
HEADERS += src/common/config.h \ HEADERS += src/common/config.h \
src/GUI/legendentryitem.h \
src/GUI/legenditem.h \ src/GUI/legenditem.h \
src/common/garmin.h \ src/common/garmin.h \
src/common/coordinates.h \ src/common/coordinates.h \
@ -278,7 +277,6 @@ HEADERS += src/common/config.h \
src/data/geojsonparser.h src/data/geojsonparser.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/GUI/legendentryitem.cpp \
src/GUI/legenditem.cpp \ src/GUI/legenditem.cpp \
src/common/coordinates.cpp \ src/common/coordinates.cpp \
src/common/rectc.cpp \ src/common/rectc.cpp \

View File

@ -178,16 +178,6 @@ void AreaItem::setDigitalZoom(int zoom)
_pen.setWidthF(width() * pow(2, -_digitalZoom)); _pen.setWidthF(width() * pow(2, -_digitalZoom));
} }
void AreaItem::hover(bool hvr)
{
if (hvr)
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom));
else
_pen.setWidthF(_width * pow(2, -_digitalZoom));
update();
}
void AreaItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void AreaItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);

View File

@ -6,8 +6,6 @@
class AreaItem : public PlaneItem class AreaItem : public PlaneItem
{ {
Q_OBJECT
public: public:
AreaItem(const Area &area, Map *map, GraphicsItem *parent = 0); AreaItem(const Area &area, Map *map, GraphicsItem *parent = 0);
@ -33,9 +31,6 @@ public:
const QColor color() const {return _pen.color();} const QColor color() const {return _pen.color();}
const QString &name() const {return _area.name();} const QString &name() const {return _area.name();}
public slots:
void hover(bool hvr);
protected: protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);

View File

@ -1,72 +0,0 @@
#include <QPainter>
#include <QCursor>
#include "font.h"
#include "legendentryitem.h"
#define PADDING 2
LegendEntryItem::LegendEntryItem(const QColor &color, const QString &text,
QGraphicsItem *parent) : QGraphicsItem(parent), _color(color), _text(text)
{
_textColor = Qt::black;
_font.setPixelSize(FONT_SIZE);
_font.setFamily(FONT_FAMILY);
QFontMetrics fm(_font);
_boundingRect = QRectF(0, 0, FONT_SIZE * 2 + PADDING * 2
+ fm.tightBoundingRect(text).width() + PADDING * 2,
FONT_SIZE + PADDING * 2);
setCursor(Qt::ArrowCursor);
setAcceptHoverEvents(true);
}
void LegendEntryItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
QFontMetrics fm(_font);
painter->setRenderHint(QPainter::Antialiasing, false);
painter->setFont(_font);
painter->setBrush(_color);
painter->setPen(QPen(Qt::black));
painter->drawRect(PADDING, PADDING, FONT_SIZE * 2, FONT_SIZE);
painter->setPen(QPen(_textColor));
painter->drawText(FONT_SIZE * 2 + PADDING * 2 + PADDING,
PADDING + fm.ascent(), _text);
//painter->setPen(Qt::red);
//painter->setBrush(Qt::NoBrush);
//painter->drawRect(boundingRect());
}
void LegendEntryItem::setTextColor(const QColor &color)
{
_textColor = color;
update();
}
void LegendEntryItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_font.setBold(true);
setZValue(zValue() + 1.0);
update();
emit selected(true);
}
void LegendEntryItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
_font.setBold(false);
setZValue(zValue() - 1.0);
update();
emit selected(false);
}

View File

@ -1,36 +0,0 @@
#ifndef LEGENDENTRYITEM_H
#define LEGENDENTRYITEM_H
#include <QObject>
#include <QGraphicsItem>
#include <QFont>
class LegendEntryItem : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
LegendEntryItem(const QColor &color, const QString &text,
QGraphicsItem *parent = 0);
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
void setTextColor(const QColor &color);
signals:
void selected(bool);
private:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
QRectF _boundingRect;
QColor _color, _textColor;
QString _text;
QFont _font;
};
#endif // LEGENDENTRYITEM_H

View File

@ -1,17 +1,17 @@
#include <cmath> #include <cmath>
#include <QPainter> #include <QPainter>
#include <QFileInfo>
#include "font.h" #include "font.h"
#include "pathitem.h"
#include "graphitem.h"
#include "planeitem.h"
#include "legendentryitem.h"
#include "legenditem.h" #include "legenditem.h"
#define PADDING 4
LegendItem::LegendItem(QGraphicsItem *parent) : QGraphicsItem(parent) LegendItem::LegendItem(QGraphicsItem *parent) : QGraphicsItem(parent)
{ {
_color = Qt::black;
_bgColor = Qt::white; _bgColor = Qt::white;
_drawBackground = false; _drawBackground = false;
_font.setPixelSize(FONT_SIZE);
_font.setFamily(FONT_FAMILY);
} }
void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -28,6 +28,21 @@ void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
bc.setAlpha(196); bc.setAlpha(196);
painter->setBrush(QBrush(bc)); painter->setBrush(QBrush(bc));
painter->drawRect(_boundingRect); painter->drawRect(_boundingRect);
painter->setBrush(Qt::NoBrush);
}
QFontMetrics fm(_font);
painter->setFont(_font);
for (int i = 0; i < _items.size(); i++) {
const Item &itm = _items.at(i);
painter->setBrush(itm.color);
painter->setPen(QPen(Qt::black));
painter->drawRect(0, i * (FONT_SIZE + PADDING), FONT_SIZE * 2, FONT_SIZE);
painter->setPen(QPen(_color));
painter->drawText(FONT_SIZE * 2 + PADDING, i * (FONT_SIZE + PADDING)
+ fm.ascent(), itm.text);
} }
//painter->setPen(Qt::red); //painter->setPen(Qt::red);
@ -35,45 +50,23 @@ void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
//painter->drawRect(boundingRect()); //painter->drawRect(boundingRect());
} }
void LegendItem::addItem(PathItem *item) void LegendItem::addItem(const QColor &color, const QString &text)
{ {
prepareGeometryChange(); prepareGeometryChange();
LegendEntryItem *li = new LegendEntryItem(item->color(), _items.append(Item(color, text));
item->name().isEmpty() ? QFileInfo(item->file()).fileName() : item->name(),
this);
li->setPos(0, _items.size() * li->boundingRect().height());
_items.append(li); QFontMetrics fm(_font);
qreal maxWidth = qMax((int)_boundingRect.width() - (FONT_SIZE * 2 + PADDING),
_boundingRect = QRectF(0, 0, qMax(_boundingRect.width(), fm.tightBoundingRect(text).width());
li->boundingRect().width()), _items.size() * li->boundingRect().height()); _boundingRect = QRectF(0, 0, FONT_SIZE * 2 + PADDING + maxWidth,
_items.size() * (FONT_SIZE + PADDING) - (PADDING - 1));
QObject::connect(li, &LegendEntryItem::selected, item, &PathItem::hoverAll);
}
void LegendItem::addItem(PlaneItem *item)
{
if (item->name().isEmpty())
return;
prepareGeometryChange();
LegendEntryItem *li = new LegendEntryItem(item->color(), item->name(), this);
li->setPos(0, _items.size() * li->boundingRect().height());
_items.append(li);
_boundingRect = QRectF(0, 0, qMax(_boundingRect.width(),
li->boundingRect().width()), _items.size() * li->boundingRect().height());
QObject::connect(li, &LegendEntryItem::selected, item, &PlaneItem::hover);
} }
void LegendItem::setColor(const QColor &color) void LegendItem::setColor(const QColor &color)
{ {
for (int i = 0; i < _items.size(); i++) _color = color;
_items.at(i)->setTextColor(color); update();
} }
void LegendItem::setBackgroundColor(const QColor &color) void LegendItem::setBackgroundColor(const QColor &color)
@ -91,8 +84,6 @@ void LegendItem::drawBackground(bool draw)
void LegendItem::clear() void LegendItem::clear()
{ {
prepareGeometryChange(); prepareGeometryChange();
qDeleteAll(_items);
_items.clear(); _items.clear();
_boundingRect = QRectF(); _boundingRect = QRectF();
} }

View File

@ -3,11 +3,7 @@
#include <QGraphicsItem> #include <QGraphicsItem>
class LegendEntryItem; class LegendItem : public QGraphicsItem
class PathItem;
class PlaneItem;
class LegendItem : public QGraphicsItem
{ {
public: public:
LegendItem(QGraphicsItem *parent = 0); LegendItem(QGraphicsItem *parent = 0);
@ -16,18 +12,27 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
void addItem(PathItem *item);
void addItem(PlaneItem *item);
void setDigitalZoom(qreal zoom); void setDigitalZoom(qreal zoom);
void addItem(const QColor &color, const QString &text);
void setColor(const QColor &color); void setColor(const QColor &color);
void setBackgroundColor(const QColor &color); void setBackgroundColor(const QColor &color);
void drawBackground(bool draw); void drawBackground(bool draw);
void clear(); void clear();
private: private:
QList<LegendEntryItem*> _items; struct Item
{
Item(const QColor &color, const QString &text)
: color(color), text(text) {}
QColor color;
QString text;
};
QList<Item> _items;
QRectF _boundingRect; QRectF _boundingRect;
QColor _bgColor; QColor _color, _bgColor;
QFont _font;
bool _drawBackground; bool _drawBackground;
}; };

View File

@ -205,16 +205,6 @@ void MapItem::setDigitalZoom(int zoom)
_pen.setWidthF(_width * pow(2, -_digitalZoom)); _pen.setWidthF(_width * pow(2, -_digitalZoom));
} }
void MapItem::hover(bool hvr)
{
if (hvr)
_pen.setWidthF((_width + 1) * pow(2, -_digitalZoom));
else
_pen.setWidthF(_width * pow(2, -_digitalZoom));
update();
}
void MapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) void MapItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);

View File

@ -6,7 +6,7 @@
class MapAction; class MapAction;
class Projection; class Projection;
class MapItem : public PlaneItem class MapItem : public QObject, public PlaneItem
{ {
Q_OBJECT Q_OBJECT
@ -32,9 +32,6 @@ public:
const QColor color() const {return _pen.color();} const QColor color() const {return _pen.color();}
const QString &name() const {return _name;} const QString &name() const {return _name;}
public slots:
void hover(bool hvr);
signals: signals:
void triggered(); void triggered();

View File

@ -153,18 +153,30 @@ void MapView::updateLegend()
if (_showTracks) { if (_showTracks) {
for (int i = 0; i < _tracks.size(); i++) for (int i = 0; i < _tracks.size(); i++)
_legend->addItem(_tracks.at(i)); addLegendEntry(_tracks.at(i));
} }
if (_showRoutes) { if (_showRoutes) {
for (int i = 0; i < _routes.size(); i++) for (int i = 0; i < _routes.size(); i++)
_legend->addItem(_routes.at(i)); addLegendEntry(_routes.at(i));
} }
if (_showAreas) { if (_showAreas) {
for (int i = 0; i < _areas.size(); i++) for (int i = 0; i < _areas.size(); i++)
_legend->addItem(_areas.at(i)); addLegendEntry(_areas.at(i));
} }
} }
void MapView::addLegendEntry(const PathItem *ti)
{
_legend->addItem(ti->color(), ti->name().isEmpty()
? QFileInfo(ti->file()).fileName() : ti->name());
}
void MapView::addLegendEntry(const PlaneItem *plane)
{
if (!plane->name().isEmpty())
_legend->addItem(plane->color(), plane->name());
}
PathItem *MapView::addTrack(const Track &track) PathItem *MapView::addTrack(const Track &track)
{ {
if (!track.isValid()) { if (!track.isValid()) {
@ -192,7 +204,7 @@ PathItem *MapView::addTrack(const Track &track)
if (_showTracks) { if (_showTracks) {
addPOI(_poi->points(ti->path())); addPOI(_poi->points(ti->path()));
_legend->addItem(ti); addLegendEntry(ti);
} }
return ti; return ti;
@ -226,7 +238,7 @@ PathItem *MapView::addRoute(const Route &route)
if (_showRoutes) { if (_showRoutes) {
addPOI(_poi->points(ri->path())); addPOI(_poi->points(ri->path()));
_legend->addItem(ri); addLegendEntry(ri);
} }
return ri; return ri;
@ -254,7 +266,7 @@ void MapView::addArea(const Area &area)
if (_showAreas) { if (_showAreas) {
addPOI(_poi->points(ai->bounds())); addPOI(_poi->points(ai->bounds()));
_legend->addItem(ai); addLegendEntry(ai);
} }
} }
@ -297,7 +309,7 @@ MapItem *MapView::addMap(MapAction *map)
if (_showAreas) { if (_showAreas) {
addPOI(_poi->points(mi->bounds())); addPOI(_poi->points(mi->bounds()));
_legend->addItem(mi); addLegendEntry(mi);
} }
return mi; return mi;

View File

@ -168,6 +168,8 @@ private:
void pinchGesture(QPinchGesture *gesture); void pinchGesture(QPinchGesture *gesture);
void skipColor() {_palette.nextColor();} void skipColor() {_palette.nextColor();}
void setHidpi(bool hidpi); void setHidpi(bool hidpi);
void addLegendEntry(const PathItem *path);
void addLegendEntry(const PlaneItem *plane);
void updateLegend(); void updateLegend();
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);

View File

@ -388,9 +388,9 @@ void PathItem::drawMarkerBackground(bool draw)
_markerInfo->drawBackground(draw); _markerInfo->drawBackground(draw);
} }
void PathItem::hover(bool hvr) void PathItem::hover(bool hover)
{ {
if (hvr) { if (hover) {
_pen.setWidth((width() + 1) * pow(2, -_digitalZoom)); _pen.setWidth((width() + 1) * pow(2, -_digitalZoom));
setZValue(zValue() + 1.0); setZValue(zValue() + 1.0);
} else { } else {
@ -401,12 +401,6 @@ void PathItem::hover(bool hvr)
update(); update();
} }
void PathItem::hoverAll(bool hvr)
{
hover(hvr);
emit selected(hvr);
}
void PathItem::showMarker(bool show) void PathItem::showMarker(bool show)
{ {
if (_showMarker == show) if (_showMarker == show)

View File

@ -60,8 +60,7 @@ public:
static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;}
public slots: public slots:
void hover(bool hvr); void hover(bool hover);
void hoverAll(bool hvr);
signals: signals:
void selected(bool); void selected(bool);

View File

@ -6,10 +6,8 @@
class Map; class Map;
class PlaneItem : public QObject, public GraphicsItem class PlaneItem : public GraphicsItem
{ {
Q_OBJECT
public: public:
PlaneItem(GraphicsItem *parent = 0) : GraphicsItem(parent) {} PlaneItem(GraphicsItem *parent = 0) : GraphicsItem(parent) {}
@ -25,9 +23,6 @@ public:
virtual const QColor color() const = 0; virtual const QColor color() const = 0;
virtual const QString &name() const = 0; virtual const QString &name() const = 0;
public slots:
virtual void hover(bool hvr) = 0;
}; };
#endif // PLANEITEM_H #endif // PLANEITEM_H