Commit dbf84922 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Text based edit: save button now adds the edited clip to bin playlist,...

Text based edit: save button now adds the edited clip to bin playlist, subsequent changes automatically update the playlist
parent 94e5e4c5
......@@ -936,7 +936,7 @@ Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent)
connect(m_itemModel.get(), static_cast<void (ProjectItemModel::*)(const QStringList &, const QModelIndex &)>(&ProjectItemModel::itemDropped), this,
static_cast<void (Bin::*)(const QStringList &, const QModelIndex &)>(&Bin::slotItemDropped));
connect(m_itemModel.get(), static_cast<void (ProjectItemModel::*)(const QList<QUrl> &, const QModelIndex &)>(&ProjectItemModel::itemDropped), this,
static_cast<void (Bin::*)(const QList<QUrl> &, const QModelIndex &)>(&Bin::slotItemDropped));
static_cast<const QString (Bin::*)(const QList<QUrl> &, const QModelIndex &)>(&Bin::slotItemDropped));
connect(m_itemModel.get(), &ProjectItemModel::effectDropped, this, &Bin::slotEffectDropped);
connect(m_itemModel.get(), &ProjectItemModel::addTag, this, &Bin::slotTagDropped);
connect(m_itemModel.get(), &QAbstractItemModel::dataChanged, this, &Bin::slotItemEdited);
......@@ -3306,15 +3306,15 @@ void Bin::droppedUrls(const QList<QUrl> &urls, const QString &folderInfo)
slotItemDropped(urls, current);
}
void Bin::slotAddClipToProject(const QUrl &url)
const QString Bin::slotAddClipToProject(const QUrl &url)
{
QList<QUrl> urls;
urls << url;
QModelIndex current = m_proxyModel->mapToSource(m_proxyModel->selectionModel()->currentIndex());
slotItemDropped(urls, current);
return slotItemDropped(urls, current);
}
void Bin::slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent)
const QString Bin::slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent)
{
QString parentFolder = m_itemModel->getRootFolder()->clipId();
if (parent.isValid()) {
......@@ -3333,6 +3333,7 @@ void Bin::slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent)
m_itemView->scrollTo(m_proxyModel->mapFromSource(ix), QAbstractItemView::EnsureVisible);
}
}
return id;
}
void Bin::slotExpandUrl(const ItemInfo &info, const QString &url, QUndoCommand *command)
......@@ -4426,7 +4427,7 @@ void Bin::dockWidgetInit(QDockWidget* m_DockClipWidget){
m_clipWidget->init(m_DockClipWidget);
}
void Bin::savePlaylist(const QString &binId, QString savePath, QVector<QPoint> zones, QMap<QString, QString> properties)
void Bin::savePlaylist(const QString &binId, QString savePath, QVector<QPoint> zones, QMap<QString, QString> properties, bool createNew)
{
std::shared_ptr<ProjectClip> clip = m_itemModel->getClipByBinID(binId);
if (!clip) {
......@@ -4450,4 +4451,8 @@ void Bin::savePlaylist(const QString &binId, QString savePath, QVector<QPoint> z
cons.set("store", "kdenlive");
cons.connect(t);
cons.run();
if (createNew) {
const QString id = slotAddClipToProject(QUrl::fromLocalFile(savePath));
selectClipById(id);
}
}
......@@ -322,8 +322,13 @@ public:
// TODO refac: remove this and call directly the function in ProjectItemModel
void cleanupUnused();
void selectAll();
/** @brief Save an mlt playlist from a bin id and a list of cuts */
void savePlaylist(const QString &binId, QString savePath, QVector<QPoint> zones, QMap<QString, QString> properties);
/** @brief Save an mlt playlist from a bin id and a list of cuts
* @param binId the id of the source clip for zones
* @param savePath the path for the resulting playlist
* @param zones the source cli pzones that will be put in the result playlist
* @param properties some extra properties that will be set on the producer
* @param createNew if true, the playlist will be added as a new clip in project binId */
void savePlaylist(const QString &binId, QString savePath, QVector<QPoint> zones, QMap<QString, QString> properties, bool createNew);
private slots:
void slotAddClip();
......@@ -350,7 +355,7 @@ private slots:
void selectProxyModel(const QModelIndex &id);
void slotSaveHeaders();
void slotItemDropped(const QStringList &ids, const QModelIndex &parent);
void slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent);
const QString slotItemDropped(const QList<QUrl> &urls, const QModelIndex &parent);
void slotEffectDropped(const QStringList &effectData, const QModelIndex &parent);
void slotTagDropped(const QString &tag, const QModelIndex &parent);
void slotItemEdited(const QModelIndex &, const QModelIndex &, const QVector<int> &);
......@@ -422,7 +427,7 @@ public slots:
void resetUsageCount();
/** @brief Select a clip in the Bin from its id. */
void selectClipById(const QString &id, int frame = -1, const QPoint &zone = QPoint());
void slotAddClipToProject(const QUrl &url);
const QString slotAddClipToProject(const QUrl &url);
void droppedUrls(const QList<QUrl> &urls, const QString &folderInfo = QString());
/** @brief Returns the effectstack of a given clip. */
std::shared_ptr<EffectStackModel> getClipEffectStack(int itemId);
......
......@@ -39,6 +39,7 @@
#include <QKeyEvent>
#include <QToolButton>
#include <KMessageBox>
#include <KUrlRequesterDialog>
VideoTextEdit::VideoTextEdit(QWidget *parent)
: QTextEdit(parent)
......@@ -543,8 +544,6 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
connect(vosk_config, &QToolButton::clicked, [this]() {
pCore->window()->slotPreferences(8);
});
m_playlist.setFileTemplate(QDir::temp().absoluteFilePath(QStringLiteral("kdenlive-speech-XXXXXX.mlt")));
qDebug()<<"======= EDITOR TXT COLOR: "<<palette().text().color().name()<<"\n==========";
// Visual text editor
QVBoxLayout *l = new QVBoxLayout;
......@@ -611,10 +610,12 @@ TextBasedEdit::TextBasedEdit(QWidget *parent)
button_delete->setEnabled(false);
connect(button_delete, &QToolButton::clicked, this, &TextBasedEdit::deleteItem);
button_add->setIcon(QIcon::fromTheme(QStringLiteral("media-playback-start")));
button_add->setToolTip(i18n("Play edited text"));
button_add->setIcon(QIcon::fromTheme(QStringLiteral("document-save-as")));
button_add->setToolTip(i18n("Save edited text in a new playlist"));
button_add->setEnabled(false);
connect(button_add, &QToolButton::clicked, this, &TextBasedEdit::previewPlaylist);
connect(button_add, &QToolButton::clicked, [this]() {
previewPlaylist();
});
button_insert->setIcon(QIcon::fromTheme(QStringLiteral("timeline-insert")));
button_insert->setToolTip(i18n("Insert selected blocks in timeline"));
......@@ -715,7 +716,6 @@ bool TextBasedEdit::eventFilter(QObject *obj, QEvent *event)
void TextBasedEdit::startRecognition()
{
button_add->setEnabled(true);
if (m_speechJob && m_speechJob->state() != QProcess::NotRunning) {
if (KMessageBox::questionYesNo(this, i18n("Another recognition job is running. Abort it ?")) != KMessageBox::Yes) {
return;
......@@ -805,6 +805,7 @@ void TextBasedEdit::startRecognition()
connect(m_speechJob.get(), &QProcess::readyReadStandardOutput, this, &TextBasedEdit::slotProcessSpeech);
connect(m_speechJob.get(), static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished), this, &TextBasedEdit::slotProcessSpeechStatus);
qDebug()<<"=== STARTING RECO: "<<speechScript<<" / "<<modelDirectory<<" / "<<language<<" / "<<m_sourceUrl<<", START: "<<m_visualEditor->clipOffset<<", DUR: "<<endPos;
button_add->setEnabled(false);
m_speechJob->start(pyExec, {speechScript, modelDirectory, language, m_sourceUrl, QString::number(m_visualEditor->clipOffset), QString::number(endPos)});
speech_progress->setValue(0);
frame_progress->setVisible(true);
......@@ -1000,6 +1001,7 @@ void TextBasedEdit::deleteItem()
}
// Reset selection and rebuild line numbers
m_visualEditor->rebuildZones();
previewPlaylist(false);
}
void TextBasedEdit::insertToTimeline()
......@@ -1013,15 +1015,10 @@ void TextBasedEdit::insertToTimeline()
}
}
void TextBasedEdit::previewPlaylist()
void TextBasedEdit::previewPlaylist(bool createNew)
{
qDebug()<<"???????\ncreating playlist: "<<createNew<<"\n?????";
QVector<QPoint> zones = m_visualEditor->getInsertZones();
if (!m_playlist.open()) {
// Something went wrong
showMessage(i18n("Cannot open temporary playlist"), KMessageWidget::Information);
return;
}
m_playlist.close();
if (zones.isEmpty()) {
showMessage(i18n("No text to export"), KMessageWidget::Information);
return;
......@@ -1030,16 +1027,23 @@ void TextBasedEdit::previewPlaylist()
properties.insert("kdenlive:speech", m_visualEditor->toHtml());
std::shared_ptr<AbstractProjectItem> clip = pCore->projectItemModel()->getItemByBinId(m_binId);
std::shared_ptr<ProjectClip> clipItem = std::static_pointer_cast<ProjectClip>(clip);
/*QString sourcePath = clipItem->url();
QString sourcePath = clipItem->url();
int ix = 1;
QString playlistPath = QString("%1-cut%2.mlt").arg(sourcePath).arg(ix);
while (QFile::exists(playlistPath)) {
ix++;
playlistPath = QString("%1-cut%2.mlt").arg(sourcePath).arg(ix);
}*/
pCore->bin()->savePlaylist(m_binId, m_playlist.fileName(), zones, properties);
emit previewClip(m_playlist.fileName(), i18n("Speech cut"));
//slotItemDropped({QUrl::fromLocalFile(playlistPath)}, m_proxyModel->mapToSource(m_proxyModel->selectionModel()->currentIndex()));
if (createNew) {
m_playlist = QString("%1-cut%2.mlt").arg(sourcePath).arg(ix);
while (QFile::exists(m_playlist)) {
ix++;
m_playlist = QString("%1-cut%2.mlt").arg(sourcePath).arg(ix);
}
QUrl url = KUrlRequesterDialog::getUrl(QUrl::fromLocalFile(m_playlist), this, i18n("Enter new playlist path"));
if (url.isEmpty()) {
return;
}
m_playlist = url.toLocalFile();
}
if (!m_playlist.isEmpty()) {
pCore->bin()->savePlaylist(m_binId, m_playlist, zones, properties, createNew);
}
}
void TextBasedEdit::showMessage(const QString &text, KMessageWidget::MessageType type)
......
......@@ -29,7 +29,6 @@
#include <QAction>
#include <QTextEdit>
#include <QMouseEvent>
#include <QTemporaryFile>
#include <QTimer>
/**
......@@ -150,7 +149,7 @@ private slots:
/** @brief insert currently selected zones to timeline */
void insertToTimeline();
/** @brief Preview current edited text in the clip monitor */
void previewPlaylist();
void previewPlaylist(bool createNew = true);
/** @brief Display info message */
void showMessage(const QString &text, KMessageWidget::MessageType type);
......@@ -167,11 +166,8 @@ private:
QAction *m_logAction;
VideoTextEdit *m_visualEditor;
QTextDocument m_document;
QTemporaryFile m_playlist;
QString m_playlist;
QTimer m_hideTimer;
signals:
void previewClip(const QString &path, const QString &title);
};
#endif
......@@ -358,12 +358,6 @@ void MainWindow::init()
m_clipMonitorDock->raise();
});
connect(pCore->textEditWidget(), &TextBasedEdit::previewClip, [&](const QString &path, const QString title) {
m_clipMonitor->slotPreviewResource(path, title);
m_clipMonitorDock->show();
m_clipMonitorDock->raise();
});
connect(onlineResources, &ResourceWidget::addClip, this, &MainWindow::slotAddProjectClip);
connect(onlineResources, &ResourceWidget::addLicenseInfo, this, &MainWindow::slotAddTextNote);
......
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