diff --git a/pulsatingscience.pro b/pulsatingscience.pro index f326f327d3c9025c0cef49db825f58bcdf41f6e0..028f82cfcdbdb9a683d5f3bc391e909d0e96dc58 100644 --- a/pulsatingscience.pro +++ b/pulsatingscience.pro @@ -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 diff --git a/src/pulsaranimationwidget.cpp b/src/pulsaranimationwidget.cpp index 43767f4ec09733e3a21090927ab367593c3c3f0b..159e860f28ae9e3d75e7c91f5e5b1c9bb2f3b32e 100644 --- a/src/pulsaranimationwidget.cpp +++ b/src/pulsaranimationwidget.cpp @@ -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(); } diff --git a/src/pulsaranimationwidget.h b/src/pulsaranimationwidget.h index 30a51954772f3cc9a0478879667e230ae2f7a39a..246e7bb71dee01c4f5950a72bea33add084c233a 100644 --- a/src/pulsaranimationwidget.h +++ b/src/pulsaranimationwidget.h @@ -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(); diff --git a/src/pulsatingscience.cpp b/src/pulsatingscience.cpp index 2bfc730942f57fee53394f78931153653936db8c..70290d5c10951528b7a1db81f90f717f512ca023 100644 --- a/src/pulsatingscience.cpp +++ b/src/pulsatingscience.cpp @@ -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); diff --git a/src/pulsatingscience.ui b/src/pulsatingscience.ui index 3373bc1740e72eca72e326ea884d85dae2918703..6bf117ea63531de237ec8071b023256fbd95eca4 100644 --- a/src/pulsatingscience.ui +++ b/src/pulsatingscience.ui @@ -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" /> diff --git a/src/pulsescopewidget.cpp b/src/pulsescopewidget.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1097dd22dba26917ffb40b0aa432e1a2809029e2 --- /dev/null +++ b/src/pulsescopewidget.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * 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); +} diff --git a/src/pulsescopewidget.h b/src/pulsescopewidget.h new file mode 100644 index 0000000000000000000000000000000000000000..b5f547bfb76aa76132f4db5c135fe5fac21e8462 --- /dev/null +++ b/src/pulsescopewidget.h @@ -0,0 +1,56 @@ +/****************************************************************************** + * 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_ */