diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp index 0549a4e4e21e06dba9ef677a56fb634b272c70af..8de8ae650e9383e71a6ab855e4e5086207118b1f 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 257940e592b3b8bfb80e0f48fc08aa8bbfe1c957..18b986b6fd31d6f33e5343c3a5f807366f0378cc 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_ */