Qt: Export to ACT

This commit is contained in:
Jeffrey Pfau 2015-05-30 17:42:31 -07:00
parent 632316eef0
commit f8362d680b
3 changed files with 52 additions and 4 deletions

View File

@ -9,7 +9,6 @@
#include "GameController.h" #include "GameController.h"
#include "Window.h" #include "Window.h"
#include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QFileOpenEvent> #include <QFileOpenEvent>
@ -129,3 +128,32 @@ QString GBAApp::getSaveFileName(QWidget* owner, const QString& title, const QStr
} }
return filename; 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;
}

View File

@ -7,6 +7,7 @@
#define QGBA_APP_H #define QGBA_APP_H
#include <QApplication> #include <QApplication>
#include <QFileDialog>
#include "ConfigController.h" #include "ConfigController.h"
#include "MultiplayerController.h" #include "MultiplayerController.h"
@ -32,6 +33,9 @@ public:
QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString()); QString getOpenFileName(QWidget* owner, const QString& title, const QString& filter = QString());
QString getSaveFileName(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: public slots:
void interruptAll(); void interruptAll();
void continueAll(); void continueAll();
@ -40,6 +44,15 @@ protected:
bool event(QEvent*); bool event(QEvent*);
private: 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(); Window* newWindowInternal();
ConfigController m_configController; ConfigController m_configController;

View File

@ -8,6 +8,7 @@
#include "GBAApp.h" #include "GBAApp.h"
#include "VFileDevice.h" #include "VFileDevice.h"
#include <QFileDialog>
#include <QFontDatabase> #include <QFontDatabase>
extern "C" { extern "C" {
@ -83,17 +84,23 @@ void PaletteView::exportPalette(int start, int length) {
length = 512 - start; length = 512 - start;
} }
m_controller->threadInterrupt(); m_controller->threadInterrupt();
QString filename = GBAApp::app()->getSaveFileName(this, tr("Export palette"), tr("Windows PAL (*.pal)")); QFileDialog* dialog = GBAApp::app()->getSaveFileDialog(this, tr("Export palette"), tr("Windows PAL (*.pal);;Adobe Color Table (*.act)"));
if (filename.isNull()) { if (!dialog->exec()) {
m_controller->threadContinue(); m_controller->threadContinue();
return; return;
} }
QString filename = dialog->selectedFiles()[0];
VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC); VFile* vf = VFileDevice::open(filename, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
m_controller->threadContinue(); m_controller->threadContinue();
return; 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); vf->close(vf);
m_controller->threadContinue(); m_controller->threadContinue();
} }