]> git.sesse.net Git - kdenlive/commitdiff
Guides can now be moved, and deleted, all actions can be undone
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 10 Jun 2008 20:51:22 +0000 (20:51 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Tue, 10 Jun 2008 20:51:22 +0000 (20:51 +0000)
svn path=/branches/KDE4/; revision=2243

src/CMakeLists.txt
src/clipitem.cpp
src/customruler.cpp
src/customtrackview.cpp
src/customtrackview.h
src/definitions.h
src/editguidecommand.cpp [new file with mode: 0644]
src/editguidecommand.h [new file with mode: 0644]
src/guide.cpp
src/guide.h

index b1836765d3679ac1f7471365833ed8380822ca1a..2fb8ff715c8498f4c3b13127ce3e6b41a8e7e4c4 100644 (file)
@@ -112,6 +112,7 @@ set(kdenlive_SRCS
   slideshowclip.cpp
   markerdialog.cpp
   guide.cpp
+  editguidecommand.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 9a5018516f5de5df128d508dbe541a72edd4fc6b..7cbda2bcb2b06707b79e7a10181b896ea6785f8b 100644 (file)
@@ -48,7 +48,6 @@ ClipItem::ClipItem(DocClipBase *clip, ItemInfo info, GenTime cropStart, double s
     m_producer = clip->getId();
     m_clipType = clip->clipType();
     m_cropStart = cropStart;
-
     m_maxDuration = clip->maxDuration();
     setAcceptDrops(true);
     audioThumbReady = clip->audioThumbCreated();
index f25d648fe7282934b152468bca939e906bcdd3d0..60e05fa15b32ab4521e4bd4108e147a02df31cc7 100644 (file)
@@ -89,6 +89,8 @@ CustomRuler::CustomRuler(Timecode tc, CustomTrackView *parent)
     m_contextMenu = new QMenu(this);
     QAction *addGuide = m_contextMenu->addAction(KIcon("document-new"), i18n("Add Guide"));
     connect(addGuide, SIGNAL(triggered()), m_view, SLOT(slotAddGuide()));
+    QAction *delGuide = m_contextMenu->addAction(KIcon("document-new"), i18n("Delete Guide"));
+    connect(delGuide, SIGNAL(triggered()), m_view, SLOT(slotDeleteGuide()));
 }
 
 // virtual
index fe6fa3fc1d9f61c84cd7acb3da5daa4fc9e8c3a9..8655f009ca6d2a14e8bea21f5dc3f0224e5fd411 100644 (file)
@@ -38,6 +38,7 @@
 #include "moveclipcommand.h"
 #include "movetransitioncommand.h"
 #include "resizeclipcommand.h"
+#include "editguidecommand.h"
 #include "addtimelineclipcommand.h"
 #include "addeffectcommand.h"
 #include "editeffectcommand.h"
@@ -65,7 +66,7 @@
 // const int duration = animate ? 1500 : 1;
 
 CustomTrackView::CustomTrackView(KdenliveDoc *doc, QGraphicsScene * projectscene, QWidget *parent)
-        : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL) {
+        : QGraphicsView(projectscene, parent), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(NONE), m_dragItem(NULL), m_visualTip(NULL), m_moveOpMode(NONE), m_animation(NULL), m_projectDuration(0), m_scale(1.0), m_clickPoint(QPoint()), m_document(doc), m_autoScroll(KdenliveSettings::autoscroll()), m_tracksHeight(KdenliveSettings::trackheight()), m_tool(SELECTTOOL), m_dragGuide(NULL) {
     if (doc) m_commandStack = doc->commandStack();
     else m_commandStack == NULL;
     setMouseTracking(true);
@@ -128,7 +129,9 @@ void CustomTrackView::checkTrackHeight() {
     m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), m_tracksHeight * m_tracksList.count());
 
     for (int i = 0; i < m_guides.count(); i++) {
-        m_guides.at(i)->updatePosition(m_scale, m_tracksHeight * m_tracksList.count());
+        QLineF l = m_guides.at(i)->line();
+        l.setP2(QPointF(l.x2(), m_tracksHeight * m_tracksList.count()));
+        m_guides.at(i)->setLine(l);
     }
 
     setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_tracksList.count());
@@ -197,6 +200,13 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 ((ClipItem*) m_dragItem)->setFadeOut((int)(m_dragItem->endPos().frames(m_document->fps()) - pos), m_scale);
             }
 
