Commit 3c0e4962 authored by Oliver Bock's avatar Oliver Bock
Browse files

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
parent 6377d9eb
......@@ -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);
......
......@@ -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_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment