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