+            if (m_animation) delete m_animation;
+            m_animation = NULL;
+            if (m_visualTip) delete m_visualTip;
+            m_visualTip = NULL;
+            QGraphicsView::mouseMoveEvent(event);
+            return;
+        } else if (m_operationMode == MOVEGUIDE) {
             if (m_animation) delete m_animation;
             m_animation = NULL;
             if (m_visualTip) delete m_visualTip;
@@ -205,23 +215,28 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
             return;
         }
 
-        QList<QGraphicsItem *> itemList = items(event->pos());
-        QGraphicsRectItem *item = NULL;
-        for (int i = 0; i < itemList.count(); i++) {
-            if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
-                item = (QGraphicsRectItem*) itemList.at(i);
-                break;
-            }
-        }
         if (m_tool == RAZORTOOL) {
             setCursor(m_razorCursor);
             QGraphicsView::mouseMoveEvent(event);
             return;
         }
 
+        QList<QGraphicsItem *> itemList = items(event->pos());
+        QGraphicsRectItem *item = NULL;
+        OPERATIONTYPE opMode = NONE;
+
+        if (itemList.count() == 1 && itemList.at(0)->type() == GUIDEITEM) {
+            opMode = MOVEGUIDE;
+        } else for (int i = 0; i < itemList.count(); i++) {
+                if (itemList.at(i)->type() == AVWIDGET || itemList.at(i)->type() == TRANSITIONWIDGET) {
+                    item = (QGraphicsRectItem*) itemList.at(i);
+                    break;
+                }
+            }
+
         if (item && event->buttons() == Qt::NoButton) {
             AbstractClipItem *clip = (AbstractClipItem*) item;
-            OPERATIONTYPE opMode = opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
+            opMode = clip->operationMode(mapToScene(event->pos()), m_scale);
             double size = 8;
 
             if (opMode == m_moveOpMode) {
@@ -237,6 +252,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 }
             }
             m_moveOpMode = opMode;
+
             if (opMode == MOVE) {
                 setCursor(Qt::OpenHandCursor);
             } else if (opMode == RESIZESTART) {
@@ -372,6 +388,9 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) {
                 }
                 setCursor(Qt::PointingHandCursor);
             }
+        } else if (opMode == MOVEGUIDE) {
+            m_moveOpMode = opMode;
+            setCursor(Qt::SplitHCursor);
         } else {
             m_moveOpMode = NONE;
             if (event->buttons() != Qt::NoButton && event->modifiers() == Qt::NoModifier) {
@@ -411,71 +430,83 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) {
         bool collision = false;
         m_dragItem = NULL;
         QList<QGraphicsItem *> collisionList = items(event->pos());
-        for (int i = 0; i < collisionList.size(); ++i) {
-            QGraphicsItem *item = collisionList.at(i);
-            if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
-                if (m_tool == RAZORTOOL) {
-                    if (item->type() == TRANSITIONWIDGET) return;
-                    AbstractClipItem *clip = (AbstractClipItem *) item;
-                    ItemInfo info;
-                    info.startPos = clip->startPos();
-                    info.endPos = clip->endPos();
-                    info.track = clip->track();
-                    RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
-                    m_commandStack->push(command);
-                    m_document->setModified(true);
-                    return;
-                }
-                // select item
-                if (!item->isSelected()) {
-                    QList<QGraphicsItem *> itemList = items();
-                    for (int i = 0; i < itemList.count(); i++) {
-                        itemList.at(i)->setSelected(false);
-                        itemList.at(i)->update();
+        if (collisionList.count() == 1 && collisionList.at(0)->type() == GUIDEITEM) {
+            // a guide item was pressed
+            collisionList.at(0)->setFlag(QGraphicsItem::ItemIsMovable, true);
+            m_dragItem = NULL;
+            m_dragGuide = (Guide *) collisionList.at(0);
+            collision = true;
+            m_operationMode = MOVEGUIDE;
+            // deselect all clips so that only the guide will move
+            QList<QGraphicsItem *> clips = scene()->selectedItems();
+            for (int i = 0; i < clips.count(); ++i)
+                clips.at(i)->setSelected(false);
+            updateSnapPoints(NULL);
+            QGraphicsView::mousePressEvent(event);
+        } else for (int i = 0; i < collisionList.count(); ++i) {
+                QGraphicsItem *item = collisionList.at(i);
+                if (item->type() == AVWIDGET || item->type() == TRANSITIONWIDGET) {
+                    if (m_tool == RAZORTOOL) {
+                        if (item->type() == TRANSITIONWIDGET) return;
+                        AbstractClipItem *clip = (AbstractClipItem *) item;
+                        ItemInfo info;
+                        info.startPos = clip->startPos();
+                        info.endPos = clip->endPos();
+                        info.track = clip->track();
+                        RazorClipCommand* command = new RazorClipCommand(this, info, GenTime((int)(mapToScene(event->pos()).x() / m_scale), m_document->fps()), true);
+                        m_commandStack->push(command);
+                        m_document->setModified(true);
+                        return;
+                    }
+                    // select item
+                    if (!item->isSelected()) {
+                        QList<QGraphicsItem *> itemList = items();
+                        for (int i = 0; i < itemList.count(); i++) {
+                            itemList.at(i)->setSelected(false);
+                            itemList.at(i)->update();
+                        }
+                        item->setSelected(true);
+                        item->update();
                     }
-                    item->setSelected(true);
-                    item->update();
-                }
 
-                m_dragItem = (AbstractClipItem *) item;
-
-                m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
-                m_dragItemInfo.startPos = m_dragItem->startPos();
-                m_dragItemInfo.endPos = m_dragItem->endPos();
-                m_dragItemInfo.track = m_dragItem->track();
-
-                m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
-                if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
-                if (m_operationMode == TRANSITIONSTART) {
-                    ItemInfo info;
-                    info.startPos = m_dragItem->startPos();
-                    info.track = m_dragItem->track();
-                    int transitiontrack = getPreviousVideoTrack(info.track);
-                    ClipItem *transitionClip = NULL;
-                    if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
-                    if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
-                        info.endPos = transitionClip->endPos();
-                    } else info.endPos = info.startPos + GenTime(2.5);
-
-                    slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
-                }
-                if (m_operationMode == TRANSITIONEND) {
-                    ItemInfo info;
-                    info.endPos = m_dragItem->endPos();
-                    info.track = m_dragItem->track();
-                    int transitiontrack = getPreviousVideoTrack(info.track);
-                    ClipItem *transitionClip = NULL;
-                    if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
-                    if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
-                        info.startPos = transitionClip->startPos();
-                    } else info.startPos = info.endPos - GenTime(2.5);
-                    slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+                    m_dragItem = (AbstractClipItem *) item;
+
+                    m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps()) * m_scale), (int)(event->pos().y() - m_dragItem->rect().top()));
+                    m_dragItemInfo.startPos = m_dragItem->startPos();
+                    m_dragItemInfo.endPos = m_dragItem->endPos();
+                    m_dragItemInfo.track = m_dragItem->track();
+
+                    m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(event->pos())), m_scale);
+                    if (m_operationMode == MOVE) setCursor(Qt::ClosedHandCursor);
+                    else if (m_operationMode == TRANSITIONSTART) {
+                        ItemInfo info;
+                        info.startPos = m_dragItem->startPos();
+                        info.track = m_dragItem->track();
+                        int transitiontrack = getPreviousVideoTrack(info.track);
+                        ClipItem *transitionClip = NULL;
+                        if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.startPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
+                        if (transitionClip && transitionClip->endPos() < m_dragItem->endPos()) {
+                            info.endPos = transitionClip->endPos();
+                        } else info.endPos = info.startPos + GenTime(2.5);
+
+                        slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+                    } else if (m_operationMode == TRANSITIONEND) {
+                        ItemInfo info;
+                        info.endPos = m_dragItem->endPos();
+                        info.track = m_dragItem->track();
+                        int transitiontrack = getPreviousVideoTrack(info.track);
+                        ClipItem *transitionClip = NULL;
+                        if (transitiontrack != 0) transitionClip = getClipItemAt((int) info.endPos.frames(m_document->fps()), m_tracksList.count() - transitiontrack);
+                        if (transitionClip && transitionClip->startPos() > m_dragItem->startPos()) {
+                            info.startPos = transitionClip->startPos();
+                        } else info.startPos = info.endPos - GenTime(2.5);
+                        slotAddTransition((ClipItem *) m_dragItem, info, transitiontrack);
+                    }
+                    updateSnapPoints(m_dragItem);
+                    collision = true;
+                    break;
                 }
-                updateSnapPoints(m_dragItem);
-                collision = true;
-                break;
             }
-        }
         emit clipItemSelected((m_dragItem && m_dragItem->type() == AVWIDGET) ? (ClipItem*) m_dragItem : NULL);
 
         if (!collision) {
@@ -858,6 +889,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
     }
     QGraphicsView::mouseReleaseEvent(event);
     setDragMode(QGraphicsView::NoDrag);
+    if (m_operationMode == MOVEGUIDE) {
+        setCursor(Qt::ArrowCursor);
+        m_operationMode = NONE;
+        m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, false);
+        EditGuideCommand *command = new EditGuideCommand(this, m_dragGuide->position(), m_dragGuide->label(), GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()), m_dragGuide->label(), false);
+        m_commandStack->push(command);
+        m_dragGuide->update(GenTime(m_dragGuide->pos().x() / m_scale, m_document->fps()));
+        m_dragGuide = NULL;
+        m_dragItem = NULL;
+        return;
+    }
     if (m_dragItem == NULL) {
         emit transitionItemSelected(NULL);
         return;
@@ -964,6 +1006,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) {
         }
     }
 
+
     emit transitionItemSelected((m_dragItem && m_dragItem->type() == TRANSITIONWIDGET) ? (Transition*) m_dragItem : NULL);
     m_document->setModified(true);
     m_operationMode = NONE;
@@ -1218,15 +1261,15 @@ void CustomTrackView::updateSnapPoints(AbstractClipItem *selected) {
         }
     }
 
-       // add cursor position
+    // add cursor position
     GenTime pos = GenTime(m_cursorPos, m_document->fps());
     m_snapPoints.append(pos);
     if (offset != GenTime()) m_snapPoints.append(pos - offset);
 
-       // add guides
+    // add guides
     for (int i = 0; i < m_guides.count(); i++) {
-               m_snapPoints.append(m_guides.at(i)->position());
-               if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
+        m_snapPoints.append(m_guides.at(i)->position());
+        if (offset != GenTime()) m_snapPoints.append(m_guides.at(i)->position() - offset);
     }
 
     qSort(m_snapPoints);
@@ -1347,12 +1390,58 @@ void CustomTrackView::addMarker(const int id, const GenTime &pos, const QString
     viewport()->update();
 }
 
-void CustomTrackView::slotAddGuide() {
-    Guide *g = new Guide(GenTime(m_cursorPos, m_document->fps()), i18n("guide"), m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
+
+
+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
+        for (int i = 0; i < m_guides.count(); i++) {
+            if (m_guides.at(i)->position() == oldPos) {
+                Guide *item = m_guides.takeAt(i);
+                delete item;
+                break;
+            }
+        }
+
+    }
+}
+
+void CustomTrackView::addGuide(const GenTime pos, const QString &comment) {
+    Guide *g = new Guide(this, pos, comment, m_scale, m_document->fps(), m_tracksHeight * m_tracksList.count());
     scene()->addItem(g);
     m_guides.append(g);
 }
 
+void CustomTrackView::slotAddGuide() {
+    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());
+       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);
+            break;
+        }
+       }
+}
+
 void CustomTrackView::setTool(PROJECTTOOL tool) {
     m_tool = tool;
 }
@@ -1372,7 +1461,7 @@ void CustomTrackView::setScale(double scaleFactor) {
     }
 
     for (int i = 0; i < m_guides.count(); i++) {
-        m_guides.at(i)->updatePosition(m_scale, m_tracksHeight * m_tracksList.count());
+        m_guides.at(i)->updatePosition(m_scale);
     }
 
     updateCursorPos();
index ff3fc4a3db5252961cb9e883678062564c9317e5..118765174bf3dfb635b067d5efa062b9db96c4ff 100644 (file)
@@ -81,6 +81,7 @@ public:
     void cutClip(ItemInfo info, GenTime cutTime, bool cut);
     void slotSeekToPreviousSnap();
     void slotSeekToNextSnap();
+    double getSnapPointForPos(double pos);
 
 public slots:
     void setCursorPos(int pos, bool seek = true);
@@ -100,6 +101,8 @@ public slots:
     void slotUpdateClip(int clipId);
     void slotAddClipMarker(int id, GenTime t, QString c);
     void slotAddGuide();
+       void slotDeleteGuide();
+    void editGuide(const GenTime oldPos, const GenTime pos, const QString &comment);
 
 protected:
     virtual void drawBackground(QPainter * painter, const QRectF & rect);
@@ -125,6 +128,7 @@ private:
     OPERATIONTYPE m_operationMode;
     OPERATIONTYPE m_moveOpMode;
     AbstractClipItem *m_dragItem;
+    Guide *m_dragGuide;
     KUndoStack *m_commandStack;
     QGraphicsItem *m_visualTip;
     QGraphicsItemAnimation *m_animation;
@@ -137,7 +141,6 @@ private:
     QList <GenTime> m_snapPoints;
     QList <Guide *> m_guides;
     void updateSnapPoints(AbstractClipItem *selected);
-    double getSnapPointForPos(double pos);
     ClipItem *getClipItemAt(int pos, int track);
     ClipItem *getClipItemAt(GenTime pos, int track);
     Transition *getTransitionItemAt(int pos, int track);
@@ -155,6 +158,7 @@ private:
     /** Get the index of the video track that is just below current track */
     int getPreviousVideoTrack(int track);
     void updateClipFade(ClipItem * item, bool updateFadeOut = false);
+    void addGuide(const GenTime pos, const QString &comment);
 
 signals:
     void cursorMoved(int, int);
index 5c848f124ec6c4593eb8c48214f6ee305e3672fe..6d5c955e3ad6bcefdd559db06f55fd12f016bc92 100644 (file)
@@ -26,7 +26,7 @@
 #define FRAME_SIZE 90
 #define MAXCLIPDURATION 15000
 
-enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN = 4, FADEOUT = 5, TRANSITIONSTART = 6, TRANSITIONEND = 7};
+enum OPERATIONTYPE { NONE = 0, MOVE = 1, RESIZESTART = 2, RESIZEEND = 3, FADEIN = 4, FADEOUT = 5, TRANSITIONSTART = 6, TRANSITIONEND = 7, MOVEGUIDE = 8};
 enum CLIPTYPE { UNKNOWN = 0, AUDIO = 1, VIDEO = 2, AV = 3, COLOR = 4, IMAGE = 5, TEXT = 6, SLIDESHOW = 7, VIRTUAL = 8, PLAYLIST = 9, FOLDER = 10};
 enum GRAPHICSRECTITEM { AVWIDGET = 70000 , LABELWIDGET , TRANSITIONWIDGET };
 
diff --git a/src/editguidecommand.cpp b/src/editguidecommand.cpp
new file mode 100644 (file)
index 0000000..946d616
--- /dev/null
@@ -0,0 +1,42 @@
+/***************************************************************************
+                          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 "editguidecommand.h"
+#include "customtrackview.h"
+
+EditGuideCommand::EditGuideCommand(CustomTrackView *view, const GenTime oldPos, const QString &oldcomment, const GenTime pos, const QString &comment, bool doIt) : m_view(view), m_oldPos(oldPos), m_oldcomment(oldcomment), m_pos(pos), m_comment(comment), m_doIt(doIt) {
+    if (m_oldcomment.isEmpty()) setText(i18n("Add guide"));
+    else if (m_oldPos == m_pos) setText(i18n("Edit guide"));
+    else setText(i18n("Move guide"));
+    kDebug() << "///  CREATE GUIDE COMMAND, TIMES: " << m_oldPos.frames(25) << "x" << m_pos.frames(25);
+}
+
+
+// virtual
+void EditGuideCommand::undo() {
+    m_view->editGuide(m_pos, m_oldPos, m_oldcomment);
+}
+// virtual
+void EditGuideCommand::redo() {
+    if (m_doIt) {
+        m_view->editGuide(m_oldPos, m_pos, m_comment);
+    }
+    m_doIt = true;
+}
+
+#include "editguidecommand.moc"
diff --git a/src/editguidecommand.h b/src/editguidecommand.h
new file mode 100644 (file)
index 0000000..742227f
--- /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 GUIDECOMMAND_H
+#define GUIDECOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+#include <QDomElement>
+#include <KDebug>
+
+#include "gentime.h"
+#include "definitions.h"
+class CustomTrackView;
+
+
+class EditGuideCommand : public QUndoCommand {
+public:
+    EditGuideCommand(CustomTrackView *view, const GenTime oldPos, const QString &oldcomment, const GenTime pos, const QString &comment, bool doIt);
+    virtual void undo();
+    virtual void redo();
+
+private:
+    CustomTrackView *m_view;
+    QString m_oldcomment;
+    QString m_comment;
+    GenTime m_oldPos;
+    GenTime m_pos;
+    bool m_doIt;
+};
+
+#endif
+
index a93905826407e5ead59c5b7cc64fa578d5df9556..1cf781e211e30cec6f73ec7f6a9284fc8fa3efd4 100644 (file)
 
 
 #include <QPen>
+#include <QBrush>
 
 #include <KDebug>
 
 #include "guide.h"
+#include "customtrackview.h"
 
-Guide::Guide(GenTime pos, QString label, double scale, double fps, double height)
-        : QGraphicsLineItem(), m_position(pos), m_label(label), m_fps(fps) {
-
-    setLine(m_position.frames(m_fps) * scale, 0, m_position.frames(m_fps) * scale, height);
-    setPen(QPen(QColor(0, 0, 200, 180)));
+Guide::Guide(CustomTrackView *view, GenTime pos, QString label, double scale, double fps, double height)
+        : QGraphicsLineItem(), m_view(view), m_position(pos), m_label(label), m_scale(scale), m_fps(fps) {
+    setFlags(QGraphicsItem::ItemIsMovable);
+    setToolTip(label);
+    setLine(0, 0, 0, height);
+    setPos(m_position.frames(m_fps) * scale, 0);
+    setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
     setZValue(999);
+    setAcceptsHoverEvents(true);
+}
+
+
+void Guide::updatePosition(double scale) {
+    setPos(m_position.frames(m_fps) * scale, 0);
+    m_scale = scale;
 }
 
+QString Guide::label() const {
+    return m_label;
+}
 
-void Guide::updatePosition(double scale, double height) {
-    setLine(m_position.frames(m_fps) * scale, 0, m_position.frames(m_fps) * scale, height);
+GenTime Guide::position() const {
+    return m_position;
 }
 
-GenTime Guide::position() {
-       return m_position;
+void Guide::update(const GenTime newPos, const QString &comment) {
+    m_position = newPos;
+    if (comment != QString()) {
+        m_label = comment;
+        setToolTip(m_label);
+    }
 }
 
+//virtual
+int Guide::type() const {
+    return GUIDEITEM;
+}
 
+//virtual
+void Guide::hoverEnterEvent(QGraphicsSceneHoverEvent *) {
+    setPen(QPen(QBrush(QColor(200, 0, 0, 180)), 2));
+}
+
+//virtual
+void Guide::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
+    setPen(QPen(QBrush(QColor(0, 0, 200, 180)), 2));
+}
+
+//virtual
+QVariant Guide::itemChange(GraphicsItemChange change, const QVariant &value) {
+    if (change == ItemPositionChange && scene()) {
+        // value is the new position.
+        QPointF newPos = value.toPointF();
+        newPos.setY(0);
+        const double offset = m_position.frames(m_fps) * m_scale;
+        newPos.setX(m_view->getSnapPointForPos(offset + newPos.x()) - offset);
+        return newPos;
+    }
+    return QGraphicsItem::itemChange(change, value);
+}
 
index 14f353f9e5e372cbc2db729c77851138ff498535..4d57d77a1446ffe417d8db8e3dc6a37a6254dcba 100644 (file)
 
 #include "gentime.h"
 
+#define GUIDEITEM 8000
+
+class CustomTrackView;
+
 class Guide : public QGraphicsLineItem {
 
 public:
-    Guide(GenTime pos, QString label, double scale, double fps, double height);
-    void updatePosition(double scale, double height);
-       GenTime position();
+    Guide(CustomTrackView *view, GenTime pos, QString label, double scale, double fps, double height);
+    void updatePosition(double scale);
+    GenTime position() const;
+    void update(const GenTime newPos, const QString &comment = QString());
+    QString label() const;
+    virtual int type() const;
+
+protected:
+    virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
+    virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
+    virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
 
 private:
     GenTime m_position;
     QString m_label;
+    double m_scale;
     double m_fps;
+    CustomTrackView *m_view;
 };
 
 #endif