Support FileOpen events on OS X

This commit is contained in:
Jeffrey Pfau 2014-10-18 23:18:08 -07:00
parent 8fc3ef27ad
commit 8aa5880afd
6 changed files with 85 additions and 20 deletions

View File

@ -28,5 +28,18 @@
<true/>
<key>NSHumanReadableCopyright</key>
<string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>gba</string>
</array>
<key>CFBundleTypeName</key>
<string>Game Boy Advance ROM Image</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>

View File

@ -28,6 +28,7 @@ set(SOURCE_FILES
AudioDevice.cpp
AudioProcessor.cpp
Display.cpp
GBAApp.cpp
GameController.cpp
LoadSaveState.cpp
LogView.cpp

View File

@ -0,0 +1,32 @@
#include "GBAApp.h"
#include "GameController.h"
#include <QFileOpenEvent>
using namespace QGBA;
GBAApp::GBAApp(int& argc, char* argv[])
: QApplication(argc, argv)
{
QApplication::setApplicationName(PROJECT_NAME);
QApplication::setApplicationVersion(PROJECT_VERSION);
if (parseCommandArgs(&m_opts, argc, argv, 0)) {
m_window.optionsPassed(&m_opts);
}
m_window.show();
}
GBAApp::~GBAApp() {
freeOptions(&m_opts);
}
bool GBAApp::event(QEvent* event) {
if (event->type() == QEvent::FileOpen) {
m_window.controller()->loadGame(static_cast<QFileOpenEvent*>(event)->file());
return true;
}
return QApplication::event(event);
}

34
src/platform/qt/GBAApp.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef QGBA_APP_H
#define QGBA_APP_H
#include <QApplication>
#include "Window.h"
extern "C" {
#include "platform/commandline.h"
}
namespace QGBA {
class GameController;
class GBAApp : public QApplication {
Q_OBJECT
public:
GBAApp(int& argc, char* argv[]);
virtual ~GBAApp();
protected:
bool event(QEvent*);
private:
Window m_window;
StartupOptions m_opts;
};
}
#endif

View File

@ -26,6 +26,8 @@ public:
Window(QWidget* parent = nullptr);
virtual ~Window();
GameController* controller() { return m_controller; }
static GBAKey mapKey(int qtKey);
void optionsPassed(StartupOptions*);

View File

@ -1,24 +1,7 @@
#include <QApplication>
#include "GBAApp.h"
#include "Window.h"
extern "C" {
#include "platform/commandline.h"
}
int main(int argc, char* argv[]) {
QApplication application(argc, argv);
QApplication::setApplicationName(PROJECT_NAME);
QApplication::setApplicationVersion(PROJECT_VERSION);
QGBA::Window window;
struct StartupOptions opts;
if (parseCommandArgs(&opts, argc, argv, 0)) {
window.optionsPassed(&opts);
}
window.show();
int rcode = application.exec();
freeOptions(&opts);
return rcode;
QGBA::GBAApp application(argc, argv);
return application.exec();
}