all repos — mgba @ e0a6af087e83d79b53ad5352511c7e02c557b93f

mGBA Game Boy Advance Emulator

src/platform/qt/GIFView.cpp (view raw)

 1/* Copyright (c) 2013-2014 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "GIFView.h"
 7
 8#ifdef USE_MAGICK
 9
10#include "GBAApp.h"
11
12#include <QMap>
13
14using namespace QGBA;
15
16GIFView::GIFView(QWidget* parent)
17	: QWidget(parent)
18{
19	m_ui.setupUi(this);
20
21	connect(m_ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
22	connect(m_ui.start, SIGNAL(clicked()), this, SLOT(startRecording()));
23	connect(m_ui.stop, SIGNAL(clicked()), this, SLOT(stopRecording()));
24
25	connect(m_ui.selectFile, SIGNAL(clicked()), this, SLOT(selectFile()));
26	connect(m_ui.filename, SIGNAL(textChanged(const QString&)), this, SLOT(setFilename(const QString&)));
27
28	ImageMagickGIFEncoderInit(&m_encoder);
29}
30
31GIFView::~GIFView() {
32	stopRecording();
33}
34
35void GIFView::startRecording() {
36	if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toLocal8Bit().constData())) {
37		return;
38	}
39	m_ui.start->setEnabled(false);
40	m_ui.stop->setEnabled(true);
41	emit recordingStarted(&m_encoder.d);
42}
43
44void GIFView::stopRecording() {
45	emit recordingStopped();
46	ImageMagickGIFEncoderClose(&m_encoder);
47	m_ui.stop->setEnabled(false);
48	m_ui.start->setEnabled(true);
49}
50
51void GIFView::selectFile() {
52	QString filename = GBAApp::app()->getSaveFileName(this, tr("Select output file"), tr("Graphics Interchange Format (*.gif)"));
53	if (!filename.isEmpty()) {
54		m_ui.filename->setText(filename);
55		if (!ImageMagickGIFEncoderIsOpen(&m_encoder)) {
56			m_ui.start->setEnabled(true);
57		}
58	}
59}
60
61void GIFView::setFilename(const QString& fname) {
62	m_filename = fname;
63}
64
65#endif