Commit 2458320a authored by Nicolas Carion's avatar Nicolas Carion

Start using new scheme for binClip insertion and implement it for ColorClip

parent f3ec78c9
......@@ -1293,13 +1293,7 @@ void Bin::createClip(const QDomElement &xml)
QString Bin::slotAddFolder(const QString &folderName)
{
// Check parent item
QModelIndex ix = m_proxyModel->selectionModel()->currentIndex();
std::shared_ptr<ProjectFolder> parentFolder = m_itemModel->getRootFolder();
if (ix.isValid() && m_proxyModel->selectionModel()->isSelected(ix)) {
std::shared_ptr<AbstractProjectItem> currentItem = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
parentFolder = std::static_pointer_cast<ProjectFolder>(currentItem->getEnclosingFolder());
}
auto parentFolder = m_itemModel->getFolderByBinId(getCurrentFolder());
qDebug() << "pranteforder id" << parentFolder->clipId();
QString newId;
Fun undo = []() { return true; };
......@@ -1313,7 +1307,7 @@ QString Bin::slotAddFolder(const QString &folderName)
return newId;
}
auto folder = m_itemModel->getFolderByBinId(newId);
ix = m_itemModel->getIndexFromItem(folder);
auto ix = m_itemModel->getIndexFromItem(folder);
qDebug() << "selecting" << ix;
if (ix.isValid()) {
qDebug() << "ix valid";
......@@ -2346,9 +2340,10 @@ void Bin::slotCreateProjectClip()
}
ClipType type = (ClipType)act->data().toInt();
QStringList folderInfo = getFolderInfo();
QString parentFolder = getCurrentFolder();
switch (type) {
case Color:
ClipCreationDialog::createColorClip(m_doc, folderInfo, this);
ClipCreationDialog::createColorClip(m_doc, parentFolder, m_itemModel);
break;
case SlideShow:
ClipCreationDialog::createSlideshowClip(m_doc, folderInfo, this);
......@@ -3503,3 +3498,16 @@ std::shared_ptr<EffectStackModel> Bin::getClipEffectStack(int itemId)
std::shared_ptr<EffectStackModel> effectStack = std::static_pointer_cast<ClipController>(clip)->m_effectStack;
return effectStack;
}
QString Bin::getCurrentFolder()
{
// Check parent item
QModelIndex ix = m_proxyModel->selectionModel()->currentIndex();
std::shared_ptr<ProjectFolder> parentFolder = m_itemModel->getRootFolder();
if (ix.isValid() && m_proxyModel->selectionModel()->isSelected(ix)) {
std::shared_ptr<AbstractProjectItem> currentItem = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
parentFolder = std::static_pointer_cast<ProjectFolder>(currentItem->getEnclosingFolder());
}
return parentFolder->clipId();
}
......@@ -302,6 +302,8 @@ public:
QStringList getProxyHashList();
/** @brief Get info (id, name) of a folder (or the currently selected one) */
const QStringList getFolderInfo(const QModelIndex &selectedIx = QModelIndex());
/** @brief Get binId of the current selected folder */
QString getCurrentFolder();
/** @brief Save a clip zone as MLT playlist */
void saveZone(const QStringList &info, const QDir &dir);
QVariantList audioFrameCache(const QString &id);
......
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "projectclip.h"
#include "projectfolder.h"
#include "projectsubclip.h"
#include "xml/xml.hpp"
#include <KLocalizedString>
#include <QIcon>
......@@ -43,10 +44,16 @@ ProjectItemModel::ProjectItemModel(QObject *parent)
, m_lock(QReadWriteLock::Recursive)
, m_binPlaylist(new BinPlaylist())
, m_nextId(1)
, m_blankThumb()
{
KImageCache::deleteCache(QStringLiteral("kdenlive-thumbs"));
m_pixmapCache.reset(new KImageCache(QStringLiteral("kdenlive-thumbs"), 10000000));
m_pixmapCache->setEvictionPolicy(KSharedDataCache::EvictOldest);
QPixmap pix(QSize(160, 90));
pix.fill(Qt::lightGray);
m_blankThumb.addPixmap(pix);
}
std::shared_ptr<ProjectItemModel> ProjectItemModel::construct(QObject *parent)
......@@ -427,7 +434,7 @@ int ProjectItemModel::getFreeClipId()
return m_nextId++;
}
bool ProjectItemModel::requestAddFolder(QString &id, const QString &name, const QString &parentId, Fun &undo, Fun &redo)
bool ProjectItemModel::addItem(std::shared_ptr<AbstractProjectItem> item, const QString &parentId, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
std::shared_ptr<ProjectFolder> parentFolder = getFolderByBinId(parentId);
......@@ -435,17 +442,50 @@ bool ProjectItemModel::requestAddFolder(QString &id, const QString &name, const
qCDebug(KDENLIVE_LOG) << " / / ERROR IN PARENT FOLDER";
return false;
}
Fun operation = addItem_lambda(item, parentFolder->getId());
int itemId = item->getId();
Fun reverse = removeItem_lambda(itemId);
bool res = operation();
Q_ASSERT(item->isInModel());
if (res) {
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
}
return res;
}
bool ProjectItemModel::requestAddFolder(QString &id, const QString &name, const QString &parentId, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
if (id.isEmpty()) {
id = QString::number(getFreeFolderId());
}
std::shared_ptr<ProjectFolder> new_folder = ProjectFolder::construct(id, name, std::static_pointer_cast<ProjectItemModel>(shared_from_this()));
Fun operation = addItem_lambda(new_folder, parentFolder->getId());
int folderId = new_folder->getId();
Fun reverse = removeItem_lambda(folderId);
bool res = operation();
Q_ASSERT(new_folder->isInModel());
return addItem(new_folder, parentId, undo, redo);
}
bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, Fun &undo, Fun &redo)
{
QWriteLocker locker(&m_lock);
if (id.isEmpty()) {
QString defaultId = QString::number(getFreeFolderId());
id = Xml::getTagContentByAttribute(description, QStringLiteral("property"), QStringLiteral("name"), QStringLiteral("kdenlive:id"), defaultId);
}
std::shared_ptr<ProjectClip> new_clip = ProjectClip::construct(id, description, m_blankThumb, std::static_pointer_cast<ProjectItemModel>(shared_from_this()));
bool res = addItem(new_clip, parentId, undo, redo);
if (res) {
UPDATE_UNDO_REDO(operation, reverse, undo, redo);
//TODO Not very clean, improve (should pass pointer to projectClip instead of xml)
pCore->currentDoc()->getFileProperties(description, new_clip->clipId(), 150, true);
}
return res;
}
bool ProjectItemModel::requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = requestAddBinClip(id, description, parentId, undo, redo);
if (res) {
pCore->pushUndo(undo, redo, undoText.isEmpty() ? i18n("Rename Folder") : undoText);
}
return res;
}
......
......@@ -117,6 +117,15 @@ public:
*/
bool requestAddFolder(QString &id, const QString &name, const QString &parentId, Fun &undo, Fun &redo);
/* @brief Request creation of a bin clip
@param id Id of the requested bin. If this is empty, it will be used as a return parameter to give the automatic bin id used.
@param description Xml description of the clip
@param parentId Bin id of the parent folder
@param undo,redo: lambdas that are updated to accumulate operation.
*/
bool requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, Fun &undo, Fun &redo);
bool requestAddBinClip(QString &id, const QDomElement &description, const QString &parentId, const QString &undoText = QString());
/* @brief Request that a folder's name is changed
@param clip : pointer to the folder to rename
@param name: new name of the folder
......@@ -145,6 +154,9 @@ protected:
/* @brief Helper function to generate a lambda that rename a folder */
Fun requestRenameFolder_lambda(std::shared_ptr<AbstractProjectItem> folder, const QString &newName);
/* @brief Helper function to add a given item to the tree */
bool addItem(std::shared_ptr<AbstractProjectItem> item, const QString &parentId, Fun &undo, Fun &redo);
std::unique_ptr<KImageCache> m_pixmapCache;
public slots:
/** @brief An item in the list was modified, notify */
......@@ -159,6 +171,8 @@ private:
std::unique_ptr<BinPlaylist> m_binPlaylist;
int m_nextId;
QIcon m_blankThumb;
signals:
void discardJobs(const QString &id, AbstractClipJob::JOBTYPE type);
void startJob(const QString &id, AbstractClipJob::JOBTYPE type);
......
......@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "clipcreationdialog.h"
#include "bin/bin.h"
#include "bin/bincommands.h"
#include "bin/projectitemmodel.h"
#include "bin/projectclip.h"
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
......@@ -117,17 +118,17 @@ void ClipCreationDialog::createClipFromXml(KdenliveDoc *doc, QDomElement &xml, c
}
// static
void ClipCreationDialog::createColorClip(KdenliveDoc *doc, const QStringList &groupInfo, Bin *bin)
void ClipCreationDialog::createColorClip(KdenliveDoc *doc, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model)
{
QPointer<QDialog> dia = new QDialog(bin);
QScopedPointer<QDialog> dia(new QDialog(qApp->activeWindow()));
Ui::ColorClip_UI dia_ui;
dia_ui.setupUi(dia);
dia_ui.setupUi(dia.data());
dia->setWindowTitle(i18n("Color Clip"));
dia_ui.clip_name->setText(i18n("Color Clip"));
TimecodeDisplay *t = new TimecodeDisplay(doc->timecode());
QScopedPointer<TimecodeDisplay> t(new TimecodeDisplay(doc->timecode()));
t->setValue(KdenliveSettings::color_duration());
dia_ui.clip_durationBox->addWidget(t);
dia_ui.clip_durationBox->addWidget(t.data());
dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
if (dia->exec() == QDialog::Accepted) {
......@@ -139,25 +140,19 @@ void ClipCreationDialog::createColorClip(KdenliveDoc *doc, const QStringList &gr
QDomElement prod = xml.createElement(QStringLiteral("producer"));
xml.appendChild(prod);
prod.setAttribute(QStringLiteral("type"), (int) Color);
int id = bin->getFreeClipId();
prod.setAttribute(QStringLiteral("id"), QString::number(id));
prod.setAttribute(QStringLiteral("in"), QStringLiteral("0"));
prod.setAttribute(QStringLiteral("length"), doc->getFramePos(doc->timecode().getTimecode(t->gentime())));
QMap<QString, QString> properties;
properties.insert(QStringLiteral("resource"), color);
properties.insert(QStringLiteral("kdenlive:clipname"), dia_ui.clip_name->text());
properties.insert(QStringLiteral("mlt_service"), QStringLiteral("color"));
if (!groupInfo.isEmpty()) {
properties.insert(QStringLiteral("kdenlive:folderid"), groupInfo.at(0));
}
addXmlProperties(prod, properties);
qDebug() << xml.toString();
qDebug() << Xml::getTagContentByAttribute(xml.documentElement(), QStringLiteral("property"), QStringLiteral("name"), QStringLiteral("resource"));
AddClipCommand *command = new AddClipCommand(bin, xml.documentElement(), QString::number(id), true);
doc->commandStack()->push(command);
QString id;
model->requestAddBinClip(id, xml.documentElement(), parentFolder, i18n("Create color clip"));
}
delete t;
delete dia;
}
void ClipCreationDialog::createQTextClip(KdenliveDoc *doc, const QStringList &groupInfo, Bin *bin, ProjectClip *clip)
......
......@@ -28,6 +28,7 @@ class KdenliveDoc;
class QUndoCommand;
class Bin;
class ProjectClip;
class ProjectItemModel;
/**
* @namespace ClipCreationDialog
......@@ -38,7 +39,7 @@ class ProjectClip;
namespace ClipCreationDialog {
QStringList getExtensions();
void createColorClip(KdenliveDoc *doc, const QStringList &groupInfo, Bin *bin);
void createColorClip(KdenliveDoc *doc, const QString &parentFolder, std::shared_ptr<ProjectItemModel> model);
void createQTextClip(KdenliveDoc *doc, const QStringList &groupInfo, Bin *bin, ProjectClip *clip = nullptr);
void createClipFromXml(KdenliveDoc *doc, QDomElement &xml, const QStringList &groupInfo, Bin *bin);
void createSlideshowClip(KdenliveDoc *doc, const QStringList &groupInfo, Bin *bin);
......
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