From b8e404b789c03b0f30358289b0509b16fe12eb63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 22 May 2016 15:47:23 +0200 Subject: [PATCH] Plots are now paper size agnostic --- src/gui.cpp | 35 +++++++++++++++++++++-------------- src/trackinfo.cpp | 7 ++++++- src/trackinfo.h | 3 ++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index cef44c92..7492c199 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -34,10 +36,6 @@ #include "gui.h" -#define PLOT_INFO_HEIGHT 200 -#define PLOT_MARGIN 100 -#define PLOT_GRAPH_RATIO 0.2 - static QString timeSpan(qreal time) { unsigned h, m, s; @@ -709,27 +707,36 @@ void GUI::plot(QPrinter *printer) info.insert(tr("Time"), timeSpan(_time)); + qreal ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI; + qreal ih = info.contentSize().height() * ratio; + qreal mh = ih / 2; + +#define GRR(printer) \ + (((printer)->width() > (printer)->height()) \ + ? 0.15 * ((qreal)((printer)->width()) / (qreal)((printer)->height())) \ + : 0.15) +#define TRR(printer) \ + (1.0 - GRR(printer)) + if (info.isEmpty()) { if (_trackGraphs->isVisible()) _track->plot(&p, QRectF(0, 0, printer->width(), - ((1.0 - PLOT_GRAPH_RATIO) * printer->height()))); + (TRR(printer) * printer->height()))); else _track->plot(&p, QRectF(0, 0, printer->width(), printer->height())); } else { - info.plot(&p, QRectF(0, 0, printer->width(), PLOT_INFO_HEIGHT)); + info.plot(&p, QRectF(0, 0, printer->width(), ih)); if (_trackGraphs->isVisible()) - _track->plot(&p, QRectF(0, PLOT_INFO_HEIGHT + PLOT_MARGIN, - printer->width(), ((1.0 - PLOT_GRAPH_RATIO) * printer->height()) - - (PLOT_INFO_HEIGHT + 2*PLOT_MARGIN))); + _track->plot(&p, QRectF(0, ih + mh, printer->width(), + (TRR(printer) * printer->height()) - (ih + 2*mh))); else - _track->plot(&p, QRectF(0, PLOT_INFO_HEIGHT + PLOT_MARGIN, - printer->width(), printer->height() - - (PLOT_INFO_HEIGHT + PLOT_MARGIN))); + _track->plot(&p, QRectF(0, ih + mh, printer->width(), + printer->height() - (ih + mh))); } if (_trackGraphs->isVisible()) { GraphView *gv = static_cast(_trackGraphs->currentWidget()); - gv->plot(&p, QRectF(0, (1.0 - PLOT_GRAPH_RATIO) * printer->height(), - printer->width(), printer->height() * PLOT_GRAPH_RATIO)); + gv->plot(&p, QRectF(0, TRR(printer) * printer->height(), + printer->width(), printer->height() * GRR(printer))); } } diff --git a/src/trackinfo.cpp b/src/trackinfo.cpp index 4d1e676d..8dcf1dcf 100644 --- a/src/trackinfo.cpp +++ b/src/trackinfo.cpp @@ -29,7 +29,12 @@ void TrackInfo::plot(QPainter *painter, const QRectF &target) render(painter, target, adj); } -bool TrackInfo::isEmpty() +bool TrackInfo::isEmpty() const { return _info->isEmpty(); } + +QSizeF TrackInfo::contentSize() const +{ + return sceneRect().size(); +} diff --git a/src/trackinfo.h b/src/trackinfo.h index 71bfd245..b27a6913 100644 --- a/src/trackinfo.h +++ b/src/trackinfo.h @@ -14,7 +14,8 @@ public: void insert(const QString &key, const QString &value); void plot(QPainter *painter, const QRectF &target); - bool isEmpty(); + bool isEmpty() const; + QSizeF contentSize() const; private: InfoItem *_info;