mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Added slider info
This commit is contained in:
parent
da81839529
commit
c21ef0b587
@ -21,7 +21,8 @@ HEADERS += src/config.h \
|
||||
src/markeritem.h \
|
||||
src/infoitem.h \
|
||||
src/elevationgraph.h \
|
||||
src/speedgraph.h
|
||||
src/speedgraph.h \
|
||||
src/sliderinfoitem.h
|
||||
SOURCES += src/main.cpp \
|
||||
src/gui.cpp \
|
||||
src/gpx.cpp \
|
||||
@ -37,7 +38,8 @@ SOURCES += src/main.cpp \
|
||||
src/markeritem.cpp \
|
||||
src/infoitem.cpp \
|
||||
src/elevationgraph.cpp \
|
||||
src/speedgraph.cpp
|
||||
src/speedgraph.cpp \
|
||||
src/sliderinfoitem.cpp
|
||||
RESOURCES += gpxsee.qrc
|
||||
TRANSLATIONS = lang/gpxsee_cs.ts
|
||||
macx:ICON = icons/gpxsee.icns
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <cmath>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "axisitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
@ -8,8 +9,6 @@
|
||||
#define PADDING 6
|
||||
#define XTICKS 15
|
||||
#define YTICKS 10
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
||||
|
||||
struct Label {
|
||||
@ -64,7 +63,7 @@ static struct Label label(double min, double max, int ticks)
|
||||
}
|
||||
|
||||
|
||||
AxisItem::AxisItem(Type type)
|
||||
AxisItem::AxisItem(Type type, QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
_type = type;
|
||||
_size = 0;
|
||||
|
@ -8,7 +8,7 @@ class AxisItem : public QGraphicsItem
|
||||
public:
|
||||
enum Type {X, Y};
|
||||
|
||||
AxisItem(Type type);
|
||||
AxisItem(Type type, QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
@ -5,4 +5,7 @@
|
||||
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
|
||||
#define APP_VERSION "0.1"
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <float.h>
|
||||
#include "elevationgraph.h"
|
||||
|
||||
ElevationGraph::ElevationGraph()
|
||||
ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
|
||||
{
|
||||
_ascent = 0;
|
||||
_descent = 0;
|
||||
|
@ -8,7 +8,7 @@ class ElevationGraph : public Graph
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ElevationGraph();
|
||||
ElevationGraph(QWidget *parent = 0);
|
||||
|
||||
void loadData(const QVector<QPointF> &data);
|
||||
void clear();
|
||||
|
@ -2,12 +2,16 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QEvent>
|
||||
#include <QGraphicsSimpleTextItem>
|
||||
#include "slideritem.h"
|
||||
#include "sliderinfoitem.h"
|
||||
#include "infoitem.h"
|
||||
#include "config.h"
|
||||
#include "graph.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#define MARGIN 10.0
|
||||
|
||||
|
||||
@ -39,6 +43,9 @@ Graph::Graph(QWidget *parent)
|
||||
|
||||
_info = new InfoItem();
|
||||
|
||||
_sliderInfo = new SliderInfoItem(_slider);
|
||||
_sliderInfo->setZValue(2.0);
|
||||
|
||||
_xMax = -FLT_MAX;
|
||||
_xMin = FLT_MAX;
|
||||
_yMax = -FLT_MAX;
|
||||
@ -46,6 +53,8 @@ Graph::Graph(QWidget *parent)
|
||||
|
||||
_xScale = 1;
|
||||
_yScale = 1;
|
||||
|
||||
_precision = 0;
|
||||
}
|
||||
|
||||
Graph::~Graph()
|
||||
@ -135,6 +144,9 @@ void Graph::loadData(const QVector<QPointF> &data)
|
||||
_scene->addItem(pi);
|
||||
_graphs.append(pi);
|
||||
|
||||
if (_graphs.size() > 1)
|
||||
_sliderInfo->hide();
|
||||
|
||||
resize(viewport()->size() - QSizeF(MARGIN, MARGIN));
|
||||
}
|
||||
|
||||
@ -223,6 +235,8 @@ void Graph::clear()
|
||||
if (_info->scene() == _scene)
|
||||
_scene->removeItem(_info);
|
||||
|
||||
_sliderInfo->show();
|
||||
|
||||
_info->clear();
|
||||
_scene->clear();
|
||||
_graphs.clear();
|
||||
@ -240,6 +254,13 @@ void Graph::emitSliderPositionChanged(const QPointF &pos)
|
||||
{
|
||||
qreal val = pos.x() / _slider->area().width();
|
||||
emit sliderPositionChanged(val);
|
||||
|
||||
const QPainterPath &path = _graphs.at(0)->path();
|
||||
QPointF p = path.pointAtPercent(val);
|
||||
qreal r = (p.y() - path.boundingRect().bottom())
|
||||
/ path.boundingRect().height();
|
||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
|
||||
}
|
||||
|
||||
qreal Graph::sliderPosition() const
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
|
||||
class SliderItem;
|
||||
class SliderInfoItem;
|
||||
class InfoItem;
|
||||
|
||||
class Scene : public QGraphicsScene
|
||||
@ -40,6 +41,7 @@ public:
|
||||
void setYUnits(const QString &units);
|
||||
void setXScale(qreal scale) {_xScale = scale;}
|
||||
void setYScale(qreal scale) {_yScale = scale;}
|
||||
void setPrecision(int p) {_precision = p;}
|
||||
|
||||
void plot(QPainter *painter, const QRectF &target);
|
||||
void clear();
|
||||
@ -58,6 +60,7 @@ protected:
|
||||
qreal _xScale, _yScale;
|
||||
QString _xUnits, _yUnits;
|
||||
QString _xLabel, _yLabel;
|
||||
int _precision;
|
||||
|
||||
private slots:
|
||||
void emitSliderPositionChanged(const QPointF &pos);
|
||||
@ -70,13 +73,14 @@ private:
|
||||
void resize(const QSizeF &size);
|
||||
|
||||
Scene *_scene;
|
||||
|
||||
AxisItem *_xAxis, *_yAxis;
|
||||
SliderItem *_slider;
|
||||
SliderInfoItem *_sliderInfo;
|
||||
InfoItem *_info;
|
||||
|
||||
QList<QGraphicsPathItem*> _graphs;
|
||||
|
||||
qreal _xMin, _xMax, _yMin, _yMax;
|
||||
|
||||
ColorShop _colorShop;
|
||||
};
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
#include <QFont>
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "infoitem.h"
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
|
||||
#define PADDING 10
|
||||
|
||||
InfoItem::InfoItem()
|
||||
InfoItem::InfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
@ -73,4 +73,6 @@ void InfoItem::insert(const QString &key, const QString &value)
|
||||
_list.append(kv);
|
||||
else
|
||||
_list[i] = kv;
|
||||
|
||||
prepareGeometryChange();
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
class InfoItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
InfoItem();
|
||||
InfoItem(QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#define SIZE 8
|
||||
|
||||
MarkerItem::MarkerItem()
|
||||
MarkerItem::MarkerItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
class MarkerItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
MarkerItem();
|
||||
MarkerItem(QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "poiitem.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#define FONT_FAMILY "Arial"
|
||||
#define FONT_SIZE 12
|
||||
#define POINT_SIZE 8
|
||||
|
||||
|
||||
POIItem::POIItem(const QString &text)
|
||||
POIItem::POIItem(const QString &text, QGraphicsItem *parent)
|
||||
: QGraphicsItem(parent)
|
||||
{
|
||||
_text = text;
|
||||
updateBoundingRect();
|
||||
|
@ -6,7 +6,7 @@
|
||||
class POIItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
POIItem(const QString &text);
|
||||
POIItem(const QString &text, QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
46
src/sliderinfoitem.cpp
Normal file
46
src/sliderinfoitem.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <QPainter>
|
||||
#include "config.h"
|
||||
#include "sliderinfoitem.h"
|
||||
|
||||
|
||||
#define SIZE 5
|
||||
|
||||
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SliderInfoItem::updateBoundingRect()
|
||||
{
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
_boundingRect = QRectF(-SIZE/2, -SIZE/2, fm.width(_text) + SIZE, fm.height());
|
||||
}
|
||||
|
||||
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
*option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
Q_UNUSED(widget);
|
||||
QFont font;
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
painter->setFont(font);
|
||||
|
||||
painter->setPen(Qt::red);
|
||||
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
||||
painter->fillRect(QRect(-SIZE/2, -SIZE/2, SIZE, SIZE), Qt::red);
|
||||
|
||||
// painter->drawRect(boundingRect());
|
||||
}
|
||||
|
||||
void SliderInfoItem::setText(const QString &text)
|
||||
{
|
||||
_text = text;
|
||||
updateBoundingRect();
|
||||
prepareGeometryChange();
|
||||
}
|
24
src/sliderinfoitem.h
Normal file
24
src/sliderinfoitem.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef SLIDERINFOITEM_H
|
||||
#define SLIDERINFOITEM_H
|
||||
|
||||
#include <QGraphicsItem>
|
||||
|
||||
class SliderInfoItem : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
SliderInfoItem(QGraphicsItem *parent = 0);
|
||||
|
||||
QRectF boundingRect() const {return _boundingRect;}
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setText(const QString &text);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
QString _text;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
#endif // SLIDERINFOITEM_H
|
@ -5,7 +5,7 @@
|
||||
|
||||
#define SIZE 10
|
||||
|
||||
SliderItem::SliderItem()
|
||||
SliderItem::SliderItem(QGraphicsObject *parent) : QGraphicsObject(parent)
|
||||
{
|
||||
setFlag(ItemIsMovable);
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
|
@ -8,7 +8,7 @@ class SliderItem : public QGraphicsObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SliderItem();
|
||||
SliderItem(QGraphicsObject *parent = 0);
|
||||
|
||||
QRectF boundingRect() const;
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
SpeedGraph::SpeedGraph()
|
||||
SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
|
||||
{
|
||||
_max = 0;
|
||||
|
||||
@ -12,6 +12,7 @@ SpeedGraph::SpeedGraph()
|
||||
Graph::setYUnits(tr("km/h"));
|
||||
Graph::setXScale(0.001);
|
||||
Graph::setYScale(3.6);
|
||||
Graph::setPrecision(1);
|
||||
}
|
||||
|
||||
void SpeedGraph::loadData(const QVector<QPointF> &data, qreal time)
|
||||
|
@ -9,7 +9,7 @@ class SpeedGraph : public Graph
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpeedGraph();
|
||||
SpeedGraph(QWidget *parent = 0);
|
||||
|
||||
void loadData(const QVector<QPointF> &data, qreal time);
|
||||
void clear();
|
||||
|
Loading…
Reference in New Issue
Block a user