pulsescopewidget.cpp 3.36 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
	setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
	QGLWidget *glScope = (QGLWidget*) viewport();
Oliver Bock's avatar
Oliver Bock committed
29 30

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

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

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

59 60
	setScene(&m_scene);

Oliver Bock's avatar
Oliver Bock committed
61
	m_data.fill(0.0, m_scopeSizeH);
Oliver Bock's avatar
Oliver Bock committed
62 63 64 65 66
	drawCurve(m_data);
}

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

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

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

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

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

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