pulsescopewidget.cpp 4.71 KB
Newer Older
Oliver Bock's avatar
Oliver Bock committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/******************************************************************************
 *   Copyright (C) 2009 by Oliver Bock                                        *
 *   oliver.bock[AT]aei.mpg.de                                                *
 *                                                                            *
 *   This file is part of PulsatingScience.                                   *
 *                                                                            *
 *   PulsatingScience is free software: you can redistribute it and/or modify *
 *   it under the terms of the GNU General Public License as published        *
 *   by the Free Software Foundation, version 3 of the License.               *
 *                                                                            *
 *   PulsatingScience is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
 *   GNU General Public License for more details.                             *
 *                                                                            *
 *   You should have received a copy of the GNU General Public License        *
 *   along with PulsatingScience. If not, see <http://www.gnu.org/licenses/>. *
 *                                                                            *
 ******************************************************************************/

#include "pulsescopewidget.h"

PulseScopeWidget::PulseScopeWidget(QWidget *parent) : QGraphicsView(parent),
24
    m_scene()
Oliver Bock's avatar
Oliver Bock committed
25
{
26
27
    setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
    QGLWidget *glScope = (QGLWidget*) viewport();
Oliver Bock's avatar
Oliver Bock committed
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    QString msgThis = tr("pulse profile");
    if(!glScope->format().directRendering()) {
        QString msg = tr("Sorry, no direct rendering support for %1...");
        qWarning() << msg.arg(msgThis);
    }
    if(!glScope->format().doubleBuffer()) {
        QString msg = tr("Sorry, no double buffering support for %1...");
        qWarning() << msg.arg(msgThis);
    }
    if(!glScope->format().rgba()) {
        QString msg = tr("Sorry, no RGBA support for %1...");
        qWarning() << msg.arg(msgThis);
    }
    if(!glScope->format().alpha()) {
        QString msg = tr("Sorry, no alpha channel support for %1...");
        qWarning() << msg.arg(msgThis);
    }
    if(!glScope->format().sampleBuffers()) {
        QString msg = tr("Sorry, no multisampling support for %1...");
        qWarning() << msg.arg(msgThis);
    }
Oliver Bock's avatar
Oliver Bock committed
50

51
    m_scopeSizeH = 360.0 * PERIODS;
52
    m_scopeSizeV = 10.0;
Oliver Bock's avatar
Oliver Bock committed
53
    m_scaling = 1.0;
Oliver Bock's avatar
Oliver Bock committed
54

55
56
57
    m_pathLHO = NULL;
    m_pathLLO = NULL;
    m_pathVirgo = NULL;
Oliver Bock's avatar
Oliver Bock committed
58

Oliver Bock's avatar
Oliver Bock committed
59
    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));
60
    m_xAxis->setZValue(1);
61

62
    setScene(&m_scene);
Oliver Bock's avatar
Oliver Bock committed
63
64
65
66
}

PulseScopeWidget::~PulseScopeWidget()
{
67
    m_scene.clear();
Oliver Bock's avatar
Oliver Bock committed
68
69
70
71
}

void PulseScopeWidget::resizeEvent(QResizeEvent *event)
{
72
    Q_UNUSED(event);
Oliver Bock's avatar
Oliver Bock committed
73

Oliver Bock's avatar
Oliver Bock committed
74
75
76
77
78
79
    // 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);
Oliver Bock's avatar
Oliver Bock committed
80
81
}

82
void PulseScopeWidget::plot(const PlotData& data)
Oliver Bock's avatar
Oliver Bock committed
83
{
Oliver Bock's avatar
Oliver Bock committed
84
85
86
87
88
89
    // 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));
Oliver Bock's avatar
Oliver Bock committed
90

91
    for(int i = 1; i < m_scopeSizeH; ++i) {
Oliver Bock's avatar
Oliver Bock committed
92
93
94
        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);
95
    }
96
    if(m_pathLHO == NULL) {
Oliver Bock's avatar
Oliver Bock committed
97
98
99
        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));
100
101
    }
    else {
102
103
104
        m_pathLHO->setPath(pulsePathLHO);
        m_pathLLO->setPath(pulsePathLLO);
        m_pathVirgo->setPath(pulsePathVirgo);
105
    }
Oliver Bock's avatar
Oliver Bock committed
106
}