pulsatingscience.cpp 10.5 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
25
/******************************************************************************
 *   Copyright (C) 2008 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 "pulsatingscience.h"

PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
{
	ui.setupUi(this);
26

Oliver Bock's avatar
Oliver Bock committed
27
28
	QAction* animControl = ui.dockAnimControl->toggleViewAction();
	animControl->setStatusTip("Toggle the animation control visibility");
29
	animControl->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A));
Oliver Bock's avatar
Oliver Bock committed
30
	ui.menuView->addAction(animControl);
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	// inital status (based on GUI)
	m_rotationAxesVisible = ui.actionRotationAxes->isChecked();
    m_menuBarVisible = ui.actionMenu_bar->isChecked();
	m_statusBarVisible = ui.actionStatus_bar->isChecked();
	m_animControlVisible = true;
	m_animControlFloating = ui.dockAnimControl->isFloating();

	// register alternate shortcuts (will be enabled when menu is hidden)
	m_rotationAxesShortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_R), this);
	m_rotationAxesShortcut->setEnabled(false);
	m_menuBarShortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_M), this);
	m_menuBarShortcut->setEnabled(false);
	m_fullscreenShortcut = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_F), this);
	m_fullscreenShortcut->setEnabled(false);

	// TODO: register all remaining shortcuts, too (to use them while menu is hidden!)

49
50
51
52
53
54
55
56
57
	connect(ui.actionRun, SIGNAL(activated()),
			ui.pulsarGlWidget, SLOT(runAnimation()));

	connect(ui.actionPause, SIGNAL(activated()),
				ui.pulsarGlWidget, SLOT(pauseAnimation()));

	connect(ui.actionStop, SIGNAL(activated()),
				ui.pulsarGlWidget, SLOT(stopAnimation()));

Oliver Bock's avatar
Oliver Bock committed
58
59
60
	connect(ui.actionRotationAxes, SIGNAL(toggled(bool)),
				ui.pulsarGlWidget, SLOT(showRotationAxes(bool)));

Oliver Bock's avatar
Oliver Bock committed
61
62
63
	connect(ui.pulsarGlWidget, SIGNAL(pulsarSemiMajorAxisUpdated(double)),
				this, SLOT(updatePulsarSemiMajorAxisValue(double)));

Oliver Bock's avatar
Oliver Bock committed
64
65
66
67
68
69
	connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationStep(float)),
				ui.pulseScopeWidget, SLOT(markerStep(float)));

	connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationReset()),
				ui.pulseScopeWidget, SLOT(markerReset()));

70
	connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<float>&)),
Oliver Bock's avatar
Oliver Bock committed
71
72
				ui.pulseScopeWidget, SLOT(drawCurve(const QVector<float>&)));

73
74

	// initialize animation parameters (using GUI settings)
Oliver Bock's avatar
Oliver Bock committed
75
76
77
78
79
	on_sliderPulsarSemiMajorAxis_valueChanged(ui.sliderPulsarSemiMajorAxis->value());

	on_radioCompanionNS_toggled(true);
	on_sliderPulsarMass_valueChanged(ui.sliderPulsarMass->value());

Oliver Bock's avatar
Oliver Bock committed
80
	on_sliderPulsarSpinFrequency_valueChanged(ui.sliderPulsarSpinFrequency->value());
81
82
	on_sliderPulsarSpinAxisInclination_valueChanged(ui.sliderPulsarSpinAxisInclination->value());
	on_sliderPulsarMagneticAxisInclination_valueChanged(ui.sliderPulsarMagneticAxisInclination->value());
Oliver Bock's avatar
Oliver Bock committed
83
84
85
86
}

PulsatingScience::~PulsatingScience()
{
87
88
89
90
91
92
93
94
95
	if(m_rotationAxesShortcut) {
		m_rotationAxesShortcut->disconnect();
		delete m_rotationAxesShortcut;
	}

	if(m_menuBarShortcut) {
		m_menuBarShortcut->disconnect();
		delete m_menuBarShortcut;
	}
Oliver Bock's avatar
Oliver Bock committed
96

97
98
99
100
	if(m_fullscreenShortcut) {
		m_fullscreenShortcut->disconnect();
		delete m_fullscreenShortcut;
	}
Oliver Bock's avatar
Oliver Bock committed
101
}
102

Oliver Bock's avatar
Oliver Bock committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
void PulsatingScience::on_pushRun_clicked()
{
	if(ui.pushRun->isEnabled()) {
		ui.pushRun->setEnabled(false);
		ui.pushPause->setEnabled(true);
		ui.pushStop->setEnabled(true);
	}
	else {
		ui.pushRun->setEnabled(true);
		ui.pushPause->setEnabled(false);
		ui.pushStop->setEnabled(false);
	}
}

void PulsatingScience::on_pushPause_clicked()
{
	ui.pushRun->setEnabled(true);
	ui.pushPause->setEnabled(false);
	ui.pushStop->setEnabled(true);
}

void PulsatingScience::on_pushStop_clicked()
{
	ui.pushRun->setEnabled(true);
	ui.pushPause->setEnabled(false);
	ui.pushStop->setEnabled(false);
}

Oliver Bock's avatar
Oliver Bock committed
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
void PulsatingScience::on_radioCompanionWD_toggled(bool checked)
{
	if(checked) {
		ui.pulsarGlWidget->setCompanionMass(0.6f);
		ui.lcdCompanionMass->display(QString::number(0.6f, 'f', 1));
	}
}

void PulsatingScience::on_radioCompanionSun_toggled(bool checked)
{
	if(checked) {
		ui.pulsarGlWidget->setCompanionMass(1.0f);
		ui.lcdCompanionMass->display(QString::number(1.0f, 'f', 1));
	}
}

void PulsatingScience::on_radioCompanionNS_toggled(bool checked)
{
	if(checked) {
		ui.pulsarGlWidget->setCompanionMass(1.4f);
		ui.lcdCompanionMass->display(QString::number(1.4f, 'f', 1));
	}
}

void PulsatingScience::on_sliderPulsarMass_valueChanged(int value)
{
	ui.pulsarGlWidget->setPulsarMass(value * 0.1f);
	ui.lcdPulsarMass->display(QString::number(value * 0.1f, 'f', 1));
}

Oliver Bock's avatar
Oliver Bock committed
161
void PulsatingScience::on_sliderPulsarSpinFrequency_valueChanged(int value)
162
{
Oliver Bock's avatar
Oliver Bock committed
163
164
	ui.pulsarGlWidget->setPulsarSpinFrequency(value * 0.1f);
	ui.lcdPulsarSpinFrequency->display(QString::number(value * 0.1f, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
165
166
}

167
168
169
170
171
172
void PulsatingScience::on_sliderPulsarSpinAxisInclination_valueChanged(int value)
{
	ui.pulsarGlWidget->setPulsarSpinAxisInclination(value);
	ui.lcdPulsarSpinAxisInclination->display(QString::number(value));
}

173
174
175
176
177
178
void PulsatingScience::on_sliderPulsarMagneticAxisInclination_valueChanged(int value)
{
	ui.pulsarGlWidget->setPulsarMagneticAxisInclination(value);
	ui.lcdPulsarMagneticAxisInclination->display(QString::number(value));
}

Oliver Bock's avatar
Oliver Bock committed
179
void PulsatingScience::on_sliderPulsarSemiMajorAxis_valueChanged(int value)
Oliver Bock's avatar
Oliver Bock committed
180
{
Oliver Bock's avatar
Oliver Bock committed
181
182
	ui.pulsarGlWidget->setPulsarSemiMajorAxis(value * 0.001f);
	ui.lcdPulsarSemiMajorAxis->display(QString::number(value * 0.001f, 'f', 1));
183
	ui.lcdPulsarSemiMajorAxis->setStyleSheet("color: black");
184
}
Oliver Bock's avatar
Oliver Bock committed
185

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
void PulsatingScience::rotationAxesToggled() {
	if(m_rotationAxesVisible) {
		on_actionRotationAxes_toggled(false);
		ui.actionRotationAxes->setChecked(false);
	}
	else {
		on_actionRotationAxes_toggled(true);
		ui.actionRotationAxes->setChecked(true);
	}
}

void PulsatingScience::on_actionRotationAxes_toggled(bool checked) {
	m_rotationAxesVisible = checked;
}

void PulsatingScience::menuBarToggled()
{
	if(ui.menuBar->isVisible()) {
		on_actionMenu_bar_toggled(false);
		ui.actionMenu_bar->setChecked(false);
	}
	else {
		on_actionMenu_bar_toggled(true);
		ui.actionMenu_bar->setChecked(true);
	}
}

Oliver Bock's avatar
Oliver Bock committed
213
214
void PulsatingScience::on_actionMenu_bar_toggled(bool checked)
{
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
	if(checked) {
		ui.menuBar->show();
		m_menuBarVisible = true;

		// deactivate alternate shortcuts
		m_rotationAxesShortcut->disconnect();
		m_rotationAxesShortcut->setEnabled(false);
		m_fullscreenShortcut->disconnect();
		m_fullscreenShortcut->setEnabled(false);
		m_menuBarShortcut->disconnect();
		m_menuBarShortcut->setEnabled(false);
	}
	else {
		ui.menuBar->hide();
		m_menuBarVisible = false;

		// activate alternate shortcuts
		m_rotationAxesShortcut->setEnabled(true);
		connect(m_rotationAxesShortcut, SIGNAL(activated()), this, SLOT(rotationAxesToggled()));
		m_fullscreenShortcut->setEnabled(true);
		connect(m_fullscreenShortcut, SIGNAL(activated()), this, SLOT(fullscreenToggled()));
		m_menuBarShortcut->setEnabled(true);
		connect(m_menuBarShortcut, SIGNAL(activated()), this, SLOT(menuBarToggled()));
	}
}

void PulsatingScience::fullscreenToggled()
{
	if((windowState() & Qt::WindowFullScreen) > 0) {
		on_actionFullscreen_toggled(false);
		ui.actionFullscreen->setChecked(false);
	}
	else {
		on_actionFullscreen_toggled(true);
		ui.actionFullscreen->setChecked(true);
	}
}

void PulsatingScience::on_actionFullscreen_toggled(bool checked)
{
	if(checked) {
		window()->setWindowState(windowState() | Qt::WindowFullScreen);
		// assuming text being black
		setBackgroundRole(QPalette::Text);

		if(m_menuBarVisible) {
			on_actionMenu_bar_toggled(false);
			// keep visibility setting
			m_menuBarVisible = true;
		}
		if(m_statusBarVisible) ui.statusbar->hide();
		if(m_animControlVisible && !m_animControlFloating) {
			ui.dockAnimControl->hide();
			// keep visibility setting
			m_animControlVisible = true;
		}
	}
	else {
		window()->setWindowState(windowState() & ~Qt::WindowFullScreen);
		setBackgroundRole(QPalette::Window);

		if(m_menuBarVisible) on_actionMenu_bar_toggled(true);
		if(m_statusBarVisible) ui.statusbar->show();
		if(m_animControlVisible && !m_animControlFloating) ui.dockAnimControl->show();
	}
Oliver Bock's avatar
Oliver Bock committed
280
281
282
283
}

void PulsatingScience::on_actionStatus_bar_toggled(bool checked)
{
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	if(checked) {
		ui.statusbar->show();
		m_statusBarVisible = true;
	}
	else {
		ui.statusbar->hide();
		m_statusBarVisible = false;
	}
}

void PulsatingScience::on_dockAnimControl_visibilityChanged(bool visible) {
	m_animControlVisible = visible;
}

void PulsatingScience::on_dockAnimControl_topLevelChanged(bool topLevel) {
	m_animControlFloating = topLevel;
Oliver Bock's avatar
Oliver Bock committed
300
}
Oliver Bock's avatar
Oliver Bock committed
301
302
303
304
305
306
307

void PulsatingScience::on_actionAbout_activated()
{
	QMessageBox::about(this, "About",
			"<b>Pulsating Science</b><br>"
			"International Year of Astronomy 2009<br><br>"
			"Authors: Oliver Bock, Benjamin Knispel<br><br>"
308
			"Background image: The Carina Nebula<br>"
309
310
			"(Courtesy of ESO/IDA/Danish 1.5 m/R.Gendler, J-E. Ovaldsen, C. Th&ouml;ne and C. Feron)<br><br>"
			"License: GNU General Public License (Version 3)<br><br>"
Oliver Bock's avatar
Oliver Bock committed
311
312
313
			"Copyright &copy; 2009 "
			"<a href=\"http://www.aei.mpg.de\">Max-Planck-Institut f&uuml;r Gravitationsphysik</a>");
}
Oliver Bock's avatar
Oliver Bock committed
314
315
316
317

void PulsatingScience::updatePulsarSemiMajorAxisValue(double value)
{
	ui.sliderPulsarSemiMajorAxis->setValue(value * 1000.0);
318

319
320
321
322
323
324
325
	if((int)value <= 1 || (int)value >= 20) {
		if((int)value < 1 || (int)value > 20) {
			ui.lcdPulsarSemiMajorAxis->setStyleSheet("color: red");
		}
		else {
			ui.lcdPulsarSemiMajorAxis->setStyleSheet("color: black");
		}
326
327
		ui.lcdPulsarSemiMajorAxis->display(QString::number(value, 'f', 1));
	}
Oliver Bock's avatar
Oliver Bock committed
328
}