1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Improved PDF export

This commit is contained in:
Martin Tůma 2016-02-02 01:10:05 +01:00
parent 16cce5abd0
commit e7edd5c3c3
3 changed files with 26 additions and 30 deletions

View File

@ -237,7 +237,7 @@ void Graph::plot(QPainter *painter, const QRectF &target)
resize(canvas); resize(canvas);
_slider->hide(); _slider->hide();
_info->hide(); _info->hide();
_scene->render(painter, target, QRectF(), Qt::KeepAspectRatioByExpanding); _scene->render(painter, target, QRectF());
_slider->show(); _slider->show();
_info->show(); _info->show();
resize(orig); resize(orig);

View File

@ -29,7 +29,7 @@ QRectF ScaleItem::boundingRect() const
es = fm.tightBoundingRect(QString::number(_length * SEGMENTS)); es = fm.tightBoundingRect(QString::number(_length * SEGMENTS));
us = fm.tightBoundingRect(units()); us = fm.tightBoundingRect(units());
return QRectF(-ss.width()/2, -(PADDING + ss.height() + fm.descent()), return QRectF(-ss.width()/2, 0,
_width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2), _width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2),
SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent()); SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent());
} }
@ -43,22 +43,23 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
font.setPixelSize(FONT_SIZE); font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY); font.setFamily(FONT_FAMILY);
QFontMetrics fm(font); QFontMetrics fm(font);
QRect br;
painter->setFont(font); painter->setFont(font);
for (int i = 0; i <= SEGMENTS; i++) { for (int i = 0; i <= SEGMENTS; i++) {
QString label = QString::number(_length * i); QString label = QString::number(_length * i);
QRect br = fm.tightBoundingRect(label); br = fm.tightBoundingRect(label);
painter->drawText(_width * i - br.width()/2, -PADDING, label); painter->drawText(_width * i - br.width()/2, br.height(), label);
} }
painter->drawText(_width * SEGMENTS + PADDING, SCALE_HEIGHT + fm.descent(), painter->drawText(_width * SEGMENTS + PADDING, SCALE_HEIGHT + PADDING
units()); + br.height() + fm.descent(), units());
painter->drawRect(QRectF(0, 0, SEGMENTS * _width, SCALE_HEIGHT)); painter->drawRect(QRectF(0, br.height() + PADDING, SEGMENTS * _width,
SCALE_HEIGHT));
for (int i = 0; i < SEGMENTS; i += 2) for (int i = 0; i < SEGMENTS; i += 2)
painter->fillRect(QRectF(i * _width, 0, _width, SCALE_HEIGHT), painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width,
Qt::black); SCALE_HEIGHT), Qt::black);
/* /*
painter->setPen(Qt::red); painter->setPen(Qt::red);

View File

@ -12,8 +12,7 @@
#define MARGIN 10.0 #define MARGIN 10.0
#define TRACK_WIDTH 3 #define TRACK_WIDTH 3
#define SCALE_OFFSET_X 7 #define SCALE_OFFSET 7
#define SCALE_OFFSET_Y 15
Track::Track(QWidget *parent) Track::Track(QWidget *parent)
: QGraphicsView(parent) : QGraphicsView(parent)
@ -247,12 +246,6 @@ void Track::wheelEvent(QWheelEvent *event)
resetCachedContent(); resetCachedContent();
} }
void Track::showMarkers(bool show)
{
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(show);
}
void Track::setTrackLineWidth(qreal width) void Track::setTrackLineWidth(qreal width)
{ {
for (int i = 0; i < _trackPaths.size(); i++) { for (int i = 0; i < _trackPaths.size(); i++) {
@ -264,12 +257,14 @@ void Track::setTrackLineWidth(qreal width)
void Track::plot(QPainter *painter, const QRectF &target) void Track::plot(QPainter *painter, const QRectF &target)
{ {
_scene->removeItem(_mapScale); QRectF orig, adj;
QRectF orig = _scene->itemsBoundingRect();
QRectF adj;
qreal ratio, diff; qreal ratio, diff;
_scene->removeItem(_mapScale);
orig = _scene->itemsBoundingRect().adjusted(0, 0, 0,
_mapScale->boundingRect().height());
_scene->addItem(_mapScale);
if (target.width()/target.height() > orig.width()/orig.height()) { if (target.width()/target.height() > orig.width()/orig.height()) {
ratio = target.width()/target.height(); ratio = target.width()/target.height();
diff = qAbs((orig.height() * ratio) - orig.width()); diff = qAbs((orig.height() * ratio) - orig.width());
@ -280,13 +275,13 @@ void Track::plot(QPainter *painter, const QRectF &target)
adj = orig.adjusted(0, -diff/2, 0, diff/2); adj = orig.adjusted(0, -diff/2, 0, diff/2);
} }
showMarkers(false); _mapScale->setPos(adj.bottomRight()
setTrackLineWidth(0); + QPoint(-_mapScale->boundingRect().width(),
_scene->render(painter, target, adj, Qt::KeepAspectRatioByExpanding); -_mapScale->boundingRect().height()));
setTrackLineWidth(TRACK_WIDTH * _scale);
showMarkers(true);
_scene->addItem(_mapScale); setTrackLineWidth(0);
_scene->render(painter, target, adj);
setTrackLineWidth(TRACK_WIDTH * _scale);
} }
enum QPrinter::Orientation Track::orientation() const enum QPrinter::Orientation Track::orientation() const
@ -391,8 +386,8 @@ void Track::resizeEvent(QResizeEvent *e)
void Track::paintEvent(QPaintEvent *e) void Track::paintEvent(QPaintEvent *e)
{ {
QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET_X, QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET,
-SCALE_OFFSET_Y)); -(SCALE_OFFSET + _mapScale->boundingRect().height())));
_mapScale->setPos(scenePos); _mapScale->setPos(scenePos);
QGraphicsView::paintEvent(e); QGraphicsView::paintEvent(e);