mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-07 18:53:02 +02:00
Compare commits
No commits in common. "c23c4470a791a11c41aab5cfcb62e96a35322a6b" and "466c538e179e742797c7a60bb4e9f96cc7ae6abc" have entirely different histories.
c23c4470a7
...
466c538e17
@ -23,7 +23,6 @@ greaterThan(QT_MAJOR_VERSION, 5) {
|
||||
CONFIG += object_parallel_to_source
|
||||
INCLUDEPATH += ./src
|
||||
HEADERS += src/common/config.h \
|
||||
src/GUI/legendentryitem.h \
|
||||
src/GUI/legenditem.h \
|
||||
src/common/garmin.h \
|
||||
src/common/coordinates.h \
|
||||
@ -278,7 +277,6 @@ HEADERS += src/common/config.h \
|
||||
src/data/geojsonparser.h
|
||||
|
||||
SOURCES += src/main.cpp \
|
||||
src/GUI/legendentryitem.cpp \
|
||||
src/GUI/legenditem.cpp \
|
||||
src/common/coordinates.cpp \
|
||||
src/common/rectc.cpp \
|
||||
|
@ -178,16 +178,6 @@ void AreaItem::setDigitalZoom(int zoom)
|
||||
_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)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
class AreaItem : public PlaneItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AreaItem(const Area &area, Map *map, GraphicsItem *parent = 0);
|
||||
|
||||
@ -33,9 +31,6 @@ public:
|
||||
const QColor color() const {return _pen.color();}
|
||||
const QString &name() const {return _area.name();}
|
||||
|
||||
public slots:
|
||||
void hover(bool hvr);
|
||||
|
||||
protected:
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
||||
|
@ -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);
|
||||
}
|
@ -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
|
@ -1,17 +1,17 @@
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
#include "font.h"
|
||||
#include "pathitem.h"
|
||||
#include "graphitem.h"
|
||||
#include "planeitem.h"
|
||||
#include "legendentryitem.h"
|
||||
#include "legenditem.h"
|
||||
|
||||
#define PADDING 4
|
||||
|
||||
LegendItem::LegendItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
_color = Qt::black;
|
||||
_bgColor = Qt::white;
|
||||
_drawBackground = false;
|
||||
_font.setPixelSize(FONT_SIZE);
|
||||
_font.setFamily(FONT_FAMILY);
|
||||
}
|
||||
|
||||
void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
@ -28,6 +28,21 @@ void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
bc.setAlpha(196);
|
||||
painter->setBrush(QBrush(bc));
|
||||
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);
|
||||
@ -35,45 +50,23 @@ void LegendItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
//painter->drawRect(boundingRect());
|
||||
}
|
||||
|
||||
void LegendItem::addItem(PathItem *item)
|
||||
void LegendItem::addItem(const QColor &color, const QString &text)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
LegendEntryItem *li = new LegendEntryItem(item->color(),
|
||||
item->name().isEmpty() ? QFileInfo(item->file()).fileName() : item->name(),
|
||||
this);
|
||||
li->setPos(0, _items.size() * li->boundingRect().height());
|
||||
_items.append(Item(color, text));
|
||||
|
||||
_items.append(li);
|
||||
|
||||
_boundingRect = QRectF(0, 0, qMax(_boundingRect.width(),
|
||||
li->boundingRect().width()), _items.size() * li->boundingRect().height());
|
||||
|
||||
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);
|
||||
QFontMetrics fm(_font);
|
||||
qreal maxWidth = qMax((int)_boundingRect.width() - (FONT_SIZE * 2 + PADDING),
|
||||
fm.tightBoundingRect(text).width());
|
||||
_boundingRect = QRectF(0, 0, FONT_SIZE * 2 + PADDING + maxWidth,
|
||||
_items.size() * (FONT_SIZE + PADDING) - (PADDING - 1));
|
||||
}
|
||||
|
||||
void LegendItem::setColor(const QColor &color)
|
||||
{
|
||||
for (int i = 0; i < _items.size(); i++)
|
||||
_items.at(i)->setTextColor(color);
|
||||
_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
void LegendItem::setBackgroundColor(const QColor &color)
|
||||
@ -91,8 +84,6 @@ void LegendItem::drawBackground(bool draw)
|
||||
void LegendItem::clear()
|
||||
{
|
||||
prepareGeometryChange();
|
||||
|
||||
qDeleteAll(_items);
|
||||
_items.clear();
|
||||
_boundingRect = QRectF();
|
||||
}
|
||||
|
@ -3,11 +3,7 @@
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class LegendEntryItem;
|
||||
class PathItem;
|
||||
class PlaneItem;
|
||||
|
||||
class LegendItem : public QGraphicsItem
|
||||
class LegendItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
LegendItem(QGraphicsItem *parent = 0);
|
||||
@ -16,18 +12,27 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void addItem(PathItem *item);
|
||||
void addItem(PlaneItem *item);
|
||||
void setDigitalZoom(qreal zoom);
|
||||
void addItem(const QColor &color, const QString &text);
|
||||
void setColor(const QColor &color);
|
||||
void setBackgroundColor(const QColor &color);
|
||||
void drawBackground(bool draw);
|
||||
void clear();
|
||||
|
||||
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;
|
||||
QColor _bgColor;
|
||||
QColor _color, _bgColor;
|
||||
QFont _font;
|
||||
bool _drawBackground;
|
||||
};
|
||||
|
||||
|
@ -205,16 +205,6 @@ void MapItem::setDigitalZoom(int zoom)
|
||||
_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)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
@ -6,7 +6,7 @@
|
||||
class MapAction;
|
||||
class Projection;
|
||||
|
||||
class MapItem : public PlaneItem
|
||||
class MapItem : public QObject, public PlaneItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -32,9 +32,6 @@ public:
|
||||
const QColor color() const {return _pen.color();}
|
||||
const QString &name() const {return _name;}
|
||||
|
||||
public slots:
|
||||
void hover(bool hvr);
|
||||
|
||||
signals:
|
||||
void triggered();
|
||||
|
||||
|
@ -153,18 +153,30 @@ void MapView::updateLegend()
|
||||
|
||||
if (_showTracks) {
|
||||
for (int i = 0; i < _tracks.size(); i++)
|
||||
_legend->addItem(_tracks.at(i));
|
||||
addLegendEntry(_tracks.at(i));
|
||||
}
|
||||
if (_showRoutes) {
|
||||
for (int i = 0; i < _routes.size(); i++)
|
||||
_legend->addItem(_routes.at(i));
|
||||
addLegendEntry(_routes.at(i));
|
||||
}
|
||||
if (_showAreas) {
|
||||
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)
|
||||
{
|
||||
if (!track.isValid()) {
|
||||
@ -192,7 +204,7 @@ PathItem *MapView::addTrack(const Track &track)
|
||||
|
||||
if (_showTracks) {
|
||||
addPOI(_poi->points(ti->path()));
|
||||
_legend->addItem(ti);
|
||||
addLegendEntry(ti);
|
||||
}
|
||||
|
||||
return ti;
|
||||
@ -226,7 +238,7 @@ PathItem *MapView::addRoute(const Route &route)
|
||||
|
||||
if (_showRoutes) {
|
||||
addPOI(_poi->points(ri->path()));
|
||||
_legend->addItem(ri);
|
||||
addLegendEntry(ri);
|
||||
}
|
||||
|
||||
return ri;
|
||||
@ -254,7 +266,7 @@ void MapView::addArea(const Area &area)
|
||||
|
||||
if (_showAreas) {
|
||||
addPOI(_poi->points(ai->bounds()));
|
||||
_legend->addItem(ai);
|
||||
addLegendEntry(ai);
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,7 +309,7 @@ MapItem *MapView::addMap(MapAction *map)
|
||||
|
||||
if (_showAreas) {
|
||||
addPOI(_poi->points(mi->bounds()));
|
||||
_legend->addItem(mi);
|
||||
addLegendEntry(mi);
|
||||
}
|
||||
|
||||
return mi;
|
||||
|
@ -168,6 +168,8 @@ private:
|
||||
void pinchGesture(QPinchGesture *gesture);
|
||||
void skipColor() {_palette.nextColor();}
|
||||
void setHidpi(bool hidpi);
|
||||
void addLegendEntry(const PathItem *path);
|
||||
void addLegendEntry(const PlaneItem *plane);
|
||||
void updateLegend();
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *event);
|
||||
|
@ -388,9 +388,9 @@ void PathItem::drawMarkerBackground(bool 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));
|
||||
setZValue(zValue() + 1.0);
|
||||
} else {
|
||||
@ -401,12 +401,6 @@ void PathItem::hover(bool hvr)
|
||||
update();
|
||||
}
|
||||
|
||||
void PathItem::hoverAll(bool hvr)
|
||||
{
|
||||
hover(hvr);
|
||||
emit selected(hvr);
|
||||
}
|
||||
|
||||
void PathItem::showMarker(bool show)
|
||||
{
|
||||
if (_showMarker == show)
|
||||
|
@ -60,8 +60,7 @@ public:
|
||||
static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;}
|
||||
|
||||
public slots:
|
||||
void hover(bool hvr);
|
||||
void hoverAll(bool hvr);
|
||||
void hover(bool hover);
|
||||
|
||||
signals:
|
||||
void selected(bool);
|
||||
|
@ -6,10 +6,8 @@
|
||||
|
||||
class Map;
|
||||
|
||||
class PlaneItem : public QObject, public GraphicsItem
|
||||
class PlaneItem : public GraphicsItem
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlaneItem(GraphicsItem *parent = 0) : GraphicsItem(parent) {}
|
||||
|
||||
@ -25,9 +23,6 @@ public:
|
||||
|
||||
virtual const QColor color() const = 0;
|
||||
virtual const QString &name() const = 0;
|
||||
|
||||
public slots:
|
||||
virtual void hover(bool hvr) = 0;
|
||||
};
|
||||
|
||||
#endif // PLANEITEM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user