#include "moveclipcommand.h"
#include "resizeclipcommand.h"
#include "addtimelineclipcommand.h"
+#include "addeffectcommand.h"
CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
: QGraphicsView(projectscene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_startPos(QPointF()), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(0), m_document(doc)
for (int i = 0; i < collisionList.size(); ++i) {
QGraphicsItem *item = collisionList.at(i);
if (item->type() == 70000) {
+ // select item
+ if (!item->isSelected()) {
+ QList<QGraphicsItem *> itemList = items();
+ for (int i = 0; i < itemList.count(); i++)
+ itemList.at(i)->setSelected(false);
+ item->setSelected(true);
+ update();
+ }
m_dragItem = (ClipItem *) item;
+ emit clipItemSelected(m_dragItem);
m_clickPoint = mapToScene(event->pos()).x() - m_dragItem->startPos() * m_scale;
m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
- if (m_operationMode == MOVE || m_operationMode == RESIZESTART) m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
- else if (m_operationMode == RESIZEEND) m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
+ if (m_operationMode == MOVE || m_operationMode == RESIZESTART)
+ m_startPos = QPointF(m_dragItem->startPos(), m_dragItem->track());
+ else if (m_operationMode == RESIZEEND)
+ m_startPos = QPointF(m_dragItem->endPos(), m_dragItem->track());
kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
collision = true;
break;
}
updateSnapPoints(m_dragItem);
//kDebug()<<pos;
- QGraphicsView::mousePressEvent(event);
+ //QGraphicsView::mousePressEvent(event);
}
void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
{
if (event->mimeData()->hasText()) {
- QString clip = event->mimeData()->text();
+ kDebug()<<"/////////////// DRAG ENTERED, TEXT: "<<event->mimeData()->text();
+ QStringList ids = QString(event->mimeData()->text()).split(";");
+ //TODO: drop of several clips
+ for (int i = 0; i < ids.size(); ++i) {
+ }
+ DocClipBase *clip = m_document->getBaseClip(ids.at(0).toInt());
+ if (clip == NULL) kDebug()<<" WARNING))))))))) CLIP NOT FOUND : "<<ids.at(0).toInt();
addItem(clip, event->pos());
event->acceptProposedAction();
}
}
+void CustomTrackView::addEffect(int track, GenTime pos, QString tag, QMap <QString, QString> args)
+{
+ m_document->renderer()->mltAddEffect(track, pos, tag, args);
+ ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+ if (clip) clip->addEffect(args);
+}
+
+void CustomTrackView::deleteEffect(int track, GenTime pos, QString tag)
+{
+ m_document->renderer()->mltRemoveEffect(track, pos, tag, -1);
+ ClipItem *clip = getClipItemAt(pos.frames(m_document->fps()) + 1, m_tracksCount - track);
+ if (clip) clip->deleteEffect(tag);
+}
+
+void CustomTrackView::slotAddEffect(QMap <QString, QString> filter)
+{
+ QList<QGraphicsItem *> itemList = items();
+ for (int i = 0; i < itemList.count(); i++) {
+ if (itemList.at(i)->type() == 70000 && itemList.at(i)->isSelected()) {
+ ClipItem *item = (ClipItem *)itemList.at(i);
+ QString tag = filter.value("mlt_service");
+ AddEffectCommand *command = new AddEffectCommand(this, m_tracksCount - item->track(),GenTime(item->startPos(), m_document->fps()), tag, filter, true);
+ m_commandStack->push(command);
+ }
+ }
+}
-void CustomTrackView::addItem(QString producer, QPoint pos)
+void CustomTrackView::addItem(DocClipBase *clip, QPoint pos)
{
- QDomDocument doc;
- doc.setContent(producer);
- QDomElement elem = doc.documentElement();
- int in = elem.attribute("in", 0).toInt();
- int out = elem.attribute("out", 0).toInt() - in;
- if (out == 0) out = elem.attribute("duration", 0).toInt();
- kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
+ int in =0;
+ int out = clip->duration().frames(m_document->fps());
+ //kdDebug()<<"- - - -CREATING CLIP, duration = "<<out<<", URL: "<<clip->fileURL();
int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
- m_dropItem = new ClipItem(elem, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
+ m_dropItem = new ClipItem(clip, ((int) mapToScene(pos).y()/50), in, QRectF(mapToScene(pos).x() * m_scale, trackTop, out * m_scale, 49), out);
scene()->addItem(m_dropItem);
}
void CustomTrackView::dropEvent ( QDropEvent * event ) {
if (m_dropItem) {
- AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false);
+ AddTimelineClipCommand *command = new AddTimelineClipCommand(this, m_dropItem->xml(), m_dropItem->clipProducer(), m_dropItem->track(), m_dropItem->startPos(), m_dropItem->rect(), m_dropItem->duration(), false, false);
m_commandStack->push(command);
- m_document->renderer()->mltInsertClip(m_dropItem->track(), GenTime(m_dropItem->startPos(), 25), m_dropItem->xml());
+ m_dropItem->baseClip()->addReference();
+ m_document->updateClip(m_dropItem->baseClip()->getId());
+ kDebug()<<"IIIIIIIIIIIIIIIIIIIIIIII TRAX CNT: "<<m_tracksCount<<", DROP: "<<m_dropItem->track();
+ m_document->renderer()->mltInsertClip(m_tracksCount - m_dropItem->track(), GenTime(m_dropItem->startPos(), m_document->fps()), m_dropItem->xml());
}
m_dropItem = NULL;
}
m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), 50 * m_tracksCount);
}
-void CustomTrackView::setCursorPos(int pos)
+void CustomTrackView::deleteClip(int clipId)
+{
+ QList<QGraphicsItem *> itemList = items();
+ for (int i = 0; i < itemList.count(); i++) {
+ if (itemList.at(i)->type() == 70000) {
+ ClipItem *item = (ClipItem *)itemList.at(i);
+ if (item->clipProducer() == clipId) {
+ AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->track(), item->startPos(), item->rect(), item->duration(), true, true);
+ m_commandStack->push(command);
+ //delete item;
+ }
+ }
+ }
+}
+
+void CustomTrackView::setCursorPos(int pos, bool seek)
{
m_cursorPos = pos;
m_cursorLine->setPos(pos, 0);
int frame = mapToScene(QPoint(pos, 0)).x() / m_scale;
- m_document->renderer()->seek(GenTime(frame, 25));
+ if (seek) m_document->renderer()->seek(GenTime(frame, m_document->fps()));
}
int CustomTrackView::cursorPos()
setDragMode(QGraphicsView::NoDrag);
if (m_dragItem == NULL) return;
//kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
- if (m_operationMode == MOVE) {
+ if (m_operationMode == MOVE && m_startPos.x() != m_dragItem->startPos()) {
// move clip
MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), false);
m_commandStack->push(command);
+ m_document->renderer()->mltMoveClip(m_tracksCount - m_startPos.y(), m_tracksCount - m_dragItem->track(), m_startPos.x(), m_dragItem->startPos());
}
else if (m_operationMode == RESIZESTART) {
// resize start
ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->startPos(), m_dragItem->track()), true, false);
+
+ m_document->renderer()->mltResizeClipStart(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->endPos(), m_document->fps()), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_startPos.x(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps()));
m_commandStack->push(command);
+ m_document->renderer()->doRefresh();
}
else if (m_operationMode == RESIZEEND) {
// resize end
ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->endPos(), m_dragItem->track()), false, false);
+
+ m_document->renderer()->mltResizeClipEnd(m_tracksCount - m_dragItem->track(), GenTime(m_dragItem->startPos(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()), GenTime(m_dragItem->cropStart(), m_document->fps()) + GenTime(m_dragItem->endPos(), m_document->fps()) - GenTime(m_dragItem->startPos(), m_document->fps()));
m_commandStack->push(command);
+ m_document->renderer()->doRefresh();
}
m_operationMode = NONE;
m_dragItem = NULL;
}
-void CustomTrackView::deleteClip ( const QRectF &rect )
+void CustomTrackView::deleteClip (int track, int startpos, const QRectF &rect )
{
- ClipItem *item = (ClipItem *) scene()->itemAt(rect.x() + 1, rect.y() + 1);
+ ClipItem *item = getClipItemAt(startpos, track);
if (!item) {
kDebug()<<"---------------- ERROR, CANNOT find clip to move at: "<<rect.x();
return;
}
+ item->baseClip()->removeReference();
+ m_document->updateClip(item->baseClip()->getId());
delete item;
+ m_document->renderer()->mltRemoveClip(m_tracksCount - track, GenTime(startpos, m_document->fps()));
+ m_document->renderer()->doRefresh();
}
-void CustomTrackView::addClip ( QDomElement xml, int track, int startpos, const QRectF &rect, int duration )
+void CustomTrackView::addClip ( QDomElement xml, int clipId, int track, int startpos, const QRectF &rect, int duration )
{
QRect r(startpos * m_scale, 50 * track, duration * m_scale, 49);
- ClipItem *item = new ClipItem(xml, track, startpos, r, duration);
+ DocClipBase *baseclip = m_document->clipManager()->getClipById(clipId);
+ ClipItem *item = new ClipItem(baseclip, track, startpos, r, duration);
scene()->addItem(item);
+ baseclip->addReference();
+ m_document->updateClip(baseclip->getId());
+ m_document->renderer()->mltInsertClip(m_tracksCount - track, GenTime(startpos, m_document->fps()), xml);
+ m_document->renderer()->doRefresh();
+}
+
+ClipItem *CustomTrackView::getClipItemAt(int pos, int track)
+{
+ return (ClipItem *) scene()->itemAt(pos * m_scale, track * 50 + 25);
}
void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
{
- ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + 1) * m_scale, startPos.y() * 50 + 25);
+ ClipItem *item = getClipItemAt(startPos.x() + 1, startPos.y());
if (!item) {
kDebug()<<"---------------- ERROR, CANNOT find clip to move at: "<<startPos.x() * m_scale * FRAME_SIZE + 1<<", "<<startPos.y() * 50 + 25;
return;
}
kDebug()<<"---------------- Move CLIP FROM: "<<startPos.x()<<", END:"<<endPos.x();
item->moveTo(endPos.x(), m_scale, (endPos.y() - startPos.y()) * 50, endPos.y());
+ m_document->renderer()->mltMoveClip(m_tracksCount - startPos.y(), m_tracksCount - endPos.y(), startPos.x(), endPos.x());
}
void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
int offset;
if (resizeClipStart) offset = 1;
else offset = -1;
- ClipItem *item = (ClipItem *) scene()->itemAt((startPos.x() + offset) * m_scale, startPos.y() * 50 + 25);
+ ClipItem *item = getClipItemAt(startPos.x() + offset, startPos.y());
if (!item) {
kDebug()<<"---------------- ERROR, CANNOT find clip to resize at: "<<startPos;
return;
}
qreal diff = endPos.x() - startPos.x();
if (resizeClipStart) {
+ m_document->renderer()->mltResizeClipStart(m_tracksCount - item->track(), GenTime(item->endPos(), m_document->fps()), GenTime(endPos.x(), m_document->fps()), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()), GenTime(item->cropStart() + diff, m_document->fps()) + GenTime(item->endPos(), m_document->fps()) - GenTime(endPos.x(), m_document->fps()));
item->resizeStart(endPos.x(), m_scale);
}
else {
+ m_document->renderer()->mltResizeClipEnd(m_tracksCount - item->track(), GenTime(item->startPos(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()), GenTime(item->cropStart(), m_document->fps()) + GenTime(endPos.x(), m_document->fps()) - GenTime(item->startPos(), m_document->fps()));
item->resizeEnd(endPos.x(), m_scale);
}
+ m_document->renderer()->doRefresh();
}
double CustomTrackView::getSnapPointForPos(double pos)
void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )
{
QColor base = palette().button().color();
- painter->setPen(base);
+ //painter->setPen(base);
painter->setClipRect(rect);
painter->drawLine(0, 0, rect.width(), 0);
for (uint i = 0; i < m_tracksCount;i++)
{
- painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
- //painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i));
+ painter->drawLine(0, 50 * (i+1), width(), 50 * (i+1));
+ painter->drawText(QRectF(10, 50 * i, 100, 50 * i + 49), Qt::AlignLeft, i18n(" Track ") + QString::number(i + 1));
}
int lowerLimit = 50 * m_tracksCount;
if (height() > lowerLimit)