pulsatingscience.cpp 12.7 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
	QAction* animControl = ui.dockAnimControl->toggleViewAction();
Oliver Bock's avatar
Oliver Bock committed
28
	animControl->setStatusTip(tr("Toggle the animation control visibility"));
29
	animControl->setShortcut(QKeySequence(tr("Alt+A")));
Oliver Bock's avatar
Oliver Bock committed
30
	ui.menuView->addAction(animControl);
31

32
	// inital status (based on GUI)
33
	m_permanentOrbits = ui.actionPermanent_orbits->isChecked();
34
35
36
37
38
39
40
	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)
41
42
43
44
45
46
	m_runShortcut = new QShortcut(ui.actionRun->shortcut(), this);
	m_runShortcut->setEnabled(false);
	m_pauseShortcut = new QShortcut(ui.actionPause->shortcut(), this);
	m_pauseShortcut->setEnabled(false);
	m_stopShortcut = new QShortcut(ui.actionStop->shortcut(), this);
	m_stopShortcut->setEnabled(false);
47
48
	m_permanentOrbitsShortcut = new QShortcut(ui.actionPermanent_orbits->shortcut(), this);
	m_permanentOrbitsShortcut->setEnabled(false);
49
	m_rotationAxesShortcut = new QShortcut(ui.actionRotationAxes->shortcut(), this);
50
	m_rotationAxesShortcut->setEnabled(false);
51
	m_menuBarShortcut = new QShortcut(ui.actionMenu_bar->shortcut(), this);
52
	m_menuBarShortcut->setEnabled(false);
53
	m_fullscreenShortcut = new QShortcut(ui.actionFullscreen->shortcut(), this);
54
55
	m_fullscreenShortcut->setEnabled(false);

56
	// establish object communications
57
58
59
	connect(ui.pushRun, SIGNAL(clicked()),
			ui.pulsarGlWidget, SLOT(runAnimation()));

60
61
62
	connect(ui.actionRun, SIGNAL(activated()),
			ui.pulsarGlWidget, SLOT(runAnimation()));

63
64
65
66
67
68
	connect(ui.actionRun, SIGNAL(activated()),
				this, SLOT(on_pushRun_clicked()));

	connect(ui.pushPause, SIGNAL(clicked()),
			ui.pulsarGlWidget, SLOT(pauseAnimation()));

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

72
73
74
75
76
77
	connect(ui.actionPause, SIGNAL(activated()),
				this, SLOT(on_pushPause_clicked()));

	connect(ui.pushStop, SIGNAL(clicked()),
			ui.pulsarGlWidget, SLOT(stopAnimation()));

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

81
82
83
	connect(ui.actionStop, SIGNAL(activated()),
				this, SLOT(on_pushStop_clicked()));

84
85
86
	connect(ui.actionPermanent_orbits, SIGNAL(toggled(bool)),
				ui.pulsarGlWidget, SLOT(showOrbits(bool)));

Oliver Bock's avatar
Oliver Bock committed
87
88
89
	connect(ui.actionRotationAxes, SIGNAL(toggled(bool)),
				ui.pulsarGlWidget, SLOT(showRotationAxes(bool)));

Oliver Bock's avatar
Oliver Bock committed
90
91
92
	connect(ui.pulsarGlWidget, SIGNAL(pulsarSemiMajorAxisUpdated(double)),
				this, SLOT(updatePulsarSemiMajorAxisValue(double)));

Oliver Bock's avatar
Oliver Bock committed
93
	connect(ui.pulsarGlWidget, SIGNAL(pulsarAnimationStep(double)),
94
				ui.pulseScopeWidget, SLOT(setMarker(double)), Qt::DirectConnection);
Oliver Bock's avatar
Oliver Bock committed
95

Oliver Bock's avatar
Oliver Bock committed
96
97
	connect(ui.pulsarGlWidget, SIGNAL(pulseProfileUpdated(const QVector<double>&)),
				ui.pulseScopeWidget, SLOT(drawCurve(const QVector<double>&)), Qt::DirectConnection);
