Skip to content
Snippets Groups Projects
Select Git revision
  • 2d08a536e88c7b5d91cf46f7b60da9d893f65988
  • master default protected
2 results

test_hom.py

Blame
  • pulsescopewidget.cpp 3.42 KiB
    /******************************************************************************
     *   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),
    	m_scene(),
    	m_data()
    {
    	setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
    	QGLWidget *glScope = (QGLWidget*) viewport();
    
    	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);
    	}
    
    	m_scopeSizeH = 360.0;
    	m_scopeSizeV = 1.0;
    
    	m_path = NULL;
    	m_marker = m_scene.addLine(0.0, 0.0, 0.0, m_scopeSizeV, QPen(Qt::red));
    	m_marker->setZValue(1);
    
    	setScene(&m_scene);
    
    	m_data.fill(0.0, m_scopeSizeH);
    	drawCurve(m_data);
    }
    
    PulseScopeWidget::~PulseScopeWidget()
    {
    	m_scene.clear();
    }
    
    void PulseScopeWidget::resizeEvent(QResizeEvent *event)
    {
    	Q_UNUSED(event);
    
    	fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
    }
    
    void PulseScopeWidget::drawCurve(const QVector<double>& vector)
    {
    	m_data = vector;
    
    	QPainterPath pulsePath(QPoint(0.0, m_scopeSizeV));
    	for(int i = 0; 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);
    	}
    
    	fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
    }
    
    void PulseScopeWidget::setMarker(double position) {
    	m_marker->setLine(position, 0.0, position, m_scopeSizeV);
    }