pulsescopewidget.cpp 3.56 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 25
    m_scene(),
    m_data()
Oliver Bock's avatar
Oliver Bock committed
26
{
27 28
    setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
    QGLWidget *glScope = (QGLWidget*) viewport();
Oliver Bock's avatar
Oliver Bock committed
29

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    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);
    }
51

52 53
    m_scopeSizeH = 360.0;
    m_scopeSizeV = 1.0;
Oliver Bock's avatar
Oliver Bock committed
54

55 56 57
    m_path = NULL;
    m_marker = m_scene.addLine(0.0, 0.0, 0.0, m_scopeSizeV, QPen(Qt::red));
    m_marker->setZValue(1);
Oliver Bock's avatar
Oliver Bock committed
58

59
    setScene(&m_scene);
60

61 62
    m_data.fill(0.0, qRound(m_scopeSizeH));
    drawCurve(m_data);
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

74
    fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
Oliver Bock's avatar
Oliver Bock committed
75 76
}

77
void PulseScopeWidget::drawCurve(const QVector<double>& vector)
Oliver Bock's avatar
Oliver Bock committed
78
{
79
    m_data = vector;
Oliver Bock's avatar
Oliver Bock committed
80

81 82 83 84 85 86 87 88 89 90
    QPainterPath pulsePath(QPointF(0.0, m_scopeSizeV - m_data.at(0)));
    for(int i = 1; i < m_scopeSizeH; ++i) {
        pulsePath.lineTo(i, m_scopeSizeV - m_data.at(i));
    }
    if(m_path == NULL) {
        m_path = m_scene.addPath(pulsePath, QPen(Qt::yellow));
    }
    else {
        m_path->setPath(pulsePath);
    }
Oliver Bock's avatar
Oliver Bock committed
91 92
}

93
void PulseScopeWidget::setMarker(double position) {
94
    m_marker->setLine(position, 0.0, position, m_scopeSizeV);
Oliver Bock's avatar
Oliver Bock committed
95
}