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