From f8362d680b1b684e4ee22986acc8320c65997aa6 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 30 May 2015 17:42:31 -0700 Subject: [PATCH] Qt: Export to ACT --- src/platform/qt/GBAApp.cpp | 30 +++++++++++++++++++++++++++++- src/platform/qt/GBAApp.h | 13 +++++++++++++ src/platform/qt/PaletteView.cpp | 13 ++++++++++--- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/platform/qt/GBAApp.cpp b/src/platform/qt/GBAApp.cpp index c94c32102..182b4f570 100644 --- a/src/platform/qt/GBAApp.cpp +++ b/src/platform/qt/GBAApp.cpp @@ -9,7 +9,6 @@ #include "GameController.h" #include "Window.h" -#include #include #include @@ -129,3 +128,32 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr } 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; +} diff --git a/src/platform/qt/GBAApp.h b/src/platform/qt/GBAApp.h index 157c5fd2f..1cf0d8d30 100644 --- a/src/platform/qt/GBAApp.h +++ b/src/platform/qt/GBAApp.h @@ -7,6 +7,7 @@ #define QGBA_APP_H #include +#include #include "ConfigController.h" #include "MultiplayerController.h" @@ -32,6 +33,9 @@ public: 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; diff --git a/src/platform/qt/PaletteView.cpp b/src/platform/qt/PaletteView.cpp index 29a0d1e36..15f338438 100644 --- a/src/platform/qt/PaletteView.cpp +++ b/src/platform/qt/PaletteView.cpp @@ -8,6 +8,7 @@ #include "GBAApp.h" #include "VFileDevice.h" +#include #include extern "C" { @@ -83,17 +84,23 @@ void PaletteView::exportPalette(int start, int length) { 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(); }