From 3c0e4962486fd9d1691fe52cb8c11ff493e42d05 Mon Sep 17 00:00:00 2001 From: Oliver Bock <oliver.bock@aei.mpg.de> Date: Thu, 5 Oct 2017 16:44:43 +0200 Subject: [PATCH] Improved plot graphics * Ignoring the aspect ratio during auto-fit stretches/compresses the curve strokes * Keep aspect ratio and use manual scaling to avoid that * Increased pen sizes and set nicer styles * y-Axis ("stretcher") isn't needed anymore as we now retain the y-scaling with fixed ratio --- src/pulsescopewidget.cpp | 34 ++++++++++++++++++++-------------- src/pulsescopewidget.h | 4 +++- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp index 0549a4e..8de8ae6 100644 --- a/src/pulsescopewidget.cpp +++ b/src/pulsescopewidget.cpp @@ -49,17 +49,15 @@ PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent), } m_scopeSizeH = 360.0 * PERIODS; - // vertical axes range m_scopeSizeV = 10.0; + m_scaling = 1.0; m_pathLHO = NULL; m_pathLLO = NULL; m_pathVirgo = NULL; - m_xAxis = m_scene.addLine(0.0, m_scopeSizeV/2.0, m_scopeSizeH, m_scopeSizeV/2.0, QPen(QColor("white"), 0.1)); + m_xAxis = m_scene.addLine(0.0, m_scopeSizeV/2.0, m_scopeSizeH, m_scopeSizeV/2.0, QPen(QBrush(QColor("white")), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); m_xAxis->setZValue(1); - m_yAxis = m_scene.addLine(0.0, 0.0, 0.0, m_scopeSizeV); - m_yAxis->setZValue(1); setScene(&m_scene); } @@ -73,24 +71,32 @@ void PulseScopeWidget::resizeEvent(QResizeEvent *event) { Q_UNUSED(event); - fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio); + // custom scaling to avoid ugly auto-fitting artefacts + m_scaling = (height() * 1.0 / width()) * 110; + plot(*m_data); + + // custom scaling allows us to retain the aspect ratio during auto-fit (much nicer curves!) + fitInView(m_scene.itemsBoundingRect(), Qt::KeepAspectRatio); } void PulseScopeWidget::plot(const PlotData& data) { - QPainterPath pulsePathLHO(QPointF(0.0, m_scopeSizeV - data.m_dataLHO.at(0) - m_scopeSizeV/2.0)); - QPainterPath pulsePathLLO(QPointF(0.0, m_scopeSizeV - data.m_dataLLO.at(0) - m_scopeSizeV/2.0)); - QPainterPath pulsePathVirgo(QPointF(0.0, m_scopeSizeV - data.m_dataVirgo.at(0) - m_scopeSizeV/2.0)); + // save data for resize-only events + m_data = &data; + + QPainterPath pulsePathLHO(QPointF(0.0, m_scopeSizeV - data.m_dataLHO.at(0)*m_scaling - m_scopeSizeV/2.0)); + QPainterPath pulsePathLLO(QPointF(0.0, m_scopeSizeV - data.m_dataLLO.at(0)*m_scaling - m_scopeSizeV/2.0)); + QPainterPath pulsePathVirgo(QPointF(0.0, m_scopeSizeV - data.m_dataVirgo.at(0)*m_scaling - m_scopeSizeV/2.0)); for(int i = 1; i < m_scopeSizeH; ++i) { - pulsePathLHO.lineTo(i, m_scopeSizeV - data.m_dataLHO.at(i) - m_scopeSizeV/2.0); - pulsePathLLO.lineTo(i, m_scopeSizeV - data.m_dataLLO.at(i) - m_scopeSizeV/2.0); - pulsePathVirgo.lineTo(i, m_scopeSizeV - data.m_dataVirgo.at(i) - m_scopeSizeV/2.0); + pulsePathLHO.lineTo(i, m_scopeSizeV - data.m_dataLHO.at(i)*m_scaling - m_scopeSizeV/2.0); + pulsePathLLO.lineTo(i, m_scopeSizeV - data.m_dataLLO.at(i)*m_scaling - m_scopeSizeV/2.0); + pulsePathVirgo.lineTo(i, m_scopeSizeV - data.m_dataVirgo.at(i)*m_scaling - m_scopeSizeV/2.0); } if(m_pathLHO == NULL) { - m_pathLHO = m_scene.addPath(pulsePathLHO, QPen(QColor(data.m_colorLHO), 0.2)); - m_pathLLO = m_scene.addPath(pulsePathLLO, QPen(QColor(data.m_colorLLO), 0.2)); - m_pathVirgo = m_scene.addPath(pulsePathVirgo, QPen(QColor(data.m_colorVirgo), 0.2)); + m_pathLHO = m_scene.addPath(pulsePathLHO, QPen(QBrush(QColor(data.m_colorLHO)), 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + m_pathLLO = m_scene.addPath(pulsePathLLO, QPen(QBrush(QColor(data.m_colorLLO)), 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + m_pathVirgo = m_scene.addPath(pulsePathVirgo, QPen(QBrush(QColor(data.m_colorVirgo)), 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); } else { m_pathLHO->setPath(pulsePathLHO); diff --git a/src/pulsescopewidget.h b/src/pulsescopewidget.h index 257940e..18b986b 100644 --- a/src/pulsescopewidget.h +++ b/src/pulsescopewidget.h @@ -53,10 +53,12 @@ private: QGraphicsPathItem *m_pathLLO; QGraphicsPathItem *m_pathVirgo; QGraphicsLineItem *m_xAxis; - QGraphicsLineItem *m_yAxis; double m_scopeSizeH; double m_scopeSizeV; + double m_scaling; + + const PlotData* m_data; }; #endif /* PULSESCOPEWIDGET_H_ */ -- GitLab