DlgAnimationRenderer.cpp 4.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 *  Copyright (c) 2016 Boudewijn Rempt <boud@valdyas.org>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include "DlgAnimationRenderer.h"

#include <QPluginLoader>
#include <QJsonObject>

#include <klocalizedstring.h>
#include <kpluginfactory.h>

#include <kis_properties_configuration.h>
#include <kis_debug.h>
#include <KisMimeDatabase.h>
#include <KoJsonTrader.h>
#include <KisImportExportFilter.h>

DlgAnimaterionRenderer::DlgAnimaterionRenderer(QWidget *parent)
34
    : KoDialog(parent)
35 36 37 38 39 40 41
{
    setCaption(i18n("Render Animation"));
    setButtons(Ok | Cancel);
    setDefaultButton(Ok);

    m_page = new WdgAnimaterionRenderer(this);
    m_page->layout()->setMargin(0);
42
    m_page->dirRequester->setMode(KoFileDialog::OpenDirectory);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    setMainWidget(m_page);
    resize(m_page->sizeHint());

    KoJsonTrader trader;
    QList<QPluginLoader *>list = trader.query("Krita/AnimationExporter", "");
    Q_FOREACH(QPluginLoader *loader, list) {
        QJsonObject json = loader->metaData().value("MetaData").toObject();
        Q_FOREACH(const QString &mimetype, json.value("X-KDE-Export").toString().split(",")) {

            KLibFactory *factory = qobject_cast<KLibFactory *>(loader->instance());

            if (!factory) {
                warnUI << loader->errorString();
                continue;
            }

            QObject* obj = factory->create<KisImportExportFilter>(parent);
            if (!obj || !obj->inherits("KisImportExportFilter")) {
                delete obj;
                continue;
            }

            QSharedPointer<KisImportExportFilter> filter(static_cast<KisImportExportFilter*>(obj));
            if (!filter) {
                delete obj;
                continue;
            }

            m_filters.append(filter);
72 73
            //            m_configWidgets.append(filter->createConfigurationWidget(m_page->grpRenderOptions));
            //            m_configWidgets.last()->setVisible(false);
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119

            m_page->cmbRenderType->addItem(KisMimeDatabase::descriptionForMimeType(mimetype));
        }
    }

    connect(m_page->cmbRenderType, SIGNAL(activated(int)), this, SLOT(selectRenderType(int)));
}

DlgAnimaterionRenderer::~DlgAnimaterionRenderer()
{
    delete m_page;
}

KisPropertiesConfigurationSP DlgAnimaterionRenderer::getSequenceConfiguration() const
{
    KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
    cfg->setProperty("basename", m_page->txtBasename->text());
    cfg->setProperty("directory", m_page->dirRequester->fileName());
    cfg->setProperty("first_frame", m_page->intStart->value());
    cfg->setProperty("last_frame", m_page->intEnd->value());
    cfg->setProperty("sequence_start", m_page->sequenceStart->value());
    return cfg;
}

KisPropertiesConfigurationSP DlgAnimaterionRenderer::getVideoConfiguration() const
{
    if (!m_page->grpRenderOptions->isChecked()) {
        return 0;
    }
    KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
    cfg->setProperty("filename", m_page->videoFilename->fileName());
    cfg->setProperty("delete_sequence", m_page->chkDeleteSequence->isChecked());
    return cfg;
}

KisPropertiesConfigurationSP DlgAnimaterionRenderer::getencoderConfiguration() const
{
    if (!m_page->grpRenderOptions->isChecked()) {
        return 0;
    }
    KisPropertiesConfigurationSP cfg = new KisPropertiesConfiguration();
    return cfg;
}

void DlgAnimaterionRenderer::selectRenderType(int renderType)
{
120 121 122 123 124 125 126 127 128 129
    //    if (renderType >= m_configWidgets->size) return;

    //    Q_FOREACH(QWidget *w, m_configWidgets) {
    //        if (w) {
    //            w->setVisible(false);
    //        }
    //    }
    //    if (m_configWidgets[renterType]) {
    //        m_configWidgets[renderType]->setVisible(true);
    //    }
130
}