+void CustomTrackView::slotSeekToPreviousSnap() {
+ updateSnapPoints(NULL);
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ GenTime res = GenTime();
+ for (int i = 0; i < m_snapPoints.size(); ++i) {
+ if (m_snapPoints.at(i) >= pos) {
+ if (i == 0) i = 1;
+ res = m_snapPoints.at(i - 1);
+ break;
+ }
+ }
+ setCursorPos((int) res.frames(m_document->fps()));
+}
+
+void CustomTrackView::slotSeekToNextSnap() {
+ updateSnapPoints(NULL);
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ GenTime res = GenTime(m_projectDuration, m_document->fps());
+ for (int i = 0; i < m_snapPoints.size(); ++i) {
+ if (m_snapPoints.at(i) > pos) {
+ res = m_snapPoints.at(i);
+ break;
+ }
+ }
+ setCursorPos((int) res.frames(m_document->fps()));
+}
+
+void CustomTrackView::slotAddClipMarker() {
+ QList<QGraphicsItem *> itemList = scene()->selectedItems();
+ if (itemList.count() != 1) {
+ emit displayMessage(i18n("Cannot add marker if more than one clip is selected"), ErrorMessage);
+ kDebug() << "// CANNOT ADD MARKER IF MORE TAN ONE CLIP IS SELECTED....";
+ return;
+ }
+ AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
+ if (item->type() != AVWIDGET) return;
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ if (item->startPos() > pos || item->endPos() < pos) return;
+ ClipItem *clip = (ClipItem *) item;
+ int id = clip->baseClip()->getId();
+ GenTime position = pos - item->startPos() + item->cropStart();
+ CommentedTime marker(position, i18n("Marker"));
+ MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
+ if (d.exec() == QDialog::Accepted) {
+ slotAddClipMarker(id, d.newMarker().time(), d.newMarker().comment());
+ }
+}
+
+void CustomTrackView::slotAddClipMarker(int id, GenTime t, QString c) {
+ QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
+ AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, true);
+ m_commandStack->push(command);
+}
+
+void CustomTrackView::slotDeleteClipMarker() {
+ QList<QGraphicsItem *> itemList = scene()->selectedItems();
+ if (itemList.count() != 1) {
+ emit displayMessage(i18n("Cannot delete marker if more than one clip is selected"), ErrorMessage);
+ kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
+ return;
+ }
+ AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
+ if (item->type() != AVWIDGET) {
+ emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
+ return;
+ }
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ if (item->startPos() > pos || item->endPos() < pos) {
+ emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
+ return;
+ }
+ ClipItem *clip = (ClipItem *) item;
+ int id = clip->baseClip()->getId();
+ GenTime position = pos - item->startPos() + item->cropStart();
+ QString comment = clip->baseClip()->markerComment(position);
+ if (comment.isEmpty()) {
+ emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
+ return;
+ }
+ AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true);
+ m_commandStack->push(command);
+}
+
+void CustomTrackView::slotEditClipMarker() {
+ QList<QGraphicsItem *> itemList = scene()->selectedItems();
+ if (itemList.count() != 1) {
+ emit displayMessage(i18n("Cannot edit marker if more than one clip is selected"), ErrorMessage);
+ kDebug() << "// CANNOT DELETE MARKER IF MORE TAN ONE CLIP IS SELECTED....";
+ return;
+ }
+ AbstractClipItem *item = (AbstractClipItem *)itemList.at(0);
+ if (item->type() != AVWIDGET) {
+ emit displayMessage(i18n("No clip at cursor time"), ErrorMessage);
+ return;
+ }
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ if (item->startPos() > pos || item->endPos() < pos) {
+ emit displayMessage(i18n("No selected clip at cursor time"), ErrorMessage);
+ return;
+ }
+ ClipItem *clip = (ClipItem *) item;
+ int id = clip->baseClip()->getId();
+ GenTime position = pos - item->startPos() + item->cropStart();
+ QString oldcomment = clip->baseClip()->markerComment(position);
+ if (oldcomment.isEmpty()) {
+ emit displayMessage(i18n("No marker found at cursor time"), ErrorMessage);
+ return;
+ }
+
+ CommentedTime marker(position, oldcomment);
+ MarkerDialog d(clip->baseClip(), marker, m_document->timecode(), this);
+ if (d.exec() == QDialog::Accepted) {
+ if (d.newMarker().time() == position) {
+ // marker position was not changed, only text
+ AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, d.newMarker().comment(), id, position, true);
+ m_commandStack->push(command);
+ } else {
+ // marker text and position were changed, remove previous marker and add new one
+ AddMarkerCommand *command1 = new AddMarkerCommand(this, oldcomment, QString(), id, position, true);
+ AddMarkerCommand *command2 = new AddMarkerCommand(this, QString(), d.newMarker().comment(), id, d.newMarker().time(), true);
+ m_commandStack->push(command1);
+ m_commandStack->push(command2);
+ }
+ }
+}
+
+void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString comment) {
+ DocClipBase *base = m_document->clipManager()->getClipById(id);
+ if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
+ else base->deleteSnapMarker(pos);
+ m_document->setModified(true);
+ viewport()->update();
+}
+
+
+
+void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) {
+ if (oldPos > GenTime() && pos > GenTime()) {
+ // move guide
+ for (int i = 0; i < m_guides.count(); i++) {
+ kDebug() << "// LOOKING FOR GUIDE (" << i << "): " << m_guides.at(i)->position().frames(25) << ", LOOK: " << oldPos.frames(25) << "x" << pos.frames(25);
+ if (m_guides.at(i)->position() == oldPos) {
+ Guide *item = m_guides.at(i);
+ item->update(pos, comment);
+ item->updatePosition(m_scale);
+ break;
+ }
+ }
+ } else if (pos > GenTime()) addGuide(pos, comment);
+ else {
+ // remove guide
+ bool found = false;
+ for (int i = 0; i < m_guides.count(); i++) {
+ if (m_guides.at(i)->position() == oldPos) {
+ Guide *item = m_guides.takeAt(i);
+ delete item;
+ found = true;
+ break;
+ }
+ }
+ if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
+ }
+}
+
+bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
+ for (int i = 0; i < m_guides.count(); i++) {
+ if (m_guides.at(i)->position() == pos) {
+ emit displayMessage(i18n("A guide already exists at that position"), ErrorMessage);
+ return false;
+ }
+ }
+ Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
+ scene()->addItem(g);
+ m_guides.append(g);
+ return true;
+}
+
+void CustomTrackView::slotAddGuide() {
+ if (addGuide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"))) {
+ EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), GenTime(m_cursorPos, m_document->fps()), i18n("guide"), false);
+ m_commandStack->push(command);
+ }
+}
+
+void CustomTrackView::slotDeleteGuide() {
+ GenTime pos = GenTime(m_cursorPos, m_document->fps());
+ bool found = false;
+ for (int i = 0; i < m_guides.count(); i++) {
+ if (m_guides.at(i)->position() == pos) {
+ EditGuideCommand *command = new EditGuideCommand(this, m_guides.at(i)->position(), m_guides.at(i)->label(), GenTime(), QString(), true);
+ m_commandStack->push(command);
+ found = true;
+ break;
+ }
+ }
+ if (!found) emit displayMessage(i18n("No guide at cursor time"), ErrorMessage);
+}
+
+void CustomTrackView::setTool(PROJECTTOOL tool) {
+ m_tool = tool;
+}