all repos — mgba @ f8362d680b1b684e4ee22986acc8320c65997aa6

mGBA Game Boy Advance Emulator

Qt: Export to ACT
Jeffrey Pfau jeffrey@endrift.com
Sat, 30 May 2015 17:42:31 -0700
commit

f8362d680b1b684e4ee22986acc8320c65997aa6

parent

632316eef0b5c82598c8f7ad1685720570eebcd6

3 files changed, 52 insertions(+), 4 deletions(-)

jump to
M src/platform/qt/GBAApp.cppsrc/platform/qt/GBAApp.cpp

@@ -9,7 +9,6 @@ #include "AudioProcessor.h"

#include "GameController.h" #include "Window.h" -#include <QFileDialog> #include <QFileInfo> #include <QFileOpenEvent>

@@ -129,3 +128,32 @@ m_configController.setQtOption("lastDirectory", QFileInfo(filename).dir().path());

} return filename; } + +QFileDialog* GBAApp::getOpenFileDialog(QWidget* owner, const QString& title, const QString& filter) { + FileDialog* dialog = new FileDialog(this, owner, title, filter); + dialog->setAcceptMode(QFileDialog::AcceptOpen); + return dialog; +} + +QFileDialog* GBAApp::getSaveFileDialog(QWidget* owner, const QString& title, const QString& filter) { + FileDialog* dialog = new FileDialog(this, owner, title, filter); + dialog->setAcceptMode(QFileDialog::AcceptSave); + return dialog; +} + +GBAApp::FileDialog::FileDialog(GBAApp* app, QWidget* parent, const QString& caption, const QString& filter) + : QFileDialog(parent, caption, app->m_configController.getQtOption("lastDirectory").toString(), filter) + , m_app(app) +{ +} + +int GBAApp::FileDialog::exec() { + m_app->interruptAll(); + bool didAccept = QFileDialog::exec() == QDialog::Accepted; + QStringList filenames = selectedFiles(); + if (!filenames.isEmpty()) { + m_app->m_configController.setQtOption("lastDirectory", QFileInfo(filenames[0]).dir().path()); + } + m_app->continueAll(); + return didAccept; +}
M src/platform/qt/GBAApp.hsrc/platform/qt/GBAApp.h

@@ -7,6 +7,7 @@ #ifndef QGBA_APP_H

#define QGBA_APP_H #include <QApplication> +#include <QFileDialog> #include "ConfigController.h" #include "MultiplayerController.h"

@@ -32,6 +33,9 @@

QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString()); QString getSaveFileName(QWidget* owner, const QString& title, const QString& filter = QString()); + QFileDialog* getOpenFileDialog(QWidget* owner, const QString& title, const QString& filter = QString()); + QFileDialog* getSaveFileDialog(QWidget* owner, const QString& title, const QString& filter = QString()); + public slots: void interruptAll(); void continueAll();

@@ -40,6 +44,15 @@ protected:

bool event(QEvent*); private: + class FileDialog : public QFileDialog { + public: + FileDialog(GBAApp* app, QWidget* parent = nullptr, const QString& caption = QString(), const QString& filter = QString()); + virtual int exec() override; + + private: + GBAApp* m_app; + }; + Window* newWindowInternal(); ConfigController m_configController;
M src/platform/qt/PaletteView.cppsrc/platform/qt/PaletteView.cpp

@@ -8,6 +8,7 @@

#include "GBAApp.h" #include "VFileDevice.h" +#include <QFileDialog> #include <QFontDatabase> extern "C" {

@@ -83,17 +84,23 @@ if (start + length > 512) {

length = 512 - start; } m_controller->threadInterrupt(); - QString filename = GBAApp::app()->getSaveFileName(this, tr("Export palette"), tr("Windows PAL (*.pal)")); - if (filename.isNull()) { + QFileDialog* dialog = GBAApp::app()->getSaveFileDialog(this, tr("Export palette"), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)")); + if (!dialog->exec()) { m_controller->threadContinue(); return; } + QString filename = dialog->selectedFiles()[0]; VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); if (!vf) { m_controller->threadContinue(); return; } - GBAExportPaletteRIFF(vf, length, &m_controller->thread()->gba->video.palette[start]); + QString filter = dialog->selectedNameFilter(); + if (filter.contains("*.pal")) { + GBAExportPaletteRIFF(vf, length, &m_controller->thread()->gba->video.palette[start]); + } else if (filter.contains("*.act")) { + GBAExportPaletteACT(vf, length, &m_controller->thread()->gba->video.palette[start]); + } vf->close(vf); m_controller->threadContinue(); }