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

Fixes for color clips and more

parent 8f263ba1
......@@ -31,6 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "project/jobs/jobmanager.h"
#include "monitor/monitor.h"
#include "doc/kdenlivedoc.h"
#include "dialogs/clipcreationdialog.h"
#include "core.h"
#include "mltcontroller/clipcontroller.h"
#include "projectsortproxymodel.h"
......@@ -205,11 +206,9 @@ Monitor *Bin::monitor()
return m_monitor;
}
void Bin::slotAddClip()
const QStringList Bin::getFolderInfo()
{
// Check if we are in a folder
QString folderName;
QString folderId;
QStringList folderInfo;
QModelIndex ix = m_proxyModel->selectionModel()->currentIndex();
if (ix.isValid() && m_proxyModel->selectionModel()->isSelected(ix)) {
AbstractProjectItem *currentItem = static_cast<AbstractProjectItem *>(m_proxyModel->mapToSource(ix).internalPointer());
......@@ -219,11 +218,18 @@ void Bin::slotAddClip()
if (currentItem == m_rootFolder) {
// clip was added to root folder, leave folder info empty
} else {
folderName = currentItem->name();
folderId = currentItem->clipId();
folderInfo << currentItem->name();
folderInfo << currentItem->clipId();
}
}
pCore->projectManager()->current()->clipManager()->slotAddClip(QString(), folderName, folderId);
return folderInfo;
}
void Bin::slotAddClip()
{
// Check if we are in a folder
QStringList folderInfo = getFolderInfo();
pCore->projectManager()->current()->clipManager()->slotAddClip(QString(), folderInfo);
}
void Bin::deleteClip(const QString &id)
......@@ -840,3 +846,8 @@ bool Bin::hasPendingJob(const QString &id, AbstractClipJob::JOBTYPE type)
return m_jobManager->hasPendingJob(id, type);
}
void Bin::slotCreateColorClip()
{
QStringList folderInfo = getFolderInfo();
ClipCreationDialogDialog::createColorClip(pCore->projectManager()->current(), folderInfo);
}
......@@ -318,6 +318,7 @@ public slots:
void slotSwitchClipProperties(const QModelIndex &ix);
void slotSwitchClipProperties();
void slotAddFolder();
void slotCreateColorClip();
protected:
void contextMenuEvent(QContextMenuEvent *event);
......@@ -356,6 +357,7 @@ private:
QAction *m_deleteAction;
void showClipProperties(ProjectClip *clip);
void selectModel(const QModelIndex &id);
const QStringList getFolderInfo();
signals:
void itemUpdated(AbstractProjectItem*);
......
......@@ -56,8 +56,11 @@ ProjectClip::ProjectClip(const QDomElement& description, ProjectFolder* parent)
{
Q_ASSERT(description.hasAttribute("id"));
m_properties = QMap <QString, QString> ();
QUrl resource = QUrl::fromLocalFile(getXmlProperty(description, "resource"));
m_name = resource.fileName();
QString resource = getXmlProperty(description, "resource");
if (!resource.isEmpty()) {
m_name = QUrl::fromLocalFile(resource).fileName();
}
else m_name = description.attribute("name");
if (description.hasAttribute("zone"))
m_zone = QPoint(description.attribute("zone").section(':', 0, 0).toInt(), description.attribute("zone").section(':', 1, 1).toInt());
setParent(parent);
......@@ -140,8 +143,10 @@ QUrl ProjectClip::url() const
bool ProjectClip::hasLimitedDuration() const
{
//TODO: should be false for color and image clips
return m_hasLimitedDuration;
if (m_controller) {
return m_controller->hasLimitedDuration();
}
return true;
}
GenTime ProjectClip::duration() const
......@@ -235,8 +240,12 @@ void ProjectClip::setProducer(ClipController *controller, bool replaceProducer)
m_controller->updateProducer(controller->masterProducer());
delete controller;
}
else m_controller = controller;
m_duration = m_controller->getStringDuration();
else {
// We did not yet have the controller, update info
m_controller = controller;
if (m_name.isEmpty()) m_name = m_controller->clipName();
m_duration = m_controller->getStringDuration();
}
bin()->emitItemUpdated(this);
getFileHash();
}
......
......@@ -77,7 +77,7 @@ QVariant ProjectItemModel::data(const QModelIndex& index, int role) const
AbstractProjectItem *item = static_cast<AbstractProjectItem *>(index.internalPointer());
return item->data(AbstractProjectItem::DataDuration);
}
if (role == Bin::JobType | Bin::JobProgress | Bin::JobMessage | Bin::ItemTypeRole) {
if (role == Bin::JobType || role == Bin::JobProgress || role == Bin::JobMessage || role == Bin::ItemTypeRole) {
AbstractProjectItem *item = static_cast<AbstractProjectItem *>(index.internalPointer());
return item->data((AbstractProjectItem::DataType) role);
}
......
set(kdenlive_SRCS
${kdenlive_SRCS}
dialogs/clipcreationdialog.cpp
dialogs/encodingprofilesdialog.cpp
dialogs/kdenlivesettingsdialog.cpp
dialogs/profilesdialog.cpp
......
......@@ -1087,7 +1087,8 @@ const QString KdenliveDoc::description() const
bool KdenliveDoc::addClip(QDomElement elem, const QString &clipId, bool createClipItem)
{
const QString producerId = clipId.section('_', 0, 0);
m_clipManager->addProjectClip(elem, producerId);
elem.setAttribute("id", producerId);
pCore->bin()->createClip(elem);
m_render->getFileProperties(elem, producerId, 150, true);
QString str;
......@@ -1300,9 +1301,9 @@ void KdenliveDoc::slotCreateXmlClip(const QString &name, const QDomElement &xml,
emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
}
void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId)
void KdenliveDoc::slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QStringList &groupInfo)
{
m_clipManager->slotAddColorClipFile(name, color, duration, group, groupId);
m_clipManager->slotAddColorClipFile(name, color, duration, groupInfo);
setModified(true);
emit selectLastAddedClip(QString::number(m_clipManager->lastClipId()));
}
......
......@@ -226,7 +226,7 @@ private:
public slots:
void slotCreateXmlClip(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
void slotCreateColorClip(const QString &name, const QString &color, const QString &duration, const QStringList &groupInfo);
void slotCreateSlideshowClipFile(const QMap<QString, QString> &properties, const QString &group, const QString &groupId);
/**
* @brief Create a title clip.
......
......@@ -1123,7 +1123,7 @@ void MainWindow::setupActions()
QAction *addClip = addAction("add_clip", i18n("Add Clip"), pCore->bin(), SLOT(slotAddClip()), QIcon::fromTheme("kdenlive-add-clip"));
addClips->addAction(addClip);
addClips->addAction(addAction("add_color_clip", i18n("Add Color Clip"), m_projectList, SLOT(slotAddColorClip()),
addClips->addAction(addAction("add_color_clip", i18n("Add Color Clip"), pCore->bin(), SLOT(slotCreateColorClip()),
QIcon::fromTheme("kdenlive-add-color-clip")));
addClips->addAction(addAction("add_slide_clip", i18n("Add Slideshow Clip"), m_projectList, SLOT(slotAddSlideshowClip()),
QIcon::fromTheme("kdenlive-add-slide-clip")));
......
......@@ -32,23 +32,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
ClipController::ClipController(BinController *bincontroller, Mlt::Producer& producer) : QObject()
, m_binController(bincontroller)
, m_snapMarkers(QList < CommentedTime >())
, m_hasLimitedDuration(true)
{
m_masterProducer = &producer;
if (!m_masterProducer->is_valid()) qDebug()<<"// WARNING, USING INVALID PRODUCER";
else {
append(m_masterProducer);
m_url = QUrl::fromLocalFile(m_masterProducer->get("resource"));
if (m_url.isValid()) {
m_name = m_url.fileName();
}
m_service = m_masterProducer->get("mlt_service");
m_duration = GenTime(m_masterProducer->get_playtime(), m_binController->fps());
getInfoForProducer();
}
}
ClipController::ClipController(BinController *bincontroller) : QObject()
, m_binController(bincontroller)
, m_snapMarkers(QList < CommentedTime >())
, m_hasLimitedDuration(true)
, m_clipType(Unknown)
{
m_masterProducer = NULL;
}
......@@ -67,16 +67,51 @@ void ClipController::addMasterProducer(Mlt::Producer &producer)
m_masterProducer = &producer;
if (!m_masterProducer->is_valid()) qDebug()<<"// WARNING, USING INVALID PRODUCER";
else {
m_duration = GenTime(m_masterProducer->get_playtime(), m_binController->fps());
insert(0, m_masterProducer);
m_url = QUrl::fromLocalFile(m_masterProducer->get("resource"));
if (m_url.isValid()) {
m_name = m_url.fileName();
}
m_service = m_masterProducer->get("mlt_service");
getInfoForProducer();
}
}
void ClipController::getInfoForProducer()
{
m_duration = GenTime(m_masterProducer->get_playtime(), m_binController->fps());
if (m_service == "avformat" || m_service == "avformat-novalidate") {
m_clipType = AV;
}
else if (m_service == "qimage" || m_service == "pixbuf") {
m_clipType = Image;
}
else if (m_service == "colour" || m_service == "color") {
m_clipType = Color;
}
else if (m_service == "kdenlivetitle") {
m_clipType = Text;
}
else if (m_service == "mlt") {
m_clipType = Playlist;
}
else m_clipType = Unknown;
if (m_clipType == AV || m_clipType == Video || m_clipType == Audio || m_clipType == Image || m_clipType == Playlist) {
m_name = m_url.fileName();
}
else if (m_clipType == Color) {
m_name = i18n("Color");
m_hasLimitedDuration = false;
}
else if (m_clipType == Text) {
m_name = i18n("Title");
m_hasLimitedDuration = false;
}
}
bool ClipController::hasLimitedDuration() const
{
return m_hasLimitedDuration;
}
Mlt::Producer &ClipController::originalProducer()
{
return *m_masterProducer;
......@@ -118,11 +153,16 @@ void ClipController::updateProducer(Mlt::Producer* producer)
}
}
Mlt::Producer *ClipController::getTrackProducer(int track, PlaylistState::ClipState clipState, double speed)
{
if (track == -1) {
return m_masterProducer;
}
if (m_clipType != AV && m_clipType != Audio && m_clipType != Playlist) {
// Only producers with audio need a different producer for each track (or we have an audio crackle bug)
return new Mlt::Producer(m_masterProducer->parent());
}
QString clipWithTrackId = clipId();
clipWithTrackId.append("_" + QString::number(track));
......@@ -212,17 +252,7 @@ void ClipController::setProperty(const QString& name, const QString& value)
ClipType ClipController::clipType() const
{
if (!m_masterProducer || !m_masterProducer->is_valid()) return Unknown;
if (m_service == "avformat" || m_service == "avformat-novalidate") {
return AV;
}
if (m_service == "qimage" || m_service == "pixbuf") {
return Image;
}
if (m_service == "color") {
return Color;
}
return Unknown;
return m_clipType;
}
......
......@@ -127,6 +127,7 @@ public:
CommentedTime markerAt(const GenTime &t) const;
void setZone(const QPoint &zone);
QPoint zone() const;
bool hasLimitedDuration() const;
private:
Mlt::Producer *m_masterProducer;
......@@ -134,9 +135,12 @@ private:
GenTime m_duration;
QUrl m_url;
QString m_name;
ClipType m_clipType;
bool m_hasLimitedDuration;
BinController *m_binController;
/** A list of snap markers; these markers are added to a clips snap-to points, and are displayed as necessary. */
QList < CommentedTime > m_snapMarkers;
void getInfoForProducer();
};
#endif
......@@ -397,15 +397,15 @@ QMap <QString, QString> ClipManager::documentFolderList() const
return m_folderList;
}
void ClipManager::slotAddClip(const QString &url, const QString &groupName, const QString &groupId)
void ClipManager::slotAddClip(const QString &url, const QStringList &groupInfo)
{
//qDebug()<<"// Adding clip: "<<url;
QList <QUrl> list = QList <QUrl>();
if (!url.isEmpty()) list.append(QUrl::fromLocalFile(url));
slotAddClipList(list, groupName, groupId);
slotAddClipList(list, groupInfo);
}
void ClipManager::slotAddClipList(const QList <QUrl> &givenList, const QString &groupName, const QString &groupId)
void ClipManager::slotAddClipList(const QList <QUrl> &givenList, const QStringList &groupInfo)
{
if (!m_doc->commandStack())
qDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
......@@ -451,8 +451,7 @@ void ClipManager::slotAddClipList(const QList <QUrl> &givenList, const QString &
int count = list.count();
if (count > 1) {
delete d;
QStringList groupInfo; // = getGroup();
groupInfo << QString() << QString();
/*QStringList groupInfo = getGroup(); */
// get image sequence base name
while (fileName.at(fileName.size() - 1).isDigit()) {
fileName.chop(1);
......@@ -498,18 +497,12 @@ void ClipManager::slotAddClipList(const QList <QUrl> &givenList, const QString &
if (folderFiles.count() > 1) foldersList.append(folderFiles);
}
}
/*if (givenList.isEmpty() && !list.isEmpty()) {
QStringList groupInfo; // = getGroup();
groupInfo << QString() << QString();
if (givenList.isEmpty() && !list.isEmpty()) {
QMap <QString, QString> data;
data.insert("group", groupInfo.at(0));
data.insert("groupId", groupInfo.at(1));
doAddClipList(list, data);
} else*/
if (!list.isEmpty()) {
QMap <QString, QString> data;
data.insert("group", groupName);
data.insert("groupId", groupId);
if (!groupInfo.isEmpty()) {
data.insert("group", groupInfo.at(0));
data.insert("groupId", groupInfo.at(1));
}
doAddClipList(list, data);
}
......@@ -543,12 +536,6 @@ void ClipManager::deleteProjectClip(const QString &clipId)
pCore->bin()->deleteClip(clipId);
}
void ClipManager::addProjectClip(QDomElement xml, const QString &clipId)
{
xml.setAttribute("id", clipId);
pCore->bin()->createClip(xml);
}
void ClipManager::slotDeleteClips(QStringList ids)
{
QUndoCommand *delClips = new QUndoCommand();
......@@ -765,7 +752,7 @@ void ClipManager::slotAddXmlClipFile(const QString &name, const QDomElement &xml
m_doc->commandStack()->push(command);
}
void ClipManager::slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId)
void ClipManager::slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QStringList &groupInfo)
{
QDomDocument doc;
QDomElement prod = doc.createElement("producer");
......@@ -778,9 +765,9 @@ void ClipManager::slotAddColorClipFile(const QString &name, const QString &color
prod.setAttribute("in", "0");
prod.setAttribute("out", m_doc->getFramePos(duration) - 1);
prod.setAttribute("name", name);
if (!group.isEmpty()) {
prod.setAttribute("groupname", group);
prod.setAttribute("groupid", groupId);
if (!groupInfo.isEmpty()) {
prod.setAttribute("group", groupInfo.at(0));
prod.setAttribute("groupid", groupInfo.at(1));
}
AddClipCommand *command = new AddClipCommand(m_doc, doc.documentElement(), QString::number(id), true);
m_doc->commandStack()->push(command);
......
......@@ -78,21 +78,15 @@ Q_OBJECT public:
* @param groupId id of the group (if any)
* It checks for duplicated items and asks to the user for instructions. */
void doAddClipList(const QList<QUrl> &urls, const QMap<QString, QString> &data = QMap<QString, QString>());
/** @brief Build a ProjectClip item
* @param xml description of the clip
* @param clipId The id we want to set on this clip */
void addProjectClip(QDomElement xml, const QString &clipId);
void deleteProjectClip(const QString &clipId);
void slotAddClip(const QString &url, const QString &groupName, const QString &groupId);
void slotAddClipList(const QList <QUrl> &givenList, const QString &groupName, const QString &groupId);
void slotAddClip(const QString &url, const QStringList &groupInfo);
void slotAddClipList(const QList <QUrl> &givenList, const QStringList &groupInfo);
void slotAddTextClipFile(const QString &titleName, int out, const QString &xml, const QString &group, const QString &groupId);
void slotAddTextTemplateClip(QString titleName, const QUrl &path, const QString &group, const QString &groupId);
void slotAddXmlClipFile(const QString &name, const QDomElement &xml, const QString &group, const QString &groupId);
void slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QString &group, const QString &groupId);
void slotAddColorClipFile(const QString &name, const QString &color, const QString &duration, const QStringList &groupInfo);
void slotAddSlideshowClipFile(QMap <QString, QString> properties, const QString &group, const QString &groupId);
//const QList <DocClipBase *> getClipByResource(const QString &resource);
void slotDeleteClips(QStringList ids);
......
......@@ -1845,34 +1845,6 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
m_thumbnailQueue.removeAll(id);
}
void ProjectList::slotAddColorClip()
{
if (!m_commandStack)
qDebug() << "!!!!!!!!!!!!!!!! NO CMD STK";
QPointer<QDialog> dia = new QDialog(this);
Ui::ColorClip_UI dia_ui;
dia_ui.setupUi(dia);
dia->setWindowTitle(i18n("Color Clip"));
dia_ui.clip_name->setText(i18n("Color Clip"));
TimecodeDisplay *t = new TimecodeDisplay(m_timecode);
t->setValue(KdenliveSettings::color_duration());
dia_ui.clip_durationBox->addWidget(t);
dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor());
if (dia->exec() == QDialog::Accepted) {
QString color = dia_ui.clip_color->color().name();
KdenliveSettings::setColorclipcolor(color);
color = color.replace(0, 1, "0x") + "ff";
QStringList groupInfo = getGroup();
m_doc->slotCreateColorClip(dia_ui.clip_name->text(), color, m_timecode.getTimecode(t->gentime()), groupInfo.at(0), groupInfo.at(1));
}
delete t;
delete dia;
}
void ProjectList::slotAddSlideshowClip()
{
if (!m_commandStack)
......
......@@ -191,9 +191,6 @@ public slots:
void slotOpenClip();
void slotEditClip();
void slotReloadClip(const QString &id = QString());
/** @brief Shows dialog for setting up a color clip. */
void slotAddColorClip();
void regenerateTemplate(const QString &id);
void slotUpdateClipCut(QPoint p);
void slotAddClipCut(const QString &id, int in, int out);
......
......@@ -67,7 +67,6 @@ ClipItem::ClipItem(ProjectClip *clip, const ItemInfo& info, double fps, double s
FRAME_SIZE = frame_width;
setRect(0, 0, (info.endPos - info.startPos).frames(fps) - 0.02, (double) itemHeight());
setPos(info.startPos.frames(fps), (double)(info.track * KdenliveSettings::trackheight()) + 1 + itemOffset());
// set speed independent info
if (m_speed <= 0 && m_speed > -1)
m_speed = -1.0;
......@@ -85,13 +84,18 @@ ClipItem::ClipItem(ProjectClip *clip, const ItemInfo& info, double fps, double s
m_clipType = m_binClip->clipType();
//m_cropStart = info.cropStart;
m_maxDuration = m_binClip->duration();
if (m_binClip->hasLimitedDuration()) {
m_maxDuration = m_binClip->duration();
}
else {
// For color / image / text clips, we have unlimited duration
m_maxDuration = GenTime();
}
setAcceptDrops(true);
m_audioThumbReady = m_binClip->audioThumbCreated();
//setAcceptsHoverEvents(true);
connect(this , SIGNAL(prepareAudioThumb(double,int,int,int,int)) , this, SLOT(slotPrepareAudioThumb(double,int,int,int,int)));
if (m_clipType == Video || m_clipType == AV || m_clipType == SlideShow || m_clipType == Playlist) {
if (m_clipType == AV || m_clipType == Video || m_clipType == SlideShow || m_clipType == Playlist ) {
m_baseColor = QColor(141, 166, 215);
//TODO:
if (false /*&& !m_clip->isPlaceHolder()*/) {
......@@ -107,7 +111,7 @@ ClipItem::ClipItem(ProjectClip *clip, const ItemInfo& info, double fps, double s
}
} else if (m_clipType == Color) {
QString colour = m_binClip->getProducerProperty("colour");
QString colour = m_binClip->getProducerProperty("resource");
colour = colour.replace(0, 2, "#");
m_baseColor = QColor(colour.left(7));
} else if (m_clipType == Image || m_clipType == Text) {
......
......@@ -1651,9 +1651,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
QMutexLocker lock(&m_selectionMutex);
if (track < 0 || track > m_document->tracksCount() - 1 || m_document->trackInfoAt(m_document->tracksCount() - track - 1).isLocked) return true;
if (data->hasFormat("kdenlive/clip")) {
qDebug()<< " * * RECIEVED DRAD";
QStringList list = QString(data->data("kdenlive/clip")).split(';');
qDebug()<< " * * RECIEVED DRAD:" << list.at(0);
ProjectClip *clip = m_document->getBinClip(list.at(0));
if (clip == NULL) {
//qDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
......
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