mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-01-18 11:52:08 +01:00
Improved graph slider info
This commit is contained in:
parent
bb47a34823
commit
da4a51e7fa
@ -2,7 +2,7 @@
|
||||
#include "coordinates.h"
|
||||
#include "format.h"
|
||||
|
||||
QString Format::timeSpan(qreal time)
|
||||
QString Format::timeSpan(qreal time, bool full)
|
||||
{
|
||||
unsigned h, m, s;
|
||||
|
||||
@ -10,7 +10,11 @@ QString Format::timeSpan(qreal time)
|
||||
m = (time - (h * 3600)) / 60;
|
||||
s = time - (h * 3600) - (m * 60);
|
||||
|
||||
return QString("%1:%2:%3").arg(h).arg(m, 2, 10, QChar('0'))
|
||||
if (full || h)
|
||||
return QString("%1:%2:%3").arg(h, 2, 10, QChar('0'))
|
||||
.arg(m, 2, 10, QChar('0')).arg(s, 2, 10, QChar('0'));
|
||||
else
|
||||
return QString("%1:%2").arg(m, 2, 10, QChar('0'))
|
||||
.arg(s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ class Coordinates;
|
||||
|
||||
namespace Format
|
||||
{
|
||||
QString timeSpan(qreal time);
|
||||
QString timeSpan(qreal time, bool full = true);
|
||||
QString distance(qreal value, Units units);
|
||||
QString elevation(qreal value, Units units);
|
||||
QString coordinates(const Coordinates &value);
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "graph.h"
|
||||
#include "graphitem.h"
|
||||
#include "pathitem.h"
|
||||
#include "format.h"
|
||||
#include "graphview.h"
|
||||
|
||||
|
||||
@ -171,6 +172,11 @@ void GraphView::showGrid(bool show)
|
||||
_grid->setVisible(show);
|
||||
}
|
||||
|
||||
void GraphView::showSliderInfo(bool show)
|
||||
{
|
||||
_sliderInfo->setVisible(show);
|
||||
}
|
||||
|
||||
void GraphView::addGraph(GraphItem *graph, PathItem *path, int id)
|
||||
{
|
||||
graph->setUnits(_units);
|
||||
@ -374,22 +380,25 @@ void GraphView::updateSliderPosition()
|
||||
_slider->setVisible(false);
|
||||
}
|
||||
|
||||
if (_slider->isVisible())
|
||||
updateSliderInfo();
|
||||
}
|
||||
|
||||
void GraphView::updateSliderInfo()
|
||||
{
|
||||
_sliderInfo->setVisible(_visible.count() == 1);
|
||||
if (!_sliderInfo->isVisible())
|
||||
return;
|
||||
qreal r, y;
|
||||
|
||||
if (_visible.count() > 1)
|
||||
r = 0;
|
||||
else {
|
||||
QRectF br(_visible.first()->bounds());
|
||||
if (br.height() < _minYRange)
|
||||
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
|
||||
_minYRange/2 - br.height()/2);
|
||||
|
||||
qreal y = _visible.first()->yAtX(_sliderPos);
|
||||
qreal r = (y - br.bottom()) / br.height();
|
||||
y = _visible.first()->yAtX(_sliderPos);
|
||||
r = (y - br.bottom()) / br.height();
|
||||
}
|
||||
|
||||
qreal pos = (_sliderPos / bounds().width()) * _slider->area().width();
|
||||
SliderInfoItem::Side s = (pos + _sliderInfo->boundingRect().width()
|
||||
@ -397,8 +406,11 @@ void GraphView::updateSliderInfo()
|
||||
|
||||
_sliderInfo->setSide(s);
|
||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||
_sliderInfo->setText(QString::number(-y * _yScale + _yOffset, 'f',
|
||||
_precision));
|
||||
_sliderInfo->setText(_graphType == Time ? Format::timeSpan(_sliderPos,
|
||||
bounds().width() > 3600) : QString::number(_sliderPos * _xScale, 'f', 1)
|
||||
+ UNIT_SPACE + _xUnits, (_visible.count() > 1) ? QString()
|
||||
: QString::number(-y * _yScale + _yOffset, 'f', _precision) + UNIT_SPACE
|
||||
+ _yUnits);
|
||||
}
|
||||
|
||||
void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
void setGraphType(GraphType type);
|
||||
void setUnits(Units units);
|
||||
void showGrid(bool show);
|
||||
void showSliderInfo(bool show);
|
||||
|
||||
void setPalette(const Palette &palette);
|
||||
void setGraphWidth(int width);
|
||||
|
20
src/gui.cpp
20
src/gui.cpp
@ -425,6 +425,10 @@ void GUI::createActions()
|
||||
_showGraphGridAction->setCheckable(true);
|
||||
connect(_showGraphGridAction, SIGNAL(triggered(bool)), this,
|
||||
SLOT(showGraphGrids(bool)));
|
||||
_showGraphSliderInfoAction = new QAction(tr("Show slider info"), this);
|
||||
_showGraphSliderInfoAction->setCheckable(true);
|
||||
connect(_showGraphSliderInfoAction, SIGNAL(triggered(bool)), this,
|
||||
SLOT(showGraphSliderInfo(bool)));
|
||||
|
||||
// Settings actions
|
||||
_showToolbarsAction = new QAction(tr("Show toolbars"), this);
|
||||
@ -513,6 +517,7 @@ void GUI::createMenus()
|
||||
graphMenu->addAction(_timeGraphAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphGridAction);
|
||||
graphMenu->addAction(_showGraphSliderInfoAction);
|
||||
graphMenu->addSeparator();
|
||||
graphMenu->addAction(_showGraphsAction);
|
||||
|
||||
@ -1177,6 +1182,12 @@ void GUI::showGraphGrids(bool show)
|
||||
_tabs.at(i)->showGrid(show);
|
||||
}
|
||||
|
||||
void GUI::showGraphSliderInfo(bool show)
|
||||
{
|
||||
for (int i = 0; i < _tabs.size(); i++)
|
||||
_tabs.at(i)->showSliderInfo(show);
|
||||
}
|
||||
|
||||
void GUI::loadMap()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"),
|
||||
@ -1537,6 +1548,10 @@ void GUI::writeSettings()
|
||||
if (_showGraphGridAction->isChecked() != SHOW_GRAPH_GRIDS_DEFAULT)
|
||||
settings.setValue(SHOW_GRAPH_GRIDS_SETTING,
|
||||
_showGraphGridAction->isChecked());
|
||||
if (_showGraphSliderInfoAction->isChecked()
|
||||
!= SHOW_GRAPH_SLIDER_INFO_DEFAULT)
|
||||
settings.setValue(SHOW_GRAPH_SLIDER_INFO_SETTING,
|
||||
_showGraphSliderInfoAction->isChecked());
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(POI_SETTINGS_GROUP);
|
||||
@ -1724,6 +1739,11 @@ void GUI::readSettings()
|
||||
showGraphGrids(false);
|
||||
else
|
||||
_showGraphGridAction->setChecked(true);
|
||||
if (!settings.value(SHOW_GRAPH_SLIDER_INFO_SETTING,
|
||||
SHOW_GRAPH_SLIDER_INFO_DEFAULT).toBool())
|
||||
showGraphSliderInfo(false);
|
||||
else
|
||||
_showGraphSliderInfoAction->setChecked(true);
|
||||
settings.endGroup();
|
||||
|
||||
settings.beginGroup(POI_SETTINGS_GROUP);
|
||||
|
@ -51,6 +51,7 @@ private slots:
|
||||
void closePOIFiles();
|
||||
void showGraphs(bool show);
|
||||
void showGraphGrids(bool show);
|
||||
void showGraphSliderInfo(bool show);
|
||||
void showToolbars(bool show);
|
||||
void showFullscreen(bool show);
|
||||
void showTracks(bool show);
|
||||
@ -156,6 +157,7 @@ private:
|
||||
QAction *_clearMapCacheAction;
|
||||
QAction *_showGraphsAction;
|
||||
QAction *_showGraphGridAction;
|
||||
QAction *_showGraphSliderInfoAction;
|
||||
QAction *_distanceGraphAction;
|
||||
QAction *_timeGraphAction;
|
||||
QAction *_showToolbarsAction;
|
||||
|
@ -25,6 +25,8 @@
|
||||
#define GRAPH_TYPE_DEFAULT Distance
|
||||
#define SHOW_GRAPH_GRIDS_SETTING "grid"
|
||||
#define SHOW_GRAPH_GRIDS_DEFAULT true
|
||||
#define SHOW_GRAPH_SLIDER_INFO_SETTING "sliderInfo"
|
||||
#define SHOW_GRAPH_SLIDER_INFO_DEFAULT true
|
||||
|
||||
#define MAP_SETTINGS_GROUP "Map"
|
||||
#define CURRENT_MAP_SETTING "map"
|
||||
|
@ -17,10 +17,12 @@ void SliderInfoItem::updateBoundingRect()
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
|
||||
qreal width = qMax(fm.width(_x), fm.width(_y));
|
||||
qreal height = 2 * fm.height() - 2*fm.descent();
|
||||
|
||||
_boundingRect = (_side == Right)
|
||||
? QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height())
|
||||
: QRectF(-(fm.width(_text) + SIZE/2), 0, fm.width(_text) + SIZE,
|
||||
fm.height());
|
||||
? QRectF(-SIZE/2, -height/2, width + 1.5*SIZE, height)
|
||||
: QRectF(-(width + SIZE), -height/2, width + 1.5*SIZE, height);
|
||||
}
|
||||
|
||||
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
@ -32,25 +34,48 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||
font.setPixelSize(FONT_SIZE);
|
||||
font.setFamily(FONT_FAMILY);
|
||||
QFontMetrics fm(font);
|
||||
QRectF rx, ry;
|
||||
|
||||
|
||||
qreal width = qMax(fm.width(_x), fm.width(_y));
|
||||
if (_side == Right) {
|
||||
ry = QRectF(SIZE, -fm.height() + fm.descent(), fm.width(_y),
|
||||
fm.height() - fm.descent());
|
||||
rx = QRectF(SIZE, 0, fm.width(_x), fm.height()
|
||||
- fm.descent());
|
||||
} else {
|
||||
ry = QRectF(-(width + SIZE), -fm.height() + fm.descent(), fm.width(_y),
|
||||
fm.height() - fm.descent());
|
||||
rx = QRectF(-(width + SIZE), 0, fm.width(_x), fm.height()
|
||||
- fm.descent());
|
||||
}
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QBrush(QColor(255, 255, 255, 196)));
|
||||
painter->drawRect(ry);
|
||||
painter->drawRect(rx);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
|
||||
painter->setFont(font);
|
||||
painter->setRenderHint(QPainter::Antialiasing, false);
|
||||
painter->setPen(Qt::red);
|
||||
|
||||
if (_side == Right)
|
||||
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
||||
else
|
||||
painter->drawText(-(fm.width(_text) + SIZE/2),
|
||||
fm.height() - fm.descent(), _text);
|
||||
if (_side == Right) {
|
||||
painter->drawText(SIZE, -fm.descent()/2, _y);
|
||||
painter->drawText(SIZE, fm.height() - fm.descent()*1.5, _x);
|
||||
} else {
|
||||
painter->drawText(-(width + SIZE), -fm.descent()/2, _y);
|
||||
painter->drawText(-(width + SIZE), fm.height() - fm.descent()*1.5, _x);
|
||||
}
|
||||
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
|
||||
|
||||
//painter->drawRect(boundingRect());
|
||||
}
|
||||
|
||||
void SliderInfoItem::setText(const QString &text)
|
||||
void SliderInfoItem::setText(const QString &x, const QString &y)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_text = text;
|
||||
_x = x; _y = y;
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,14 @@ public:
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||
QWidget *widget);
|
||||
|
||||
void setText(const QString &text);
|
||||
void setText(const QString &x, const QString &y);
|
||||
void setSide(Side side);
|
||||
|
||||
private:
|
||||
void updateBoundingRect();
|
||||
|
||||
Side _side;
|
||||
QString _text;
|
||||
QString _x, _y;
|
||||
QRectF _boundingRect;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user