From 2ad94947d7a8edb4fa9b73db0fb56a7b5fc6f92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 22 May 2016 11:54:27 +0200 Subject: [PATCH] Make the file info and graph info having the same text size in plots. --- src/config.h | 1 + src/graphview.cpp | 10 ++++++---- src/trackinfo.cpp | 14 +++++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/config.h b/src/config.h index 267130f7..745ac095 100644 --- a/src/config.h +++ b/src/config.h @@ -11,6 +11,7 @@ #define FONT_FAMILY "Arial" #define FONT_SIZE 12 +#define SCREEN_DPI 96.0 #define MAP_FILE QString("maps.txt") #define POI_DIR QString("POI") diff --git a/src/graphview.cpp b/src/graphview.cpp index be85dba9..f09147c4 100644 --- a/src/graphview.cpp +++ b/src/graphview.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include "config.h" #include "axisitem.h" #include "slideritem.h" @@ -237,15 +239,15 @@ void GraphView::resizeEvent(QResizeEvent *) void GraphView::plot(QPainter *painter, const QRectF &target) { - qreal ratio = target.width() / target.height(); - QSizeF orig = _scene->sceneRect().size(); - QSizeF canvas = QSizeF(orig.height() * ratio, orig.height()); + qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX() + / SCREEN_DPI; + QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio); setUpdatesEnabled(false); redraw(canvas); if (_slider->pos().x() == _slider->area().left()) _slider->hide(); - _scene->render(painter, target, _scene->itemsBoundingRect()); + _scene->render(painter, target); _slider->show(); redraw(); setUpdatesEnabled(true); diff --git a/src/trackinfo.cpp b/src/trackinfo.cpp index 6c68cc19..4d1e676d 100644 --- a/src/trackinfo.cpp +++ b/src/trackinfo.cpp @@ -1,6 +1,10 @@ +#include +#include +#include "config.h" #include "infoitem.h" #include "trackinfo.h" + TrackInfo::TrackInfo(QObject *parent) : QGraphicsScene(parent) { _info = new InfoItem(); @@ -14,7 +18,15 @@ void TrackInfo::insert(const QString &key, const QString &value) void TrackInfo::plot(QPainter *painter, const QRectF &target) { - render(painter, target); + qreal ratio = painter->paintEngine()->paintDevice()->logicalDpiX() + / SCREEN_DPI; + QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio); + QSizeF diff = QSizeF(qAbs(canvas.width() - sceneRect().width()), + qAbs(canvas.height() - sceneRect().height())); + QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(), + diff.height()/2); + + render(painter, target, adj); } bool TrackInfo::isEmpty()