Commit 779cc254 authored by Oliver Bock's avatar Oliver Bock

Added inactivity timer to reset animation parameters and camera settings to default values

* Resets animation parameters and camera settings to initial/default values
* Considered as activity: mouse press events
* Inactivity timeout: 10 minutes
* Currently only enabled in demo mode
parent 7027399b
......@@ -36,9 +36,12 @@ int main(int argc, char *argv[])
app.installTranslator(&appTranslator);
PulsatingScience window;
app.installEventFilter(&window);
if(argc == 2 && QString(argv[1]) == "--demo") {
window.toggleHiddenDemoMode();
}
window.show();
return app.exec();
......
......@@ -772,6 +772,22 @@ void PulsarAnimationWidget::setPulsarBeamAngle(const int degrees)
updateGL();
}
void PulsarAnimationWidget::getCameraPosition(double& cameraAngleH, double& cameraAngleV, double& cameraZoom)
{
cameraAngleH = m_mouseAngleH;
cameraAngleV = m_mouseAngleV;
cameraZoom = m_cameraZoom;
}
void PulsarAnimationWidget::resetCameraPosition(const double angleH, const double angleV, const double zoom)
{
m_mouseAngleH = angleH;
m_mouseAngleV = angleV;
m_cameraZoom = zoom;
updateCameraPosition(m_mouseAngleH, m_mouseAngleV, m_cameraZoom);
}
void PulsarAnimationWidget::updateOrbitPeriod()
{
m_orbitalPeriod = 3.1553e7 * sqrt(
......
......@@ -53,6 +53,8 @@ public:
void setPulsarMagneticAxisInclination(const int degrees);
void setPulsarSemiMajorAxis(const double length);
void setPulsarBeamAngle(const int degrees);
void getCameraPosition(double& cameraAngleH, double& cameraAngleV, double& cameraZoom);
void resetCameraPosition(const double angleH, const double angleV, const double zoom);
public slots:
void runAnimation();
......
......@@ -121,6 +121,11 @@ PulsatingScience::PulsatingScience(QWidget *parent) : QMainWindow(parent)
connect(m_hiddenShortcut, SIGNAL(activated()),
this, SLOT(toggleHiddenDemoMode()));
// prepare inactivity timer
saveOrRestoreInitialAnimationSettings();
m_inactivityTimer = new QTimer(this);
connect(m_inactivityTimer, SIGNAL(timeout()), this, SLOT(userInactivityCallback()));
// restore previously saved window and splitter layout
QCoreApplication::setOrganizationName("Max-Planck-Insitut für Gravitationsphysik");
QCoreApplication::setOrganizationDomain("aei.mpg.de");
......@@ -183,6 +188,10 @@ PulsatingScience::~PulsatingScience()
m_hiddenShortcut->disconnect();
delete m_hiddenShortcut;
}
if(m_inactivityTimer) {
delete m_inactivityTimer;
}
}
void PulsatingScience::closeEvent(QCloseEvent *event)
......@@ -523,6 +532,7 @@ void PulsatingScience::toggleHiddenDemoMode()
ui.dockAnimControl->setFeatures(QDockWidget::DockWidgetClosable
| QDockWidget::DockWidgetMovable
| QDockWidget::DockWidgetFloatable);
m_inactivityTimer->stop();
m_hiddenDemoModeActivated = false;
}
else {
......@@ -541,6 +551,74 @@ void PulsatingScience::toggleHiddenDemoMode()
ui.actionMenu_bar->setChecked(false);
window()->setWindowState(windowState() | Qt::WindowFullScreen);
ui.dockAnimControl->setFeatures(QDockWidget::NoDockWidgetFeatures);
m_inactivityTimer->start(600000);
m_hiddenDemoModeActivated = true;
}
}
bool PulsatingScience::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseButtonPress) {
userActivity();
}
// return original event (we don't want to change any behavior)
return QObject::eventFilter(obj, event);
}
void PulsatingScience::userActivity()
{
if(m_hiddenDemoModeActivated) {
// restart existing timer
m_inactivityTimer->start();
}
}
void PulsatingScience::userInactivityCallback()
{
saveOrRestoreInitialAnimationSettings();
}
void PulsatingScience::saveOrRestoreInitialAnimationSettings()
{
static bool initialized = false;
static bool radioCompanionWD;
static bool radioCompanionSun;
static bool radioCompanionNS;
static int sliderPulsarMass;
static int sliderPulsarSpinFrequency;
static int sliderPulsarSpinAxisInclination;
static int sliderPulsarMagneticAxisInclination;
static int sliderPulsarSemiMajorAxis;
static double cameraAngleH;
static double cameraAngleV;
static double cameraZoom;
if(initialized) {
// restore intial settings
ui.radioCompanionWD->setChecked(radioCompanionWD);
ui.radioCompanionSun->setChecked(radioCompanionSun);
ui.radioCompanionNS->setChecked(radioCompanionNS);
ui.sliderPulsarMass->setValue(sliderPulsarMass);
ui.sliderPulsarSpinFrequency->setValue(sliderPulsarSpinFrequency);
ui.sliderPulsarSpinAxisInclination->setValue(sliderPulsarSpinAxisInclination);
ui.sliderPulsarMagneticAxisInclination->setValue(sliderPulsarMagneticAxisInclination);
ui.sliderPulsarSemiMajorAxis->setValue(sliderPulsarSemiMajorAxis);
ui.pulsarGlWidget->resetCameraPosition(cameraAngleH, cameraAngleV, cameraZoom);
}
else {
// save initial settings
radioCompanionWD = ui.radioCompanionWD->isChecked();
radioCompanionSun = ui.radioCompanionSun->isChecked();
radioCompanionNS = ui.radioCompanionNS->isChecked();
sliderPulsarMass = ui.sliderPulsarMass->value();
sliderPulsarSpinFrequency = ui.sliderPulsarSpinFrequency->value();
sliderPulsarSpinAxisInclination = ui.sliderPulsarSpinAxisInclination->value();
sliderPulsarMagneticAxisInclination = ui.sliderPulsarMagneticAxisInclination->value();
sliderPulsarSemiMajorAxis = ui.sliderPulsarSemiMajorAxis->value();
ui.pulsarGlWidget->getCameraPosition(cameraAngleH, cameraAngleV, cameraZoom);
initialized = true;
}
}
......@@ -77,7 +77,15 @@ public slots:
void updatePulsarSemiMajorAxisValue(double value);
void toggleHiddenDemoMode();
void userInactivityCallback();
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
void userActivity();
void saveOrRestoreInitialAnimationSettings();
Ui::PulsatingScienceClass ui;
QShortcut *m_runShortcut;
......@@ -99,6 +107,8 @@ private:
bool m_animControlVisible;
bool m_animControlFloating;
bool m_hiddenDemoModeActivated;
QTimer *m_inactivityTimer;
};
#endif // PULSATINGSCIENCE_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