The system was upgraded and everything is back online. If you experience any issues, please send an email to atlas_admin@aei.mpg.de - thanks a lot for your patience!

pulsescopewidget.cpp 3.34 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 24
/******************************************************************************
 *   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(),
25
	m_data()
Oliver Bock's avatar
Oliver Bock committed
26
{
Oliver Bock's avatar
Oliver Bock committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
	setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
	QGLWidget *glScope = (QGLWidget*) viewport();
	if(!glScope->format().directRendering()) {
		qWarning("Sorry, no direct rendering support for pulse scope...");
	}
	if(!glScope->format().doubleBuffer()) {
		qWarning("Sorry, no double buffering support for pulse scope...");
	}
	if(!glScope->format().rgba()) {
		qWarning("Sorry, no RGBA support for pulse scope...");
	}
	if(!glScope->format().alpha()) {
		qWarning("Sorry, no alpha channel support for pulse scope...");
	}
	if(!glScope->format().sampleBuffers()) {
		qWarning("Sorry, no multisampling support for pulse scope...");
	}

Oliver Bock's avatar
Oliver Bock committed
45 46
	m_scopeSizeH = 360.0f;
	m_scopeSizeV = 1.0f;
Oliver Bock's avatar
Oliver Bock committed
47

48
	m_path = NULL;
49
	m_marker = m_scene.addLine(0.0f, 0.0f, 0.0f, m_scopeSizeV, QPen(Qt::red));
50
	m_marker->setZValue(1);
Oliver Bock's avatar
Oliver Bock committed
51

52 53
	setScene(&m_scene);

54
	m_data.fill(0.0f, m_scopeSizeH);
Oliver Bock's avatar
Oliver Bock committed
55 56 57 58 59
	drawCurve(m_data);
}

PulseScopeWidget::~PulseScopeWidget()
{
60
	m_scene.clear();
Oliver Bock's avatar
Oliver Bock committed
61 62 63 64 65 66 67 68 69 70 71 72 73
}

void PulseScopeWidget::resizeEvent(QResizeEvent *event)
{
	Q_UNUSED(event);

	fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
}

void PulseScopeWidget::drawCurve(const QVector<float>& vector)
{
	m_data = vector;

Oliver Bock's avatar
Oliver Bock committed
74
	QPainterPath pulsePath(QPoint(0.0f, m_scopeSizeV));
Oliver Bock's avatar
Oliver Bock committed
75
	for(int i = 0; i < m_scopeSizeH; ++i) {
Oliver Bock's avatar
Oliver Bock committed
76
		pulsePath.lineTo(i, m_scopeSizeV - m_data.at(i));
Oliver Bock's avatar
Oliver Bock committed
77
	}
78 79 80 81 82
	if(m_path == NULL) {
		m_path = m_scene.addPath(pulsePath, QPen(Qt::yellow));
	}
	else {
		m_path->setPath(pulsePath);
83
	}
Oliver Bock's avatar
Oliver Bock committed
84 85 86
}

void PulseScopeWidget::markerStep(float stepSize) {
87 88 89 90 91
	static float x = 0.0f;

	if(x < m_scopeSizeH) {
		x += stepSize;
		m_marker->setLine(x, 0.0f, x, m_scopeSizeV);
Oliver Bock's avatar
Oliver Bock committed
92 93
	}
	else {
Oliver Bock's avatar
Oliver Bock committed
94
		x -= m_scopeSizeH;
Oliver Bock's avatar
Oliver Bock committed
95 96 97 98
	}
}

void PulseScopeWidget::markerReset() {
99
	m_marker->setLine(0.0f, 0.0f, 0.0f, m_scopeSizeV);
Oliver Bock's avatar
Oliver Bock committed
100
}