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

Library widget: accept drops from Project Bin and Clip monitor

parent dece85bd
......@@ -3554,3 +3554,14 @@ void Bin::showClearButton(bool show)
m_searchLine->setClearButtonEnabled(show);
}
void Bin::saveZone(QStringList info, QDir dir)
{
if (info.size() != 3) {
return;
}
ProjectClip *clip = getBinClip(info.first());
if (clip && clip->controller()) {
QPoint zone(info.at(1).toInt(), info.at(2).toInt());
clip->controller()->saveZone(zone, dir);
}
}
......@@ -531,8 +531,10 @@ public:
void rebuildProxies();
/** @brief Return a list of all clips hashes used in this project */
QStringList getProxyHashList();
/** @brief Get info (id, name) of a folder (or the currently selected one) */
/** @brief Get info (id, name) of a folder (or the currently selected one) */
const QStringList getFolderInfo(QModelIndex selectedIx = QModelIndex());
/** @brief Save a clip zone as MLT playlist */
void saveZone(QStringList info, QDir dir);
private slots:
void slotAddClip();
......
......@@ -74,7 +74,7 @@ QMimeData * LibraryTree::mimeData(const QList<QTreeWidgetItem *> list) const
QStringList LibraryTree::mimeTypes() const
{
return QStringList() << QString("text/uri-list");;
return QStringList() << QStringLiteral("text/uri-list") << QStringLiteral("kdenlive/clip") << QStringLiteral("kdenlive/producerslist");
}
void LibraryTree::slotUpdateThumb(const QString &path, const QString &iconPath)
......@@ -130,10 +130,8 @@ void LibraryTree::mousePressEvent(QMouseEvent * event)
void LibraryTree::dropEvent(QDropEvent *event)
{
const QMimeData* qMimeData = event->mimeData();
if (!qMimeData->hasUrls()) return;
//QTreeWidget::dropEvent(event);
QList <QUrl> urls = qMimeData->urls();
const QMimeData* qMimeData = event->mimeData();
QTreeWidgetItem *dropped = this->itemAt(event->pos());
QString dest;
if (dropped) {
......@@ -142,8 +140,28 @@ void LibraryTree::dropEvent(QDropEvent *event)
dest = QUrl::fromLocalFile(dest).adjusted(QUrl::RemoveFilename).path();
}
}
if (qMimeData->hasUrls()) {
QList <QUrl> urls = qMimeData->urls();
emit moveData(urls, dest);
} else if (qMimeData->hasFormat(QStringLiteral("kdenlive/clip"))) {
emit importSequence(QString(qMimeData->data(QStringLiteral("kdenlive/clip"))).split(';'), dest);
} else if (qMimeData->hasFormat(QStringLiteral("kdenlive/producerslist"))) {
QStringList list = QString(qMimeData->data(QStringLiteral("kdenlive/producerslist"))).split(';');
foreach(QString data, list) {
if (data.startsWith(QLatin1Char('#'))) {
// Bin folder, not supported yet
continue;
}
if (data.contains(QLatin1Char('/'))) {
// Clip zone
emit importSequence(data.split(QLatin1Char('/')), dest);
} else {
// Full clip
emit importSequence(QStringList() << data << QStringLiteral("-1") << QStringLiteral("-1"), dest);
}
}
}
event->accept();
emit moveData(urls, dest);
}
......@@ -198,6 +216,7 @@ LibraryWidget::LibraryWidget(ProjectManager *manager, QWidget *parent) : QWidget
m_timer.setInterval(4000);
connect(&m_timer, &QTimer::timeout, m_infoWidget, &KMessageWidget::animatedHide);
connect(m_libraryTree, &LibraryTree::moveData, this, &LibraryWidget::slotMoveData);
connect(m_libraryTree, &LibraryTree::importSequence, this, &LibraryWidget::slotSaveSequence);
m_coreLister = new KCoreDirLister(this);
m_coreLister->setDelayedMimeTypes(false);
......@@ -398,6 +417,18 @@ void LibraryWidget::slotMoveData(QList <QUrl> urls, QString dest)
}
}
void LibraryWidget::slotSaveSequence(QStringList info, QString dest)
{
if (info.isEmpty()) return;
if (dest .isEmpty()) {
// moving to library's root
dest = m_directory.absolutePath();
}
QDir dir(dest);
if (!dir.exists()) return;
m_manager->saveZone(info, dir);
}
void LibraryWidget::slotItemEdited(QTreeWidgetItem *item, int column)
{
if (!item || column != 0) return;
......
......@@ -155,6 +155,7 @@ public slots:
signals:
void moveData(QList <QUrl>, QString);
void importSequence(QStringList, QString);
};
......@@ -177,6 +178,7 @@ private slots:
void slotAddFolder();
void slotRenameItem();
void slotMoveData(QList <QUrl>, QString);
void slotSaveSequence(QStringList info, QString dest);
void slotItemEdited(QTreeWidgetItem *item, int column);
void slotDownloadFinished(KJob *);
void slotDownloadProgress(KJob *, unsigned long);
......
......@@ -819,3 +819,20 @@ void ClipController::disableEffects(bool disable)
if (changed) m_binController->updateTrackProducer(clipId());
}
void ClipController::saveZone(QPoint zone, QDir dir)
{
QString path = QString(clipName() + "_" + QString::number(zone.x()) + ".mlt");
if (dir.exists(path)) {
//TODO ask for overwrite
}
Mlt::Consumer xmlConsumer(*profile(), ("xml:" + dir.absoluteFilePath(path)).toUtf8().constData());
xmlConsumer.set("terminate_on_pause", 1);
Mlt::Producer prod(m_masterProducer->get_producer());
Mlt::Producer *prod2 = prod.cut(zone.x(), zone.y());
Mlt::Playlist list(*profile());
list.insert_at(0, *prod2, 0);
//list.set("title", desc.toUtf8().constData());
xmlConsumer.connect(list);
xmlConsumer.run();
delete prod2;
}
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QUrl>
#include <QMutex>
#include <QDateTime>
#include <QDir>
class QPixmap;
class BinController;
......@@ -194,6 +195,8 @@ public:
void moveEffect(int oldPos, int newPos);
/** @brief Request an update of all track producers */
void reloadTrackProducers();
/** @brief Save an xml playlist of current clip with in/out points as zone.x()/y() */
void saveZone(QPoint zone, QDir dir);
private:
Mlt::Producer *m_masterProducer;
......
......@@ -774,3 +774,7 @@ QString ProjectManager::getDefaultProjectFormat()
return QStringLiteral("atsc_1080p_2997");
}
void ProjectManager::saveZone(QStringList info, QDir dir)
{
pCore->bin()->saveZone(info, dir);
}
......@@ -62,6 +62,7 @@ public:
QString projectSceneList();
/** @brief returns a default hd profile depending on timezone*/
static QString getDefaultProjectFormat();
void saveZone(QStringList info, QDir dir);
public slots:
void newFile(bool showProjectSettings = true, bool force = false);
......
Supports Markdown
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