mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-17 16:20:48 +01:00
Fixed slider info displaying on right graph border
This commit is contained in:
parent
eec797125b
commit
f469b4f600
@ -27,6 +27,9 @@ GraphView::GraphView(QWidget *parent)
|
|||||||
_scene = new Scene(this);
|
_scene = new Scene(this);
|
||||||
setScene(_scene);
|
setScene(_scene);
|
||||||
|
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
|
||||||
_xAxis = new AxisItem(AxisItem::X);
|
_xAxis = new AxisItem(AxisItem::X);
|
||||||
_yAxis = new AxisItem(AxisItem::Y);
|
_yAxis = new AxisItem(AxisItem::Y);
|
||||||
|
|
||||||
@ -148,9 +151,6 @@ void GraphView::loadData(const QVector<QPointF> &data)
|
|||||||
pi->setPen(pen);
|
pi->setPen(pen);
|
||||||
_scene->addItem(pi);
|
_scene->addItem(pi);
|
||||||
_graphs.append(pi);
|
_graphs.append(pi);
|
||||||
|
|
||||||
if (_graphs.size() > 1)
|
|
||||||
_sliderInfo->hide();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphView::redraw()
|
void GraphView::redraw()
|
||||||
@ -223,9 +223,7 @@ void GraphView::redraw(const QSizeF &size)
|
|||||||
_slider->setPos(QPointF(sp * r.width(), r.bottom()));
|
_slider->setPos(QPointF(sp * r.width(), r.bottom()));
|
||||||
_scene->addItem(_slider);
|
_scene->addItem(_slider);
|
||||||
|
|
||||||
const QPainterPath &path = _graphs.at(0)->path();
|
_sliderInfo->setVisible(_graphs.size() == 1);
|
||||||
QPointF p = path.pointAtPercent(sp);
|
|
||||||
_sliderInfo->setText(QString::number(-p.y() * _yScale, 'f', _precision));
|
|
||||||
|
|
||||||
r = _scene->itemsBoundingRect();
|
r = _scene->itemsBoundingRect();
|
||||||
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
_info->setPos(r.topLeft() + QPointF(r.width()/2
|
||||||
@ -262,13 +260,10 @@ void GraphView::clear()
|
|||||||
_scene->removeItem(_xAxis);
|
_scene->removeItem(_xAxis);
|
||||||
if (_yAxis->scene() == _scene)
|
if (_yAxis->scene() == _scene)
|
||||||
_scene->removeItem(_yAxis);
|
_scene->removeItem(_yAxis);
|
||||||
|
|
||||||
if (_slider->scene() == _scene)
|
if (_slider->scene() == _scene)
|
||||||
_scene->removeItem(_slider);
|
_scene->removeItem(_slider);
|
||||||
|
|
||||||
if (_info->scene() == _scene)
|
if (_info->scene() == _scene)
|
||||||
_scene->removeItem(_info);
|
_scene->removeItem(_info);
|
||||||
_sliderInfo->show();
|
|
||||||
|
|
||||||
_slider->clear();
|
_slider->clear();
|
||||||
_info->clear();
|
_info->clear();
|
||||||
@ -320,7 +315,7 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
|||||||
qreal val = pos.x() / _slider->area().width();
|
qreal val = pos.x() / _slider->area().width();
|
||||||
emit sliderPositionChanged(val * _bounds.width());
|
emit sliderPositionChanged(val * _bounds.width());
|
||||||
|
|
||||||
if (!_sliderInfo->isVisible())
|
if (_graphs.size() > 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QPainterPath &path = _graphs.at(0)->path();
|
const QPainterPath &path = _graphs.at(0)->path();
|
||||||
@ -331,6 +326,11 @@ void GraphView::emitSliderPositionChanged(const QPointF &pos)
|
|||||||
|
|
||||||
qreal y = yAtX(path, val * _bounds.width());
|
qreal y = yAtX(path, val * _bounds.width());
|
||||||
qreal r = (y - br.bottom()) / br.height();
|
qreal r = (y - br.bottom()) / br.height();
|
||||||
|
|
||||||
|
SliderInfoItem::Side s = (pos.x() + _sliderInfo->boundingRect().width()
|
||||||
|
> _slider->area().right()) ? SliderInfoItem::Left : SliderInfoItem::Right;
|
||||||
|
|
||||||
|
_sliderInfo->setSide(s);
|
||||||
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
_sliderInfo->setPos(QPointF(0, _slider->boundingRect().height() * r));
|
||||||
_sliderInfo->setText(QString::number(-y * _yScale, 'f', _precision));
|
_sliderInfo->setText(QString::number(-y * _yScale, 'f', _precision));
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
SliderInfoItem::SliderInfoItem(QGraphicsItem *parent) : QGraphicsItem(parent)
|
||||||
{
|
{
|
||||||
|
_side = Right;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SliderInfoItem::updateBoundingRect()
|
void SliderInfoItem::updateBoundingRect()
|
||||||
@ -16,7 +17,10 @@ void SliderInfoItem::updateBoundingRect()
|
|||||||
font.setFamily(FONT_FAMILY);
|
font.setFamily(FONT_FAMILY);
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
|
|
||||||
_boundingRect = QRectF(-SIZE/2, 0, fm.width(_text) + SIZE, fm.height());
|
_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());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
||||||
@ -31,7 +35,11 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
|
|||||||
painter->setFont(font);
|
painter->setFont(font);
|
||||||
|
|
||||||
painter->setPen(Qt::red);
|
painter->setPen(Qt::red);
|
||||||
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
if (_side == Right)
|
||||||
|
painter->drawText(SIZE, fm.height() - fm.descent(), _text);
|
||||||
|
else
|
||||||
|
painter->drawText(-(fm.width(_text) + SIZE/2),
|
||||||
|
fm.height() - fm.descent(), _text);
|
||||||
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
|
painter->drawLine(QPointF(-SIZE/2, 0), QPointF(SIZE/2, 0));
|
||||||
|
|
||||||
//painter->drawRect(boundingRect());
|
//painter->drawRect(boundingRect());
|
||||||
@ -43,3 +51,13 @@ void SliderInfoItem::setText(const QString &text)
|
|||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SliderInfoItem::setSide(Side side)
|
||||||
|
{
|
||||||
|
if (side == _side)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_side = side;
|
||||||
|
updateBoundingRect();
|
||||||
|
prepareGeometryChange();
|
||||||
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
class SliderInfoItem : public QGraphicsItem
|
class SliderInfoItem : public QGraphicsItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
enum Side {Left, Right};
|
||||||
|
|
||||||
SliderInfoItem(QGraphicsItem *parent = 0);
|
SliderInfoItem(QGraphicsItem *parent = 0);
|
||||||
|
|
||||||
QRectF boundingRect() const {return _boundingRect;}
|
QRectF boundingRect() const {return _boundingRect;}
|
||||||
@ -13,10 +15,12 @@ public:
|
|||||||
QWidget *widget);
|
QWidget *widget);
|
||||||
|
|
||||||
void setText(const QString &text);
|
void setText(const QString &text);
|
||||||
|
void setSide(Side side);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBoundingRect();
|
void updateBoundingRect();
|
||||||
|
|
||||||
|
Side _side;
|
||||||
QString _text;
|
QString _text;
|
||||||
QRectF _boundingRect;
|
QRectF _boundingRect;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user