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

Plots are now paper size agnostic

This commit is contained in:
Martin Tůma 2016-05-22 15:47:23 +02:00
parent 2ad94947d7
commit b8e404b789
3 changed files with 29 additions and 16 deletions

View File

@ -7,6 +7,8 @@
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinter> #include <QPrinter>
#include <QPainter> #include <QPainter>
#include <QPaintEngine>
#include <QPaintDevice>
#include <QKeyEvent> #include <QKeyEvent>
#include <QSignalMapper> #include <QSignalMapper>
#include <QMenu> #include <QMenu>
@ -34,10 +36,6 @@
#include "gui.h" #include "gui.h"
#define PLOT_INFO_HEIGHT 200
#define PLOT_MARGIN 100
#define PLOT_GRAPH_RATIO 0.2
static QString timeSpan(qreal time) static QString timeSpan(qreal time)
{ {
unsigned h, m, s; unsigned h, m, s;
@ -709,27 +707,36 @@ void GUI::plot(QPrinter *printer)
info.insert(tr("Time"), timeSpan(_time)); 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 (info.isEmpty()) {
if (_trackGraphs->isVisible()) if (_trackGraphs->isVisible())
_track->plot(&p, QRectF(0, 0, printer->width(), _track->plot(&p, QRectF(0, 0, printer->width(),
((1.0 - PLOT_GRAPH_RATIO) * printer->height()))); (TRR(printer) * printer->height())));
else else
_track->plot(&p, QRectF(0, 0, printer->width(), printer->height())); _track->plot(&p, QRectF(0, 0, printer->width(), printer->height()));
} else { } else {
info.plot(&p, QRectF(0, 0, printer->width(), PLOT_INFO_HEIGHT)); info.plot(&p, QRectF(0, 0, printer->width(), ih));
if (_trackGraphs->isVisible()) if (_trackGraphs->isVisible())
_track->plot(&p, QRectF(0, PLOT_INFO_HEIGHT + PLOT_MARGIN, _track->plot(&p, QRectF(0, ih + mh, printer->width(),
printer->width(), ((1.0 - PLOT_GRAPH_RATIO) * printer->height()) (TRR(printer) * printer->height()) - (ih + 2*mh)));
- (PLOT_INFO_HEIGHT + 2*PLOT_MARGIN)));
else else
_track->plot(&p, QRectF(0, PLOT_INFO_HEIGHT + PLOT_MARGIN, _track->plot(&p, QRectF(0, ih + mh, printer->width(),
printer->width(), printer->height() printer->height() - (ih + mh)));
- (PLOT_INFO_HEIGHT + PLOT_MARGIN)));
} }
if (_trackGraphs->isVisible()) { if (_trackGraphs->isVisible()) {
GraphView *gv = static_cast<GraphView*>(_trackGraphs->currentWidget()); GraphView *gv = static_cast<GraphView*>(_trackGraphs->currentWidget());
gv->plot(&p, QRectF(0, (1.0 - PLOT_GRAPH_RATIO) * printer->height(), gv->plot(&p, QRectF(0, TRR(printer) * printer->height(),
printer->width(), printer->height() * PLOT_GRAPH_RATIO)); printer->width(), printer->height() * GRR(printer)));
} }
} }

View File

@ -29,7 +29,12 @@ void TrackInfo::plot(QPainter *painter, const QRectF &target)
render(painter, target, adj); render(painter, target, adj);
} }
bool TrackInfo::isEmpty() bool TrackInfo::isEmpty() const
{ {
return _info->isEmpty(); return _info->isEmpty();
} }
QSizeF TrackInfo::contentSize() const
{
return sceneRect().size();
}

View File

@ -14,7 +14,8 @@ public:
void insert(const QString &key, const QString &value); void insert(const QString &key, const QString &value);
void plot(QPainter *painter, const QRectF &target); void plot(QPainter *painter, const QRectF &target);
bool isEmpty(); bool isEmpty() const;
QSizeF contentSize() const;
private: private:
InfoItem *_info; InfoItem *_info;