Skip to content

Commit

Permalink
Refactor|Client|UI: Switching to/from native UI mode
Browse files Browse the repository at this point in the history
The "native UI" mode puts the game to windowed mode and restores
desktop display mode so that native UI widgets can be used normally.
Moved the code for doing this from CVarNativePathWidget to the
ClientApp.
  • Loading branch information
skyjake committed Feb 12, 2015
1 parent be310c4 commit 3efff8f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 2 additions & 0 deletions doomsday/client/include/clientapp.h
Expand Up @@ -81,6 +81,8 @@ class ClientApp : public de::BaseGuiApp
public slots:
void openHomepageInBrowser();
void openInBrowser(QUrl url);
void beginNativeUIMode();
void endNativeUIMode();

private:
DENG2_PRIVATE(d)
Expand Down
22 changes: 22 additions & 0 deletions doomsday/client/src/clientapp.cpp
Expand Up @@ -558,3 +558,25 @@ void ClientApp::openInBrowser(QUrl url)

QDesktopServices::openUrl(url);
}

void ClientApp::beginNativeUIMode()
{
// Switch temporarily to windowed mode. Not needed on OS X because the display mode
// is never changed on that platform.
#ifndef MACOSX
auto &win = ClientWindow::main();
win.saveState();
int windowedMode[] = {
ClientWindow::Fullscreen, false,
ClientWindow::End
};
win.changeAttributes(windowedMode);
#endif
}

void ClientApp::endNativeUIMode()
{
#ifndef MACOSX
win.restoreState();
#endif
}
20 changes: 4 additions & 16 deletions doomsday/client/src/ui/widgets/cvarnativepathwidget.cpp
Expand Up @@ -18,6 +18,7 @@

#include "ui/widgets/cvarnativepathwidget.h"
#include "ui/clientwindow.h"
#include "clientapp.h"

#include <doomsday/console/var.h>
#include <de/PopupMenuWidget>
Expand Down Expand Up @@ -98,23 +99,12 @@ void CVarNativePathWidget::updateFromCVar()

void CVarNativePathWidget::chooseUsingNativeFileDialog()
{
auto &win = ClientWindow::main();

#ifndef MACOSX
// Switch temporarily to windowed mode. Not needed on OS X because the display mode
// is never changed on that platform.
win.saveState();
int windowedMode[] = {
ClientWindow::Fullscreen, false,
ClientWindow::End
};
win.changeAttributes(windowedMode);
#endif
ClientApp::app().beginNativeUIMode();

// Use a native dialog to pick the path.
QDir dir(d->path);
if(d->path.isEmpty()) dir = QDir::home();
QFileDialog dlg(&win, tr("Select File for \"%1\"").arg(d->cvar), dir.absolutePath());
QFileDialog dlg(&ClientWindow::main(), tr("Select File for \"%1\"").arg(d->cvar), dir.absolutePath());
if(!d->filters.isEmpty())
{
dlg.setNameFilters(d->filters);
Expand All @@ -129,9 +119,7 @@ void CVarNativePathWidget::chooseUsingNativeFileDialog()
setText(d->labelText());
}

#ifndef MACOSX
win.restoreState();
#endif
ClientApp::app().endNativeUIMode();
}

void CVarNativePathWidget::clearPath()
Expand Down

0 comments on commit 3efff8f

Please sign in to comment.