[qt] Add menu to toggle VSync

pull/110/head
Hleb Valoshka 2018-10-29 22:13:43 +03:00
parent b4a8279b40
commit 5e41e38a8a
3 changed files with 33 additions and 0 deletions

View File

@ -537,6 +537,9 @@ void CelestiaAppWindow::writeSettings()
settings.setValue("SyncTime", simulation->getSyncTime());
settings.setValue("FramesVisible", m_appCore->getFramesVisible());
settings.setValue("ActiveFrameVisible", m_appCore->getActiveFrameVisible());
#ifdef VIDEO_SYNC
settings.setValue("VSync", m_appCore->getRenderer()->getVideoSync());
#endif
// TODO: This is not a reliable way determine when local time is enabled, but it's
// all that CelestiaCore offers right now. useLocalTime won't ever be true when the system
@ -1221,6 +1224,10 @@ void CelestiaAppWindow::createMenus()
textureResolutionMenu->addAction(actions->mediumResAction);
textureResolutionMenu->addAction(actions->highResAction);
#ifdef VIDEO_SYNC
displayMenu->addSeparator();
displayMenu->addAction(actions->toggleVSyncAction);
#endif
/****** Bookmark menu ******/
bookmarkMenu = menuBar()->addMenu(_("&Bookmarks"));
@ -1272,6 +1279,19 @@ void CelestiaAppWindow::createMenus()
bool check;
QSettings settings;
settings.beginGroup("Preferences");
#ifdef VIDEO_SYNC
if (settings.contains("VSync"))
{
check = settings.value("VSync").toBool();
}
else
{
check = m_appCore->getRenderer()->getVideoSync();
}
actions->toggleVSyncAction->setChecked(check);
m_appCore->getRenderer()->setVideoSync(check);
#endif
if (settings.contains("FramesVisible"))
{
check = settings.value("FramesVisible").toBool();

View File

@ -202,6 +202,12 @@ CelestiaActions::CelestiaActions(QObject* parent,
lightTimeDelayAction->setToolTip("Subtract one-way light travel time to selected object");
connect(lightTimeDelayAction, SIGNAL(triggered()), this, SLOT(slotSetLightTimeDelay()));
toggleVSyncAction = createCheckableAction(_("Limit Frame Rate"), 0);
// toggleVSyncAction->setShortcut(QKeySequence("Ctrl+Y"));
toggleVSyncAction->setToolTip(_("Faintest visible magnitude based on field of view"));
connect(toggleVSyncAction, SIGNAL(triggered()), this, SLOT(slotToggleVsync()));
syncWithRenderer(appCore->getRenderer());
syncWithAppCore();
appCore->getRenderer()->addWatcher(this);
@ -392,6 +398,10 @@ void CelestiaActions::slotSetLightTimeDelay()
appCore->charEntered('-');
}
void CelestiaActions::slotToggleVsync()
{
appCore->getRenderer()->setVideoSync(!appCore->getRenderer()->getVideoSync());
}
// Convenience method to create a checkable action for a menu and set the data
// to the specified integer value.

View File

@ -39,6 +39,7 @@ Q_OBJECT
void slotSetTextureResolution();
void slotAdjustLimitingMagnitude();
void slotSetLightTimeDelay();
void slotToggleVsync();
private:
void syncWithRenderer(const Renderer* renderer);
@ -115,6 +116,8 @@ Q_OBJECT
QAction* increaseLimitingMagAction{ nullptr };
QAction* decreaseLimitingMagAction{ nullptr };
QAction* toggleVSyncAction{ nullptr };
private:
CelestiaCore* appCore;
};