Oliver Bock's avatar
Oliver Bock committed
98
99
100
101
}

PulsatingScience::~PulsatingScience()
{
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	if(m_runShortcut) {
		m_runShortcut->disconnect();
		delete m_runShortcut;
	}

	if(m_pauseShortcut) {
		m_pauseShortcut->disconnect();
		delete m_pauseShortcut;
	}

	if(m_stopShortcut) {
		m_stopShortcut->disconnect();
		delete m_stopShortcut;
	}

117
118
119
120
121
	if(m_permanentOrbitsShortcut) {
		m_permanentOrbitsShortcut->disconnect();
		delete m_permanentOrbitsShortcut;
	}

122
123
124
125
126
127
128
129
130
	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
131

132
133
134
135
	if(m_fullscreenShortcut) {
		m_fullscreenShortcut->disconnect();
		delete m_fullscreenShortcut;
	}
Oliver Bock's avatar
Oliver Bock committed
136
}
137

Oliver Bock's avatar
Oliver Bock committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
166
167
168
void PulsatingScience::on_radioCompanionWD_toggled(bool checked)
{
	if(checked) {
Oliver Bock's avatar
Oliver Bock committed
169
170
		ui.pulsarGlWidget->setCompanionMass(0.6);
		ui.lcdCompanionMass->display(QString::number(0.6, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
171
172
173
174
175
176
	}
}

void PulsatingScience::on_radioCompanionSun_toggled(bool checked)
{
	if(checked) {
Oliver Bock's avatar
Oliver Bock committed
177
178
		ui.pulsarGlWidget->setCompanionMass(1.0);
		ui.lcdCompanionMass->display(QString::number(1.0, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
179
180
181
182
183
184
	}
}

void PulsatingScience::on_radioCompanionNS_toggled(bool checked)
{
	if(checked) {
Oliver Bock's avatar
Oliver Bock committed
185
186
		ui.pulsarGlWidget->setCompanionMass(1.4);
		ui.lcdCompanionMass->display(QString::number(1.4, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
187
188
189
190
191
	}
}

void PulsatingScience::on_sliderPulsarMass_valueChanged(int value)
{
Oliver Bock's avatar
Oliver Bock committed
192
193
	ui.pulsarGlWidget->setPulsarMass(value * 0.1);
	ui.lcdPulsarMass->display(QString::number(value * 0.1, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
194
195
}

Oliver Bock's avatar
Oliver Bock committed
196
void PulsatingScience::on_sliderPulsarSpinFrequency_valueChanged(int value)
197
{
Oliver Bock's avatar
Oliver Bock committed
198
199
	ui.pulsarGlWidget->setPulsarSpinFrequency(value * 0.1);
	ui.lcdPulsarSpinFrequency->display(QString::number(value * 0.1, 'f', 1));
Oliver Bock's avatar
Oliver Bock committed
200
201
}

202
203
204
205
206
207
void PulsatingScience::on_sliderPulsarSpinAxisInclination_valueChanged(int value)
{
	ui.pulsarGlWidget->setPulsarSpinAxisInclination(value);
	ui.lcdPulsarSpinAxisInclination->display(QString::number(value));
}

208
209
210
211
212
213
void PulsatingScience::on_sliderPulsarMagneticAxisInclination_valueChanged(int value)
{
	ui.pulsarGlWidget->setPulsarMagneticAxisInclination(value);
	ui.lcdPulsarMagneticAxisInclination->display(QString::number(value));
}

Oliver Bock's avatar
Oliver Bock committed
214
void PulsatingScience::on_sliderPulsarSemiMajorAxis_valueChanged(int value)
Oliver Bock's avatar
Oliver Bock committed
215
{
Oliver Bock's avatar
Oliver Bock committed
216
217
	ui.pulsarGlWidget->setPulsarSemiMajorAxis(value * 0.001);
	ui.lcdPulsarSemiMajorAxis->display(QString::number(value * 0.001, 'f', 1));
218
	ui.lcdPulsarSemiMajorAxis->setStyleSheet("color: black");
219
}
Oliver Bock's avatar
Oliver Bock committed
220

221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
void PulsatingScience::permanentOrbitsToggled() {
	if(m_permanentOrbits) {
		on_actionPermanent_orbits_toggled(false);
		ui.actionPermanent_orbits->setChecked(false);
	}
	else {
		on_actionPermanent_orbits_toggled(true);
		ui.actionPermanent_orbits->setChecked(true);
	}
}

void PulsatingScience::on_actionPermanent_orbits_toggled(bool checked) {
	m_permanentOrbits = checked;
}

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
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);
	}
257
258
	else if(!ui.actionFullscreen->isChecked()) {
		// allow menu bar only when NOT in fullscreen mode
259
260
261
262
263
		on_actionMenu_bar_toggled(true);
		ui.actionMenu_bar->setChecked(true);
	}
}

Oliver Bock's avatar
Oliver Bock committed
264
265
void PulsatingScience::on_actionMenu_bar_toggled(bool checked)
{
266
267
268
269
270
	if(checked) {
		ui.menuBar->show();
		m_menuBarVisible = true;

		// deactivate alternate shortcuts
271
272
273
274
275
276
		m_runShortcut->disconnect();
		m_runShortcut->setEnabled(false);
		m_pauseShortcut->disconnect();
		m_pauseShortcut->setEnabled(false);
		m_stopShortcut->disconnect();
		m_stopShortcut->setEnabled(false);
277
278
		m_permanentOrbitsShortcut->disconnect();
		m_permanentOrbitsShortcut->setEnabled(false);
279
280
281
282
283
284
285
286
287
288
289
290
		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
291
292
293
294
295
296
		m_runShortcut->setEnabled(true);
		connect(m_runShortcut, SIGNAL(activated()), ui.pulsarGlWidget, SLOT(runAnimation()));
		m_pauseShortcut->setEnabled(true);
		connect(m_pauseShortcut, SIGNAL(activated()), ui.pulsarGlWidget, SLOT(pauseAnimation()));
		m_stopShortcut->setEnabled(true);
		connect(m_stopShortcut, SIGNAL(activated()), ui.pulsarGlWidget, SLOT(stopAnimation()));
297
298
		m_permanentOrbitsShortcut->setEnabled(true);
		connect(m_permanentOrbitsShortcut, SIGNAL(activated()), this, SLOT(permanentOrbitsToggled()));
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
		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
347
348
349
350
}

void PulsatingScience::on_actionStatus_bar_toggled(bool checked)
{
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
	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
367
}
Oliver Bock's avatar
Oliver Bock committed
368
369
370

void PulsatingScience::on_actionAbout_activated()
{
Oliver Bock's avatar
Oliver Bock committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
	QString content = "<b>%1</b><br>"
		"%2<br><br>"
		"%3: Oliver Bock, Benjamin Knispel<br><br>"
		"%4<br>"
		"(%5 ESO/IDA/Danish 1.5 m/R.Gendler, J-E. Ovaldsen, C. Th&ouml;ne, C. Feron)<br><br>"
		"%6: GNU General Public License (Version 3)<br><br>"
		"Copyright &copy; 2009 "
		"<a href=\"http://www.aei.mpg.de\">Max-Planck-Institut f&uuml;r Gravitationsphysik</a>";

	content = content.arg(
		tr("Pulsating Science"),
		tr("International Year of Astronomy 2009"),
		tr("Authors"),
		tr("Background image: The Carina Nebula"),
		tr("Courtesy of"),
		tr("License"));

	QMessageBox::about(this, tr("About \"Pulsating Science\""), content);
Oliver Bock's avatar
Oliver Bock committed
389
}
Oliver Bock's avatar
Oliver Bock committed
390
391
392
393

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

395
396
397
398
399
400
401
	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");
		}
402
403
		ui.lcdPulsarSemiMajorAxis->display(QString::number(value, 'f', 1));
	}
Oliver Bock's avatar
Oliver Bock committed
404
}