Commit 172d8f2f authored by Oliver Bock's avatar Oliver Bock

Added pulse scope widget

* Basic curve rendring (still using mock data vector)
* Basic axes: no ticks, no labels -> no Qwt ;-)
* Marker showing current pulse phase (normalized to one pulsar spin period)
* Communication with OpenGL widget
parent bb12283f
......@@ -23,8 +23,10 @@ QT += core \
gui \
opengl
HEADERS += src/pulsaranimationwidget.h \
src/pulsescopewidget.h \
src/pulsatingscience.h
SOURCES += src/pulsaranimationwidget.cpp \
src/pulsescopewidget.cpp \
src/pulsatingscience.cpp \
src/main.cpp
FORMS += src/pulsatingscience.ui
......
......@@ -330,6 +330,8 @@ void PulsarAnimationWidget::updateFrame()
}
updateGL();
emit pulsarAnimationStep(m_pulsarRotationDelta);
}
void PulsarAnimationWidget::showRotationAxes(bool enabled)
......@@ -353,13 +355,13 @@ void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
if((buttons & Qt::LeftButton) == Qt::LeftButton) {
if(m_mouseLastX != 0) {
m_mouseAngleH -= (m_mouseLastX - event->x()) / 2;
m_mouseAngleH = m_mouseAngleH < 360? m_mouseAngleH : 0;
m_mouseAngleH = m_mouseAngleH < 360 ? m_mouseAngleH : 0;
}
if(m_mouseLastY != 0) {
m_mouseAngleV -= (m_mouseLastY - event->y()) / 2;
m_mouseAngleV = m_mouseAngleV < 90? m_mouseAngleV : 90;
m_mouseAngleV = m_mouseAngleV > -90? m_mouseAngleV : -90;
m_mouseAngleV = m_mouseAngleV < 90 ? m_mouseAngleV : 90;
m_mouseAngleV = m_mouseAngleV > -90 ? m_mouseAngleV : -90;
}
m_mouseLastX = event->x();
......@@ -368,7 +370,7 @@ void PulsarAnimationWidget::mouseMoveEvent(QMouseEvent *event)
else if((buttons & Qt::RightButton) == Qt::RightButton) {
if(m_mouseLastY != 0) {
m_cameraZoom -= (m_mouseLastY - event->y()) / 2;
m_cameraZoom = m_cameraZoom >= m_cameraZoomLBound? m_cameraZoom : m_cameraZoomLBound;
m_cameraZoom = m_cameraZoom >= m_cameraZoomLBound ? m_cameraZoom : m_cameraZoomLBound;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
}
......@@ -476,4 +478,6 @@ void PulsarAnimationWidget::resetParameters()
{
m_pulsarRotationAngle = 0.0f;
m_orbitRotationAngle = 0.0f;
emit pulsarAnimationReset();
}
......@@ -56,6 +56,9 @@ public slots:
signals:
void pulsarSemiMajorAxisUpdated(double value);
void pulsarViewDataUpdated(const QVector<float>& data);
void pulsarAnimationStep(float stepSize);
void pulsarAnimationReset();
protected:
void initializeGL();
......
......@@ -44,6 +44,15 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(ui.pulsarGlWidget, SIGNAL(pulsarSemiMajorAxisUpdated(double)),
this, SLOT(updatePulsarSemiMajorAxisValue(double)));
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationStep(float)),
ui.pulseScopeWidget, SLOT(markerStep(float)));
connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()),
ui.pulseScopeWidget, SLOT(markerReset()));
connect(ui.pulsarGlWidget, SIGNAL(pulsarViewDataUpdated(const QVector<float>&)),
ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)));
on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value());
on_radioCompanionNS_toggled(true);
......
......@@ -19,7 +19,40 @@
<widget class="QWidget" name="centralwidget" >
<layout class="QGridLayout" name="gridLayout" >
<item row="0" column="0" >
<widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" />
<widget class="QSplitter" name="splitter" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<widget class="PulsarAnimationWidget" native="1" name="pulsarGlWidget" >
<zorder>graphicsView</zorder>
</widget>
<widget class="PulseScopeWidget" name="pulseScopeWidget" >
<property name="frameShape" >
<enum>QFrame::NoFrame</enum>
</property>
<property name="verticalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy" >
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="backgroundBrush" >
<brush brushstyle="SolidPattern" >
<color alpha="255" >
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</property>
<property name="interactive" >
<bool>false</bool>
</property>
<property name="renderHints" >
<set>QPainter::HighQualityAntialiasing</set>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
......@@ -36,7 +69,7 @@
</attribute>
<widget class="QWidget" name="dockWidgetContents" >
<layout class="QGridLayout" name="gridLayout_3" >
<item row="0" column="1" >
<item row="1" column="1" >
<layout class="QGridLayout" name="gridLayout_2" >
<item row="2" column="0" >
<widget class="QLabel" name="label" >
......@@ -352,7 +385,7 @@
</item>
</layout>
</item>
<item row="0" column="0" >
<item row="1" column="0" >
<layout class="QVBoxLayout" name="verticalLayout" >
<item>
<widget class="QPushButton" name="pushRun" >
......@@ -636,6 +669,11 @@
<header>src/pulsaranimationwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PulseScopeWidget</class>
<extends>QGraphicsView</extends>
<header>src/pulsescopewidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="pulsatingscience.qrc" />
......
/******************************************************************************
* 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(),
m_marker()
{
m_scopeSizeH = 360;
m_scopeSizeV = 0;
setViewport(new QGLWidget(QGLFormat(QGL::AlphaChannel | QGL::SampleBuffers)));
setScene(&m_scene);
m_data.fill(0.0f, m_scopeSizeH);
m_marker.setPen(QPen(Qt::red));
// TODO: proof of concept only!
for(int i = 0; i < m_scopeSizeH; ++i) {
m_data[i] = pow(i-180,2);
}
drawCurve(m_data);
}
PulseScopeWidget::~PulseScopeWidget()
{
}
void PulseScopeWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
}
void PulseScopeWidget::drawCurve(const QVector<float>& vector)
{
m_data = vector;
if(m_marker.scene() == 0) {
m_marker.setLine(0.0, 0.0, 0.0, m_scopeSizeV);
m_scene.addItem(&m_marker);
}
// TODO: proof of concept only!
QVector<float> checkMax(m_data);
qSort(checkMax.begin(), checkMax.end());
m_scopeSizeV = (int)ceil(checkMax.last()) * 2;
m_scene.addLine(0.0f, 0.0f, 0.0f, m_scopeSizeV, QPen(Qt::white));
m_scene.addLine(0.0f, m_scopeSizeV / 2, m_scopeSizeH, m_scopeSizeV / 2, QPen(Qt::white));
QPainterPath pulsePath(QPoint(0.0f, m_scopeSizeV / 2));
for(int i = 0; i < m_scopeSizeH; ++i) {
pulsePath.lineTo(i,m_data[i]);
}
m_scene.addPath(pulsePath, QPen(Qt::green));
fitInView(m_scene.itemsBoundingRect(), Qt::IgnoreAspectRatio);
}
void PulseScopeWidget::markerStep(float stepSize) {
if(m_marker.line().x1() < m_scopeSizeH) {
QLineF line = m_marker.line();
line.translate(stepSize, 0);
m_marker.setLine(line);
}
else {
markerReset();
}
}
void PulseScopeWidget::markerReset() {
m_marker.setLine(0.0, 0.0, 0.0, m_scopeSizeV);
}
/******************************************************************************
* 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/>. *
* *
******************************************************************************/
#ifndef PULSESCOPEWIDGET_H_
#define PULSESCOPEWIDGET_H_
#include <cmath>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGLContext>
#include <QGraphicsLineItem>
class PulseScopeWidget : public QGraphicsView
{
Q_OBJECT
public:
PulseScopeWidget(QWidget *parent = 0);
virtual ~PulseScopeWidget();
void resizeEvent(QResizeEvent *event);
public slots:
void drawCurve(const QVector<float>& vector);
void markerStep(float stepSize);
void markerReset();
private:
QGraphicsScene m_scene;
QVector<float> m_data;
QGraphicsLineItem m_marker;
int m_scopeSizeH;
int m_scopeSizeV;
};
#endif /* PULSESCOPEWIDGET_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment