Commit 7790b1da authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Implement configuration dialog for video plugin

parent 15a5d687
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* 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.
*/
#ifndef __KIS_CURSOR_OVERRIDE_HIJACKER_H
#define __KIS_CURSOR_OVERRIDE_HIJACKER_H
#include <QCursor>
#include <QStack>
#include <QApplication>
class KisCursorOverrideHijacker
{
public:
KisCursorOverrideHijacker() {
while (qApp->overrideCursor()) {
m_cursorStack.push(*qApp->overrideCursor());
qApp->restoreOverrideCursor();
}
}
~KisCursorOverrideHijacker() {
while (!m_cursorStack.isEmpty()) {
qApp->setOverrideCursor(m_cursorStack.pop());
}
}
private:
QStack<QCursor> m_cursorStack;
};
#endif /* __KIS_CURSOR_OVERRIDE_HIJACKER_H */
......@@ -31,7 +31,10 @@ include_directories(SYSTEM
set(kritavideoexport_SOURCES
kis_video_export.cpp
video_saver.cpp
)
video_export_options_dialog.cpp
)
ki18n_wrap_ui(kritavideoexport_SOURCES video_export_options_dialog.ui )
add_library(kritavideoexport MODULE ${kritavideoexport_SOURCES})
generate_export_header(kritavideoexport BASE_NAME kritavideoexport)
......
/*
* Copyright (c) 2016 Laszlo Fazekas <mneko@freemail.hu>
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* 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
......@@ -38,6 +38,10 @@
#include <kis_paint_device.h>
#include "video_saver.h"
#include "video_export_options_dialog.h"
#include "kis_cursor_override_hijacker.h"
K_PLUGIN_FACTORY_WITH_JSON(KisVideoExportFactory, "krita_video_export.json", registerPlugin<KisVideoExport>();)
......@@ -64,8 +68,43 @@ KisImportExportFilter::ConversionStatus KisVideoExport::convert(const QByteArray
if (filename.isEmpty()) return KisImportExportFilter::FileNotFound;
bool askForOptions = false;
const QFileInfo fileInfo(filename);
const QString suffix = fileInfo.suffix().toLower();
VideoExportOptionsDialog::CodecIndex codecIndex =
VideoExportOptionsDialog::CODEC_H264;
if (suffix == "mkv" || suffix == "mp4") {
codecIndex = VideoExportOptionsDialog::CODEC_H264;
askForOptions = true;
} else if (suffix == "ogv") {
codecIndex = VideoExportOptionsDialog::CODEC_THEORA;
askForOptions = true;
}
VideoSaver::AdditionalOptions additionalOptions;
askForOptions &=
!qApp->applicationName().toLower().contains("test") &
!getBatchMode();
if (askForOptions) {
KisCursorOverrideHijacker badGuy;
VideoExportOptionsDialog dlg;
dlg.setCodec(codecIndex);
if (dlg.exec() == QDialog::Accepted) {
additionalOptions = dlg.getOptions();
} else {
return KisImportExportFilter::UserCancelled;
}
}
VideoSaver kpc(input, getBatchMode());
KisImageBuilder_Result res = kpc.encode(filename);
KisImageBuilder_Result res = kpc.encode(filename, additionalOptions);
if (res == KisImageBuilder_RESULT_OK) {
return KisImportExportFilter::OK;
......
/*
* Copyright (c) 2016 Laszlo Fazekas <mneko@freemail.hu>
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* 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
......
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* 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 "video_export_options_dialog.h"
#include "ui_video_export_options_dialog.h"
#include <KoID.h>
struct VideoExportOptionsDialog::Private
{
Private() {
presets << KoID("ultrafast", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "ultrafast"));
presets << KoID("superfast", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "superfast"));
presets << KoID("veryfast", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "veryfast"));
presets << KoID("faster", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "faster"));
presets << KoID("fast", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "fast"));
presets << KoID("medium", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "medium"));
presets << KoID("slow", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "slow"));
presets << KoID("slower", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "slower"));
presets << KoID("veryslow", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "veryslow"));
presets << KoID("placebo", i18nc("h264 profile name, check simplescreenrecorder for standard translations", "placebo"));
defaultPreset = 5;
defaultBitrate = 5000;
defaultConstantRateFactor = 23;
}
QVector<KoID> presets;
int defaultPreset;
int defaultBitrate;
int defaultConstantRateFactor;
};
VideoExportOptionsDialog::VideoExportOptionsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::VideoExportOptionsDialog),
m_d(new Private)
{
ui->setupUi(this);
ui->intConstantRateFactor->setRange(0, 51);
ui->intConstantRateFactor->setValue(m_d->defaultConstantRateFactor);
Q_FOREACH (const KoID &preset, m_d->presets) {
ui->cmbPreset->insertItem(ui->cmbPreset->count(), preset.name());
}
ui->cmbPreset->setCurrentIndex(m_d->defaultPreset);
ui->intBitrate->setRange(10, 50000);
ui->intBitrate->setValue(5000);
ui->intBitrate->setSuffix(i18nc("kilo-bits-per-second, video bitrate suffix", "kbps"));
connect(ui->cmbCodec, SIGNAL(currentIndexChanged(int)),
ui->stackedWidget, SLOT(setCurrentIndex(int)));
ui->cmbCodec->setCurrentIndex(0);
ui->cmbCodec->setEnabled(false);
setModal(true);
}
VideoExportOptionsDialog::~VideoExportOptionsDialog()
{
delete ui;
}
void VideoExportOptionsDialog::setCodec(CodecIndex index)
{
ui->cmbCodec->setCurrentIndex(int(index));
}
VideoSaver::AdditionalOptions VideoExportOptionsDialog::getOptions() const
{
VideoSaver::AdditionalOptions options;
if (ui->cmbCodec->currentIndex() == int(CODEC_H264)) {
options["crf"] = QString::number(ui->intConstantRateFactor->value());
const int presetIndex = ui->cmbPreset->currentIndex();
options["preset"] = m_d->presets[presetIndex].id();
} else if (ui->cmbCodec->currentIndex() == int(CODEC_THEORA)) {
const qint64 bitRate = ui->intBitrate->value() * 1024;
options["bit_rate"] = bitRate;
}
return options;
}
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* 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.
*/
#ifndef VIDEO_EXPORT_OPTIONS_DIALOG_H
#define VIDEO_EXPORT_OPTIONS_DIALOG_H
#include <QDialog>
#include "video_saver.h"
#include <QScopedPointer>
namespace Ui {
class VideoExportOptionsDialog;
}
class VideoExportOptionsDialog : public QDialog
{
Q_OBJECT
public:
enum CodecIndex {
CODEC_H264 = 0,
CODEC_THEORA
};
public:
explicit VideoExportOptionsDialog(QWidget *parent = 0);
~VideoExportOptionsDialog();
void setCodec(CodecIndex index);
VideoSaver::AdditionalOptions getOptions() const;
private:
Ui::VideoExportOptionsDialog *ui;
private:
struct Private;
const QScopedPointer<Private> m_d;
};
#endif // VIDEO_EXPORT_OPTIONS_DIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>VideoExportOptionsDialog</class>
<widget class="QDialog" name="VideoExportOptionsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>205</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="cmbCodec">
<item>
<property name="text">
<string>H.264, MPEG-4 Part 10</string>
</property>
</item>
<item>
<property name="text">
<string>Theora</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Constant Rate Factor:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KisSliderSpinBox" name="intConstantRateFactor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Preset:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="cmbPreset"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Bitrate:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KisSliderSpinBox" name="intBitrate" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>44</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>VideoExportOptionsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>VideoExportOptionsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -20,17 +20,9 @@
#include "video_saver.h"
#include <QDebug>
// #include <QApplication>
#include <QFileInfo>
// #include <QFile>
// #include <QDir>
// #include <QVector>
// #include <QIODevice>
// #include <QRect>
// #include <KisMimeDatabase.h>
// #include <KisPart.h>
#include <KisDocument.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment