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#include "LogController.h"
12
13#include <QMap>
14
15using namespace QGBA;
16
17GIFView::GIFView(QWidget* parent)
18 : QWidget(parent)
19{
20 m_ui.setupUi(this);
21
22 connect(m_ui.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
23 connect(m_ui.start, SIGNAL(clicked()), this, SLOT(startRecording()));
24 connect(m_ui.stop, SIGNAL(clicked()), this, SLOT(stopRecording()));
25
26 connect(m_ui.selectFile, SIGNAL(clicked()), this, SLOT(selectFile()));
27 connect(m_ui.filename, SIGNAL(textChanged(const QString&)), this, SLOT(setFilename(const QString&)));
28
29 ImageMagickGIFEncoderInit(&m_encoder);
30}
31
32GIFView::~GIFView() {
33 stopRecording();
34}
35
36void GIFView::startRecording() {
37 if (!ImageMagickGIFEncoderOpen(&m_encoder, m_filename.toUtf8().constData())) {
38 LOG(ERROR) << tr("Failed to open output GIF file: %1").arg(m_filename);
39 return;
40 }
41 m_ui.start->setEnabled(false);
42 m_ui.stop->setEnabled(true);
43 emit recordingStarted(&m_encoder.d);
44}
45
46void GIFView::stopRecording() {
47 emit recordingStopped();
48 ImageMagickGIFEncoderClose(&m_encoder);
49 m_ui.stop->setEnabled(false);
50 m_ui.start->setEnabled(true);
51}
52
53void GIFView::selectFile() {
54 QString filename = GBAApp::app()->getSaveFileName(this, tr("Select output file"), tr("Graphics Interchange Format (*.gif)"));
55 if (!filename.isEmpty()) {
56 m_ui.filename->setText(filename);
57 if (!ImageMagickGIFEncoderIsOpen(&m_encoder)) {
58 m_ui.start->setEnabled(true);
59 }
60 }
61}
62
63void GIFView::setFilename(const QString& fname) {
64 m_filename = fname;
65}
66
67#endif