Qt: Show version info in window title

This commit is contained in:
Jeffrey Pfau 2015-05-15 09:11:12 -07:00
parent 47d945bf75
commit e2b964a8be
3 changed files with 32 additions and 13 deletions

View File

@ -33,6 +33,7 @@ Misc:
- GBA Thread: Add functionality for running callbacks on the GBA thread
- Qt: Fast forward (held) option moved from Other to Emulation menu
- All: Add --help flag for command line programs
- Qt: Show version info in window title
0.2.1: (2015-05-13)
Bugfixes:

View File

@ -62,12 +62,12 @@ Window::Window(ConfigController* config, int playerId, QWidget* parent)
, m_shortcutController(new ShortcutController(this))
, m_playerId(playerId)
{
setWindowTitle(projectName);
setFocusPolicy(Qt::StrongFocus);
setAcceptDrops(true);
m_controller = new GameController(this);
m_controller->setInputController(&m_inputController);
m_controller->setOverrides(m_config->overrides());
updateTitle();
QGLFormat format(QGLFormat(QGL::Rgba | QGL::DoubleBuffer));
format.setSwapInterval(1);
@ -506,7 +506,7 @@ void Window::gameStarted(GBAThread* context) {
action->setDisabled(false);
}
appendMRU(context->fname);
setWindowTitle(tr("%1 - %2").arg(projectName).arg(title));
updateTitle();
attachWidget(m_display);
#ifndef Q_OS_MAC
@ -523,7 +523,7 @@ void Window::gameStopped() {
foreach (QAction* action, m_gameActions) {
action->setDisabled(true);
}
setWindowTitle(projectName);
updateTitle();
detachWidget(m_display);
m_screenWidget->setLockAspectRatio(m_logo.width(), m_logo.height());
m_screenWidget->setPixmap(m_logo);
@ -568,22 +568,38 @@ void Window::recordFrame() {
}
void Window::showFPS() {
char gameTitle[13] = { '\0' };
GBAGetGameTitle(m_controller->thread()->gba, gameTitle);
QString title(gameTitle);
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
if (multiplayer && multiplayer->attached() > 1) {
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
}
if (m_frameList.isEmpty()) {
setWindowTitle(tr("%1 - %2").arg(projectName).arg(title));
updateTitle();
return;
}
qint64 interval = m_frameList.first().msecsTo(m_frameList.last());
float fps = (m_frameList.count() - 1) * 10000.f / interval;
fps = round(fps) / 10.f;
setWindowTitle(tr("%1 - %2 (%3 fps)").arg(projectName).arg(title).arg(fps));
updateTitle(fps);
}
void Window::updateTitle(float fps) {
QString title;
m_controller->threadInterrupt();
if (m_controller->isLoaded()) {
char gameTitle[13] = { '\0' };
GBAGetGameTitle(m_controller->thread()->gba, gameTitle);
title = (gameTitle);
}
std::shared_ptr<MultiplayerController> multiplayer = m_controller->multiplayerController();
if (multiplayer && multiplayer->attached() > 1) {
title += tr(" - Player %1 of %2").arg(m_playerId + 1).arg(multiplayer->attached());
}
m_controller->threadContinue();
if (title.isNull()) {
setWindowTitle(tr("%1 - %2").arg(projectName).arg(projectVersion));
} else if (isnan(fps)) {
setWindowTitle(tr("%1 - %2 - %3").arg(projectName).arg(title).arg(projectVersion));
} else {
setWindowTitle(tr("%1 - %2 (%3 fps) - %4").arg(projectName).arg(title).arg(fps).arg(projectVersion));
}
}
void Window::openStateWindow(LoadSave ls) {

View File

@ -133,6 +133,8 @@ private:
QAction* addControlledAction(QMenu* menu, QAction* action, const QString& name);
QAction* addHiddenAction(QMenu* menu, QAction* action, const QString& name);
void updateTitle(float fps = NAN);
GameController* m_controller;
Display* m_display;
QList<QAction*> m_gameActions;