Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Make title clips work again

parent 8a18bf7d
......@@ -2159,7 +2159,7 @@ void Bin::slotCreateProjectClip()
ClipCreationDialog::createSlideshowClip(m_doc, parentFolder, m_itemModel);
break;
case ClipType::Text:
ClipCreationDialog::createTitleClip(m_doc, folderInfo, QString(), this);
ClipCreationDialog::createTitleClip(m_doc, parentFolder, QString(), m_itemModel);
break;
case ClipType::TextTemplate:
ClipCreationDialog::createTitleTemplateClip(m_doc, parentFolder, m_itemModel);
......
......@@ -36,17 +36,13 @@
#include <QWindow>
namespace {
QDomElement createProducer(QDomDocument &xml, ClipType type, const QString &resource, const QString &name, int duration, const QString &service,
const QString &transparency)
QDomElement createProducer(QDomDocument &xml, ClipType type, const QString &resource, const QString &name, int duration, const QString &service)
{
QDomElement prod = xml.createElement(QStringLiteral("producer"));
xml.appendChild(prod);
prod.setAttribute(QStringLiteral("type"), (int)type);
prod.setAttribute(QStringLiteral("in"), QStringLiteral("0"));
prod.setAttribute(QStringLiteral("length"), duration);
if (!transparency.isEmpty()) {
prod.setAttribute(QStringLiteral("transparency"), transparency);
}
std::unordered_map<QString, QString> properties;
properties[QStringLiteral("resource")] = resource;
if (!name.isEmpty()) {
......@@ -61,12 +57,25 @@ QDomElement createProducer(QDomDocument &xml, ClipType type, const QString &reso
} // namespace
QString ClipCreator::createTitleClip(const std::unordered_map<QString, QString> &properties, int duration, const QString &name, const QString &parentFolder,
std::shared_ptr<ProjectItemModel> model)
{
QDomDocument xml;
auto prod = createProducer(xml, ClipType::Text, QString(), name, duration, QStringLiteral("kdenlivetitle"));
Xml::addXmlProperties(prod, properties);
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create title clip"));
return res ? id : QStringLiteral("-1");
}
QString ClipCreator::createColorClip(const QString &color, int duration, const QString &name, const QString &parentFolder,
std::shared_ptr<ProjectItemModel> model)
{
QDomDocument xml;
auto prod = createProducer(xml, ClipType::Color, color, name, duration, QStringLiteral("color"), QString());
auto prod = createProducer(xml, ClipType::Color, color, name, duration, QStringLiteral("color"));
QString id;
bool res = model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create color clip"));
......@@ -84,7 +93,7 @@ QString ClipCreator::createClipFromFile(const QString &path, const QString &pare
QDomElement prod;
if (type.name().startsWith(QLatin1String("image/"))) {
int duration = pCore->currentDoc()->getFramePos(KdenliveSettings::image_duration());
prod = createProducer(xml, ClipType::Image, path, QString(), duration, QString(), QString());
prod = createProducer(xml, ClipType::Image, path, QString(), duration, QString());
} else if (type.inherits(QStringLiteral("application/x-kdenlivetitle"))) {
// opening a title file
QDomDocument txtdoc(QStringLiteral("titledocument"));
......@@ -114,7 +123,7 @@ QString ClipCreator::createClipFromFile(const QString &path, const QString &pare
if (duration <= 0) {
duration = pCore->currentDoc()->getFramePos(KdenliveSettings::title_duration()) - 1;
}
prod = createProducer(xml, ClipType::Text, path, QString(), duration, QString(), QString());
prod = createProducer(xml, ClipType::Text, path, QString(), duration, QString());
txtdoc.documentElement().setAttribute(QStringLiteral("duration"), duration);
QString titleData = txtdoc.toString();
prod.setAttribute(QStringLiteral("xmldata"), titleData);
......@@ -155,7 +164,7 @@ QString ClipCreator::createSlideshowClip(const QString &path, int duration, cons
{
QDomDocument xml;
auto prod = createProducer(xml, ClipType::SlideShow, path, name, duration, QString(), QString());
auto prod = createProducer(xml, ClipType::SlideShow, path, name, duration, QString());
Xml::addXmlProperties(prod, properties);
QString id;
......@@ -186,7 +195,7 @@ QString ClipCreator::createTitleTemplate(const QString &path, const QString &tex
if (duration == 0) {
duration = pCore->currentDoc()->getFramePos(KdenliveSettings::title_duration());
}
auto prod = createProducer(xml, ClipType::TextTemplate, path, name, duration, QString(), QStringLiteral("1"));
auto prod = createProducer(xml, ClipType::TextTemplate, path, name, duration, QString());
if (!text.isEmpty()) {
prod.setAttribute(QStringLiteral("templatetext"), text);
}
......
......@@ -43,6 +43,17 @@ namespace ClipCreator {
*/
QString createColorClip(const QString &color, int duration, const QString &name, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
/* @brief Create a title clip
@param properties : title properties (xmldata, etc)
@param duration : duration of the clip
@param name: name of the clip
@param parentFolder: the binId of the containing folder
@param model: a shared pointer to the bin item model
*/
QString createTitleClip(const std::unordered_map<QString, QString> &properties, int duration, const QString &name, const QString &parentFolder,
std::shared_ptr<ProjectItemModel> model);
/* @brief Create a title template
@param path : path to the template
@param text : text of the template (optional)
......
......@@ -250,39 +250,20 @@ void ClipCreationDialog::createSlideshowClip(KdenliveDoc *doc, const QString &pa
}
}
void ClipCreationDialog::createTitleClip(KdenliveDoc *doc, const QStringList &groupInfo, const QString &templatePath, Bin *bin)
void ClipCreationDialog::createTitleClip(KdenliveDoc *doc, const QString &parentFolder, const QString &templatePath, std::shared_ptr<ProjectItemModel> model)
{
// Make sure the titles folder exists
QDir dir(doc->projectDataFolder() + QStringLiteral("/titles"));
dir.mkpath(QStringLiteral("."));
QPointer<TitleWidget> dia_ui = new TitleWidget(QUrl::fromLocalFile(templatePath), doc->timecode(), dir.absolutePath(), bin->monitor(), bin);
QObject::connect(dia_ui.data(), &TitleWidget::requestBackgroundFrame, bin, &Bin::slotGetCurrentProjectImage);
QPointer<TitleWidget> dia_ui = new TitleWidget(QUrl::fromLocalFile(templatePath), doc->timecode(), dir.absolutePath(), pCore->getMonitor(Kdenlive::ProjectMonitor), pCore->bin());
QObject::connect(dia_ui.data(), &TitleWidget::requestBackgroundFrame, pCore->bin(), &Bin::slotGetCurrentProjectImage);
if (dia_ui->exec() == QDialog::Accepted) {
// Ready, create clip xml
QDomDocument xml;
QDomElement prod = xml.createElement(QStringLiteral("producer"));
xml.appendChild(prod);
// prod.setAttribute("resource", imagePath);
int id = bin->getFreeClipId();
prod.setAttribute(QStringLiteral("id"), QString::number(id));
QMap<QString, QString> properties;
properties.insert(QStringLiteral("xmldata"), dia_ui->xml().toString());
std::unordered_map<QString, QString> properties;
properties[QStringLiteral("xmldata")] = dia_ui->xml().toString();
QString titleSuggestion = dia_ui->titleSuggest();
properties.insert(QStringLiteral("kdenlive:clipname"), titleSuggestion.isEmpty() ? i18n("Title clip") : titleSuggestion);
if (!groupInfo.isEmpty()) {
properties.insert(QStringLiteral("kdenlive:folderid"), groupInfo.at(0));
}
Xml::addXmlProperties(prod, properties);
prod.setAttribute(QStringLiteral("type"), (int)ClipType::Text);
prod.setAttribute(QStringLiteral("transparency"), QStringLiteral("1"));
prod.setAttribute(QStringLiteral("in"), QStringLiteral("0"));
prod.setAttribute(QStringLiteral("out"), dia_ui->duration() - 1);
// TODO refac
/*
AddClipCommand *command = new AddClipCommand(bin, xml.documentElement(), QString::number(id), true);
doc->commandStack()->push(command);
*/
ClipCreator::createTitleClip(properties, dia_ui->duration() - 1, titleSuggestion.isEmpty() ? i18n("Title clip") : titleSuggestion, parentFolder, model);
}
delete dia_ui;
}
......
......@@ -42,7 +42,7 @@ QStringList getExtensions();
void createColorClip(KdenliveDoc *doc, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
void createQTextClip(KdenliveDoc *doc, const QString &parentId, Bin *bin, ProjectClip *clip = nullptr);
void createSlideshowClip(KdenliveDoc *doc, const QString &parentId, std::shared_ptr<ProjectItemModel> model);
void createTitleClip(KdenliveDoc *doc, const QStringList &groupInfo, const QString &templatePath, Bin *bin);
void createTitleClip(KdenliveDoc *doc, const QString &parentFolder, const QString &templatePath, std::shared_ptr<ProjectItemModel> model);
void createTitleTemplateClip(KdenliveDoc *doc, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
void createClipsCommand(KdenliveDoc *doc, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
}
......
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