]> git.sesse.net Git - kdenlive/commitdiff
start implementing markers
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 21 May 2008 21:18:40 +0000 (21:18 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 21 May 2008 21:18:40 +0000 (21:18 +0000)
svn path=/branches/KDE4/; revision=2195

src/CMakeLists.txt
src/addmarkercommand.cpp [new file with mode: 0644]
src/addmarkercommand.h [new file with mode: 0644]
src/clipitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/kdenlivesettings.kcfg
src/kdenliveui.rc
src/mainwindow.cpp
src/mainwindow.h
src/widgets/configdisplay_ui.ui

index 67a74c307ccd07c322513d506f95794a48a991f3..56c9f4f23e86e805bde9a58d78c59bfba21a4496 100644 (file)
@@ -74,6 +74,7 @@ set(kdenlive_SRCS
   resizeclipcommand.cpp
   razorclipcommand.cpp
   addtimelineclipcommand.cpp
+  addmarkercommand.cpp
   kthumb.cpp
   clipmanager.cpp
   effectslist.cpp
diff --git a/src/addmarkercommand.cpp b/src/addmarkercommand.cpp
new file mode 100644 (file)
index 0000000..9055fcb
--- /dev/null
@@ -0,0 +1,40 @@
+/***************************************************************************
+                          addtransitioncommand.cpp  -  description
+                             -------------------
+    begin                : 2008
+    copyright            : (C) 2008 by Marco Gittler
+    email                : g.marco@freenet.de
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#include <KLocale>
+
+#include "addmarkercommand.h"
+#include "customtrackview.h"
+
+AddMarkerCommand::AddMarkerCommand(CustomTrackView *view, const QString &oldcomment, const QString &comment, const int id, const GenTime &pos, bool doIt) : m_view(view), m_oldcomment(oldcomment), m_comment(comment), m_id(id), m_pos(pos), m_doIt(doIt) {
+    if (m_comment.isEmpty()) setText(i18n("Delete marker"));
+    else setText(i18n("Add marker"));
+}
+
+
+// virtual
+void AddMarkerCommand::undo() {
+    m_view->addMarker(m_id, m_pos, m_oldcomment);
+}
+// virtual
+void AddMarkerCommand::redo() {
+    if (m_doIt) {
+        m_view->addMarker(m_id, m_pos, m_comment);
+    }
+    m_doIt = true;
+}
+
+#include "addmarkercommand.moc"
diff --git a/src/addmarkercommand.h b/src/addmarkercommand.h
new file mode 100644 (file)
index 0000000..0c839da
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+                          addmarkercommand.h  -  description
+                             -------------------
+    begin                : 2008
+    copyright            : (C) 2008 by Jean-Baptiste Mardelle
+    email                : jb@kdenlive.org
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef MARKERCOMMAND_H
+#define MARKERCOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+#include <QDomElement>
+#include <KDebug>
+
+#include "gentime.h"
+#include "definitions.h"
+class CustomTrackView;
+
+
+class AddMarkerCommand : public QUndoCommand {
+public:
+    AddMarkerCommand(CustomTrackView *view, const QString &oldcomment, const QString &comment, const int id, const GenTime &pos, bool doIt);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    QString m_oldcomment;
+    QString m_comment;
+    int m_id;
+    GenTime m_pos;
+    bool m_doIt;
+};
+
+#endif
+
index d6d5ee7dc9eb552c9121b0f184b62520a42e18c8..097139c7d4abc0b65d305a4c319aef5ea698f956 100644 (file)
@@ -210,7 +210,6 @@ void ClipItem::paint(QPainter *painter,
     //painter->setRenderHints(QPainter::Antialiasing);
 
     QPainterPath roundRectPathUpper = upperRectPart(br), roundRectPathLower = lowerRectPart(br);
-
     painter->setClipRect(option->exposedRect);
 
     // build path around clip
@@ -254,8 +253,40 @@ void ClipItem::paint(QPainter *painter,
             if (audioThumbCachePic.contains(startCache) && !audioThumbCachePic[startCache].isNull())
                 painter->drawPixmap((int)(roundRectPathUpper.united(roundRectPathLower).boundingRect().x() + startCache - cropLeft), (int)(path.boundingRect().y()), audioThumbCachePic[startCache]);
         }
+    }
 
+    // draw markers
+    QList < CommentedTime > markers = baseClip()->commentedSnapMarkers();
+    QList < CommentedTime >::Iterator it = markers.begin();
+    GenTime pos;
+    double framepos;
+    const int markerwidth = 4;
+    QBrush markerBrush;
+    markerBrush = QBrush(QColor(120, 120, 0, 100));
+    QPen pen = painter->pen();
+    pen.setColor(QColor(255, 255, 255, 200));
+    pen.setStyle(Qt::DotLine);
+    painter->setPen(pen);
+    for (; it != markers.end(); ++it) {
+        pos = (*it).time() - cropStart();
+        if (pos > GenTime()) {
+            if (pos > duration()) break;
+            framepos = scale * pos.frames(m_fps);
+            QLineF l(br.x() + framepos, br.y() + 5, br.x() + framepos, br.y() + br.height() - 5);
+            painter->drawLine(l);
+            if (KdenliveSettings::showmarkers()) {
+                const QRectF txtBounding = painter->boundingRect(br.x() + framepos + 1, br.y() + 5, br.width() - framepos - 2, br.height() - 10, Qt::AlignLeft | Qt::AlignTop, " " + (*it).comment() + " ");
+                QPainterPath path;
+                path.addRoundedRect(txtBounding, 3, 3);
+                painter->fillPath(path, markerBrush);
+                painter->drawText(txtBounding, Qt::AlignCenter, (*it).comment());
+            }
+            //painter->fillRect(QRect(br.x() + framepos, br.y(), 10, br.height()), QBrush(QColor(0, 0, 0, 150)));
+        }
     }
+    pen.setColor(Qt::black);
+    pen.setStyle(Qt::SolidLine);
+
 
     /*
       // draw start / end fades
@@ -289,8 +320,7 @@ void ClipItem::paint(QPainter *painter,
           }
       }
       */
-    QPen pen = painter->pen();
-    pen.setColor(Qt::white);
+
     //pen.setStyle(Qt::DashDotDotLine); //Qt::DotLine);
 
     // Draw effects names
@@ -502,7 +532,6 @@ void ClipItem::setFadeOut(int pos, double scale) {
 
 }
 
-
 // virtual
 void ClipItem::mousePressEvent(QGraphicsSceneMouseEvent * event) {
     /*m_resizeMode = operationMode(event->pos());
index 0ef3105e2ff20151322f539f0918071d07e13389..9667f028239b53f47ca45e2119b5ac71cb549213 100644 (file)
@@ -23,6 +23,7 @@
 #include <QDomDocument>
 #include <QScrollBar>
 #include <QApplication>
+#include <QInputDialog>
 
 #include <KDebug>
 #include <KLocale>
@@ -43,6 +44,7 @@
 #include "moveeffectcommand.h"
 #include "addtransitioncommand.h"
 #include "edittransitioncommand.h"
+#include "addmarkercommand.h"
 #include "razorclipcommand.h"
 #include "kdenlivesettings.h"
 #include "transition.h"
@@ -523,7 +525,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) {
 }
 
 void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) {
-    QList<QGraphicsItem *> itemList;
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
     if (track == -1)
         itemList = items();
     else {
@@ -533,7 +535,7 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
     }
     kDebug() << "// REQUESTING EFFECT ON CLIP: " << pos.frames(25) << ", TRK: " << track;
     for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == AVWIDGET && itemList.at(i)->isSelected()) {
+        if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = (ClipItem *)itemList.at(i);
             // the kdenlive_ix int is used to identify an effect in mlt's playlist, should
             // not be changed
@@ -882,35 +884,33 @@ void CustomTrackView::deleteClip(ItemInfo info) {
 }
 
 void CustomTrackView::deleteSelectedClips() {
-    QList<QGraphicsItem *> itemList = items();
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
     for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->isSelected()) {
-            if (itemList.at(i)->type() == AVWIDGET) {
-                ClipItem *item = (ClipItem *) itemList.at(i);
-                ItemInfo info;
-                info.startPos = item->startPos();
-                info.endPos = item->endPos();
-                info.track = item->track();
-                AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true);
-                m_commandStack->push(command);
-            } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
-                Transition *item = (Transition *) itemList.at(i);
-                ItemInfo info;
-                info.startPos = item->startPos();
-                info.endPos = item->endPos();
-                info.track = item->track();
-                AddTransitionCommand *command = new AddTransitionCommand(this, info, item->transitionEndTrack(), QDomElement(), true, true);
-                m_commandStack->push(command);
-            }
+        if (itemList.at(i)->type() == AVWIDGET) {
+            ClipItem *item = (ClipItem *) itemList.at(i);
+            ItemInfo info;
+            info.startPos = item->startPos();
+            info.endPos = item->endPos();
+            info.track = item->track();
+            AddTimelineClipCommand *command = new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), info, true, true);
+            m_commandStack->push(command);
+        } else if (itemList.at(i)->type() == TRANSITIONWIDGET) {
+            Transition *item = (Transition *) itemList.at(i);
+            ItemInfo info;
+            info.startPos = item->startPos();
+            info.endPos = item->endPos();
+            info.track = item->track();
+            AddTransitionCommand *command = new AddTransitionCommand(this, info, item->transitionEndTrack(), QDomElement(), true, true);
+            m_commandStack->push(command);
         }
     }
 }
 
 void CustomTrackView::cutSelectedClips() {
-    QList<QGraphicsItem *> itemList = items();
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
     GenTime currentPos = GenTime(m_cursorPos, m_document->fps());
     for (int i = 0; i < itemList.count(); i++) {
-        if (itemList.at(i)->type() == AVWIDGET && itemList.at(i)->isSelected()) {
+        if (itemList.at(i)->type() == AVWIDGET) {
             ClipItem *item = (ClipItem *) itemList.at(i);
             ItemInfo info;
             info.startPos = item->startPos();
@@ -1109,6 +1109,31 @@ void CustomTrackView::slotSeekToNextSnap() {
     setCursorPos((int) res.frames(m_document->fps()));
 }
 
+void CustomTrackView::slotAddClipMarker() {
+    QList<QGraphicsItem *> itemList = scene()->selectedItems();
+    if (itemList.count() != 1) {
+        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();
+    QString comment = QInputDialog::getText(this, i18n("Add Marker"), i18n("Enter text for marker on clip <b>%1</b>", clip->clipName()), QLineEdit::Normal, i18n("marker"));
+    if (comment.isEmpty()) return;
+    AddMarkerCommand *command = new AddMarkerCommand(this, QString(), 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);
+       else base->deleteSnapMarker(pos);
+}
+
 void CustomTrackView::setTool(PROJECTTOOL tool) {
     m_tool = tool;
 }
index 2322faa89397c0fb62d658049e29ac9c3c08fecb..3f7e3bec1c82f7ba80201c0bb4e0d57c5503f922 100644 (file)
@@ -52,6 +52,8 @@ public:
     void resizeClip(const ItemInfo start, const ItemInfo end);
     void addClip(QDomElement xml, int clipId, ItemInfo info);
     void deleteClip(ItemInfo info);
+    void slotAddClipMarker();
+    void addMarker(const int id, const GenTime &pos, const QString comment);
     void setScale(double scaleFactor);
     void deleteClip(int clipId);
     void slotAddEffect(QDomElement effect, GenTime pos, int track);
index eb59244d9f5baf2795e1be054cae76b3cd4a62af..8395eb870bbd32ad7bc710c2347242c9ea10c2ff 100644 (file)
       <default>true</default>
     </entry>
 
+    <entry name="showmarkers" type="Bool">
+      <label>Display clip markers comments in timeline.</label>
+      <default>false</default>
+    </entry>
+
     <entry name="normaliseaudiothumbs" type="Bool">
       <label>Normalise audio before creating thumbnails.</label>
       <default>true</default>
index 629ca1a621d6d4bd563ec534d1829887d0ec2f4a..30047475f0420be7808efb50238db913902da0de 100644 (file)
@@ -24,6 +24,7 @@
     <Menu name="timeline" ><text>Timeline</text>
       <Action name="cut_timeline_clip" />
       <Action name="delete_timeline_clip" />
+      <Action name="add_clip_marker" />
       <Menu name="video_effects_menu" ><text>Add Video Effect</text>
       </Menu>
       <Menu name="audio_effects_menu" ><text>Add Audio Effect</text>
index 6c6338e4994ee75cac7384e91fd0f2794e3597ce..a45f030195eff2cfc78686b01986d93fef02ba4f 100644 (file)
@@ -218,6 +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);
     m_timelineContextClipMenu->addMenu(videoEffectsMenu);
     m_timelineContextClipMenu->addMenu(audioEffectsMenu);
     m_timelineContextClipMenu->addMenu(customEffectsMenu);
@@ -412,6 +414,11 @@ void MainWindow::setupActions() {
     m_buttonAudioThumbs->setCheckable(true);
     m_buttonAudioThumbs->setChecked(KdenliveSettings::videothumbnails());
     connect(m_buttonAudioThumbs, SIGNAL(triggered()), this, SLOT(slotSwitchAudioThumbs()));
+
+    m_buttonShowMarkers = toolbar->addAction(KIcon("audio-mpeg"), i18n("Show markers comments"));
+    m_buttonShowMarkers->setCheckable(true);
+    m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
+    connect(m_buttonShowMarkers, SIGNAL(triggered()), this, SLOT(slotSwitchMarkersComments()));
     layout->addWidget(toolbar);
 
     statusBar()->insertPermanentWidget(0, statusProgressBar, 1);
@@ -487,6 +494,10 @@ void MainWindow::setupActions() {
     actionCollection()->addAction("cut_timeline_clip", cutTimelineClip);
     connect(cutTimelineClip, SIGNAL(triggered(bool)), this, SLOT(slotCutTimelineClip()));
 
+    KAction* addClipMarker = new KAction(KIcon("edit-delete"), i18n("Add Marker to Clip"), this);
+    actionCollection()->addAction("add_clip_marker", addClipMarker);
+    connect(addClipMarker, SIGNAL(triggered(bool)), this, SLOT(slotAddClipMarker()));
+
     KStandardAction::quit(this, SLOT(queryQuit()),
                           actionCollection());
 
@@ -904,6 +915,18 @@ void MainWindow::slotSwitchAudioThumbs() {
     m_buttonAudioThumbs->setChecked(KdenliveSettings::audiothumbnails());
 }
 
+void MainWindow::slotSwitchMarkersComments() {
+    KdenliveSettings::setShowmarkers(!KdenliveSettings::showmarkers());
+    TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
+    if (currentTab) {
+        currentTab->refresh();
+    }
+    m_buttonShowMarkers->setChecked(KdenliveSettings::showmarkers());
+}
+
+
+
+
 void MainWindow::slotDeleteTimelineClip() {
     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
     if (currentTab) {
@@ -911,6 +934,13 @@ void MainWindow::slotDeleteTimelineClip() {
     }
 }
 
+void MainWindow::slotAddClipMarker() {
+    TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
+    if (currentTab) {
+        currentTab->projectView()->slotAddClipMarker();
+    }
+}
+
 void MainWindow::slotCutTimelineClip() {
     TrackView *currentTab = (TrackView *) m_timelineArea->currentWidget();
     if (currentTab) {
index 616d300c12bc639ca0f3780190103f06872a27cf..ee58677a7e2770f0d441f5fd881cc7a13d325f26 100644 (file)
@@ -120,6 +120,7 @@ private:
 
     QAction *m_buttonAudioThumbs;
     QAction *m_buttonVideoThumbs;
+    QAction *m_buttonShowMarkers;
     QAction *m_buttonFitZoom;
     QAction *m_buttonSelectTool;
     QAction *m_buttonRazorTool;
@@ -158,6 +159,7 @@ private slots:
     void slotGotProgressInfo(KUrl url, int progress);
     void slotSwitchVideoThumbs();
     void slotSwitchAudioThumbs();
+    void slotSwitchMarkersComments();
     void slotRenderProject();
     void slotDoRender(const QString &dest, const QString &render, const QStringList &avformat_args, bool zoneOnly, bool playAfter);
     void slotFullScreen();
@@ -167,6 +169,7 @@ private slots:
     void slotFitZoom();
     void slotRemoveTab();
     void slotDeleteTimelineClip();
+    void slotAddClipMarker();
     void slotCutTimelineClip();
     void slotAddVideoEffect(QAction *result);
     void slotAddAudioEffect(QAction *result);
index d88cb360b21c4cbce4aee96878e4563980b2d90a..8adc83a0dedaeb2a86378af10f5dbcc22cae4ebc 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>335</width>
-    <height>188</height>
+    <width>353</width>
+    <height>255</height>
    </rect>
   </property>
   <layout class="QGridLayout" name="gridLayout_2" >
      </layout>
     </widget>
    </item>
-   <item row="1" column="0" colspan="3" >
-    <widget class="QCheckBox" name="kcfg_autoscroll" >
-     <property name="text" >
-      <string>Autoscroll while playing</string>
-     </property>
-    </widget>
-   </item>
-   <item row="2" column="0" >
+   <item row="4" column="0" >
     <widget class="QLabel" name="label" >
      <property name="text" >
       <string>Track height</string>
      </property>
     </widget>
    </item>
-   <item row="2" column="1" >
+   <item row="4" column="1" >
     <widget class="QSpinBox" name="kcfg_trackheight" />
    </item>
-   <item row="2" column="2" >
+   <item row="4" column="2" >
     <spacer name="horizontalSpacer_2" >
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
@@ -83,7 +76,7 @@
      </property>
     </spacer>
    </item>
-   <item row="3" column="1" >
+   <item row="5" column="1" >
     <spacer name="verticalSpacer" >
      <property name="orientation" >
       <enum>Qt::Vertical</enum>
      </property>
     </spacer>
    </item>
+   <item row="2" column="0" colspan="2" >
+    <widget class="QCheckBox" name="kcfg_showmarkers" >
+     <property name="text" >
+      <string>Display clip markers comments</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0" colspan="3" >
+    <widget class="QCheckBox" name="kcfg_autoscroll" >
+     <property name="text" >
+      <string>Autoscroll while playing</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <resources/>