From 80d3b4578590bd1de02fb0c82e16246519768b75 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Wed, 28 May 2008 21:05:14 +0000 Subject: [PATCH] edit and delete markers svn path=/branches/KDE4/; revision=2203 --- src/clipitem.cpp | 17 ++++++++++++++- src/clipitem.h | 2 ++ src/customtrackview.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ src/customtrackview.h | 2 ++ src/docclipbase.cpp | 14 +++++-------- src/kdenliveui.rc | 8 +++++-- src/mainwindow.cpp | 26 +++++++++++++++++++++-- src/mainwindow.h | 2 ++ 8 files changed, 103 insertions(+), 14 deletions(-) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 76eb5e08..9cf74099 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -188,7 +188,6 @@ void ClipItem::paint(QPainter *painter, QWidget *widget) { painter->setOpacity(m_opacity); QBrush paintColor = brush(); - if (isSelected()) paintColor = QBrush(QColor(79, 93, 121)); QRectF br = rect(); double scale = br.width() / m_cropDuration.frames(m_fps); @@ -431,6 +430,22 @@ OPERATIONTYPE ClipItem::operationMode(QPointF pos, double scale) { return MOVE; } +QList ClipItem::snapMarkers() { + QList < GenTime > snaps; + QList < GenTime > markers = baseClip()->snapMarkers(); + GenTime pos; + double framepos; + + for (int i = 0; i < markers.size(); i++) { + pos = markers.at(i) - cropStart(); + if (pos > GenTime()) { + if (pos > duration()) break; + else snaps.append(pos + startPos()); + } + } + return snaps; +} + void ClipItem::slotPrepareAudioThumb(double pixelForOneFrame, QPainterPath path, int startpixel, int endpixel) { int channels = 2; diff --git a/src/clipitem.h b/src/clipitem.h index 7703bfdf..9bfc0548 100644 --- a/src/clipitem.h +++ b/src/clipitem.h @@ -77,6 +77,8 @@ public: void resetThumbs(); /** update clip properties from base clip */ void refreshClip(); + /** Returns a list of times for this clip's markers */ + QList snapMarkers(); protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event); diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 3997b9f2..6bbd2806 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -1062,6 +1062,12 @@ void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) { GenTime end = item->endPos(); m_snapPoints.append(start); m_snapPoints.append(end); + QList < GenTime > markers = item->snapMarkers(); + for (int i = 0; i < markers.size(); ++i) { + GenTime t = markers.at(i); + m_snapPoints.append(t); + if (t > offset) m_snapPoints.append(t - offset); + } if (offset != GenTime()) { if (start > offset) m_snapPoints.append(start - offset); if (end > offset) m_snapPoints.append(end - offset); @@ -1129,6 +1135,46 @@ void CustomTrackView::slotAddClipMarker() { m_commandStack->push(command); } +void CustomTrackView::slotDeleteClipMarker() { + QList itemList = scene()->selectedItems(); + if (itemList.count() != 1) { + kDebug() << "// CANNOT DELETE 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(); + QString comment = clip->baseClip()->markerComment(position); + if (comment.isEmpty()) return; + AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position, true); + m_commandStack->push(command); +} + +void CustomTrackView::slotEditClipMarker() { + QList itemList = scene()->selectedItems(); + if (itemList.count() != 1) { + kDebug() << "// CANNOT DELETE 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(); + QString oldcomment = clip->baseClip()->markerComment(position); + if (oldcomment.isEmpty()) return; + QString comment = QInputDialog::getText(this, i18n("Add Marker"), i18n("Enter text for marker on clip %1", clip->clipName()), QLineEdit::Normal, oldcomment); + if (comment.isEmpty()) return; + AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, comment, id, position, true); + m_commandStack->push(command); +} + 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); diff --git a/src/customtrackview.h b/src/customtrackview.h index 3f7e3bec..0ef15022 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -53,6 +53,8 @@ public: void addClip(QDomElement xml, int clipId, ItemInfo info); void deleteClip(ItemInfo info); void slotAddClipMarker(); + void slotEditClipMarker(); + void slotDeleteClipMarker(); void addMarker(const int id, const GenTime &pos, const QString comment); void setScale(double scaleFactor); void deleteClip(int clipId); diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index d0ac4616..f2d87227 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -195,8 +195,7 @@ createClip(KdenliveDoc *doc, const QDomElement & element) { node.normalize(); if (element.tagName() != "kdenliveclip") { kWarning() << - "DocClipBase::createClip() element has unknown tagName : " << - element.tagName() << endl; + "DocClipBase::createClip() element has unknown tagName : " << element.tagName(); return 0; } @@ -221,8 +220,7 @@ createClip(KdenliveDoc *doc, const QDomElement & element) { n = n.nextSibling(); } if (clip == 0) { - kWarning() << "DocClipBase::createClip() unable to create clip" << - endl; + kWarning() << "DocClipBase::createClip() unable to create clip"; } else { // setup DocClipBase specifics of the clip. QMap props; @@ -282,9 +280,8 @@ void DocClipBase::addSnapMarker(const GenTime & time, QString comment) { } if ((it != m_snapMarkers.end()) && ((*it).time() == time)) { - kError() << - "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo" - << endl; + (*it).setComment(comment); + //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"; } else { CommentedTime t(time, comment); m_snapMarkers.insert(it, t); @@ -301,8 +298,7 @@ void DocClipBase::editSnapMarker(const GenTime & time, QString comment) { if (it != m_snapMarkers.end()) { (*it).setComment(comment); } else { - kError() << - "trying to edit Snap Marker that does not already exists" << endl; + kError() << "trying to edit Snap Marker that does not already exists"; } } diff --git a/src/kdenliveui.rc b/src/kdenliveui.rc index 30047475..302bbc6f 100644 --- a/src/kdenliveui.rc +++ b/src/kdenliveui.rc @@ -1,6 +1,6 @@ - + Extra Toolbar @@ -24,7 +24,11 @@ Timeline - + Markers + + + + Add Video Effect Add Audio Effect diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 78a99d85..e629649e 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -218,8 +218,8 @@ MainWindow::MainWindow(QWidget *parent) action = actionCollection()->action("delete_timeline_clip"); m_timelineContextClipMenu->addAction(action); - action = actionCollection()->action("add_clip_marker"); - m_timelineContextClipMenu->addAction(action); + QMenu *markersMenu = (QMenu*)(factory()->container("marker_menu", this)); + m_timelineContextClipMenu->addMenu(markersMenu); m_timelineContextClipMenu->addMenu(videoEffectsMenu); m_timelineContextClipMenu->addMenu(audioEffectsMenu); m_timelineContextClipMenu->addMenu(customEffectsMenu); @@ -498,6 +498,14 @@ void MainWindow::setupActions() { actionCollection()->addAction("add_clip_marker", addClipMarker); connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker())); + KAction* deleteClipMarker = new KAction(KIcon("edit-delete"), i18n("Delete Marker from Clip"), this); + actionCollection()->addAction("delete_clip_marker", deleteClipMarker); + connect(deleteClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotDeleteClipMarker())); + + KAction* editClipMarker = new KAction(KIcon("edit-delete"), i18n("Edit Marker"), this); + actionCollection()->addAction("edit_clip_marker", editClipMarker); + connect(editClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotEditClipMarker())); + KStandardAction::quit(this, SLOT(queryQuit()), actionCollection()); @@ -951,6 +959,20 @@ void MainWindow::slotAddClipMarker() { } } +void MainWindow::slotDeleteClipMarker() { + TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); + if (currentTab) { + currentTab->projectView()->slotDeleteClipMarker(); + } +} + +void MainWindow::slotEditClipMarker() { + TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); + if (currentTab) { + currentTab->projectView()->slotEditClipMarker(); + } +} + void MainWindow::slotCutTimelineClip() { TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget(); if (currentTab) { diff --git a/src/mainwindow.h b/src/mainwindow.h index ac499b23..1e0af42f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -171,6 +171,8 @@ private slots: void slotRemoveTab(); void slotDeleteTimelineClip(); void slotAddClipMarker(); + void slotDeleteClipMarker(); + void slotEditClipMarker(); void slotCutTimelineClip(); void slotAddVideoEffect(QAction *result); void slotAddAudioEffect(QAction *result); -- 2.39.5