mirror of https://github.com/mgba-emu/mgba.git
Qt: Export to ACT
This commit is contained in:
parent
632316eef0
commit
f8362d680b
|
@ -9,7 +9,6 @@
|
|||
#include "GameController.h"
|
||||
#include "Window.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QFileOpenEvent>
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define QGBA_APP_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileDialog>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "GBAApp.h"
|
||||
#include "VFileDevice.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFontDatabase>
|
||||
|
||||
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;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue