]> git.sesse.net Git - kdenlive/commitdiff
undo/redo clip move
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Jan 2008 19:23:15 +0000 (19:23 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Jan 2008 19:23:15 +0000 (19:23 +0000)
svn path=/branches/KDE4/; revision=1807

src/CMakeLists.txt
src/clipitem.cpp
src/clipitem.h
src/customtrackview.cpp
src/customtrackview.h
src/labelitem.cpp
src/mainwindow.cpp
src/moveclipcommand.cpp [new file with mode: 0644]
src/moveclipcommand.h [new file with mode: 0644]
src/trackview.cpp

index 47cde5dab000c9e7b5627b4003544b5a09581079..91dc981fd6c975274072287f0cde19252b5b7911 100644 (file)
@@ -53,6 +53,7 @@ set(kdenlive_SRCS
   customtrackview.cpp
   clipitem.cpp
   labelitem.cpp
+  moveclipcommand.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 8cc20aea973e91f9e06378b9df6421dbd8313e9d..028aa787e3c2483a99ff2e2e28c162914a9d4bcb 100644 (file)
@@ -58,15 +58,21 @@ int ClipItem::type () const
      //painter->drawRoundRect(-10, -10, 20, 20);
  }
 
+
+int ClipItem::operationMode(QPointF pos)
+{
+    if (abs(pos.x() - rect().x()) < 6)
+      return 1;
+    else if (abs(pos.x() - (rect().x() + rect().width())) < 6)
+      return 2;
+    return 0;
+}
+
 // virtual
  void ClipItem::mousePressEvent ( QGraphicsSceneMouseEvent * event ) 
  {
-    if (abs(event->pos().x() - rect().x()) < 6)
-      m_resizeMode = 1;
-    else if (abs(event->pos().x() - (rect().x() + rect().width())) < 6)
-      m_resizeMode = 2;
-    else  {
-      m_resizeMode = 0;
+    m_resizeMode = operationMode(event->pos());
+    if (m_resizeMode == 0) {
       m_grabPoint = event->pos().x() - rect().x();
     }
     QGraphicsRectItem::mousePressEvent(event);
index d80e096ba1872aa991561534521485959a6a0588..f8f1ab39340e2bd5fee0b912cf2b35ba8abb6199 100644 (file)
@@ -36,6 +36,7 @@ class ClipItem : public QGraphicsRectItem
                            QWidget *widget);
     virtual int type () const;
     void moveTo(double x, double offset);
+    int operationMode(QPointF pos);
 
   protected:
     virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
index ea585553de3fb4105f8b1f46d2f5715173526db3..e76cbc239a55bcd5f6b9a30f15dce4fcf585bad3 100644 (file)
 #include "customtrackview.h"
 #include "clipitem.h"
 #include "definitions.h"
+#include "moveclipcommand.h"
 
-CustomTrackView::CustomTrackView(QGraphicsScene * scene, QWidget *parent)
-    : QGraphicsView(scene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL)
+CustomTrackView::CustomTrackView(KUndoStack *commandStack, QGraphicsScene * scene, QWidget *parent)
+    : QGraphicsView(scene, parent), m_commandStack(commandStack), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL), m_cursorLine(NULL), m_operationMode(0), m_startPos(QPointF()), m_dragItem(NULL)
 {
   setMouseTracking(true);
   setAcceptDrops(true);
@@ -94,6 +95,10 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
   else {
     QGraphicsItem * item = itemAt(event->pos());
     if (item) {
+      m_dragItem = (ClipItem *) item;
+      m_operationMode = m_dragItem->operationMode(item->mapFromScene(event->pos()));
+      if (m_operationMode != 2) m_startPos = QPointF(m_dragItem->rect().x(), m_dragItem->rect().y());
+      else m_startPos = QPointF(rect().x() + rect().width(), rect().y());
       /*while (item->parentItem()) 
        item = item->parentItem();
 
@@ -205,8 +210,27 @@ void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
 {
   QGraphicsView::mouseReleaseEvent(event);
   setDragMode(QGraphicsView::NoDrag);
+  kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
+  MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(),m_dragItem->rect().y()), false);
+  m_commandStack->push(command);
+  
 }
 
+void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
+{
+  ClipItem *item = (ClipItem *) scene()->itemAt(startPos.x() + 1, startPos.y() + 1);
+  if (!item) {
+    kDebug()<<"----------------  ERROR, CANNOT find clip to move at: "<<startPos;
+    return;
+  }
+  item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width(), item->rect().height()));
+  QList <QGraphicsItem *> childrenList = item->children();
+  for (int i = 0; i < childrenList.size(); ++i) {
+    childrenList.at(i)->moveBy(endPos.x() - startPos.x() , endPos.y() - startPos.y());
+  }
+}
+
+
 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )  
 {
   //kDebug()<<"/////  DRAWING BG: "<<rect.x()<<", width: "<<rect.width();
index d92b1a67174e065a2147445ac1a0d3ad330977a5..d29a3260b40720fd52b573562f0458537a5c6c33 100644 (file)
@@ -22,6 +22,7 @@
 #define CUSTOMTRACKVIEW_H
 
 #include <QGraphicsView>
+#include <KUndoStack>
 
 #include "clipitem.h"
 
@@ -30,7 +31,7 @@ class CustomTrackView : public QGraphicsView
   Q_OBJECT
   
   public:
-    CustomTrackView(QGraphicsScene * scene, QWidget *parent=0);
+    CustomTrackView(KUndoStack *commandStack, QGraphicsScene * scene, QWidget *parent=0);
     virtual void mousePressEvent ( QMouseEvent * event );
     virtual void mouseReleaseEvent ( QMouseEvent * event );
     virtual void mouseMoveEvent ( QMouseEvent * event );
@@ -39,6 +40,7 @@ class CustomTrackView : public QGraphicsView
     void setCursorPos(int pos);
     int cursorPos();
     void initView();
+    void moveClip ( const QPointF &startPos, const QPointF &endPos );
 
   protected:
     virtual void drawBackground ( QPainter * painter, const QRectF & rect );
@@ -57,6 +59,10 @@ class CustomTrackView : public QGraphicsView
     ClipItem *m_dropItem;
     void addItem(QString producer, QPoint pos);
     QGraphicsLineItem *m_cursorLine;
+    QPointF m_startPos;
+    int m_operationMode;
+    ClipItem *m_dragItem;
+    KUndoStack *m_commandStack;
 
   signals:
     void cursorMoved(int);
index ccde0a67a8bea64dacf5cb5e08f58bea10bfd21b..0346c3b8e9fcf42dc53b67add65f45be4ff835ce 100644 (file)
@@ -47,13 +47,13 @@ int LabelItem::type () const
     //painter->setClipRect( option->exposedRect );
     QRectF rep = option->exposedRect;
     QGraphicsRectItem *parent = (QGraphicsRectItem *) parentItem();
-    QRectF par = parent->boundingRect();
+    QRectF par = mapFromScene(parent->rect()).boundingRect();
     //kDebug()<<"REPAINT RECT: "<<par.width();
     //kDebug()<<"REPAINT RECT: "<<rep.x()<<", "<<rep.y()<<", "<<rep.width()<<", "<<rep.height();
     //kDebug()<<"PARENT RECT: "<<par.x()<<", "<<par.y()<<", "<<par.width()<<", "<<par.height();
     QRectF parrect = parent->rect();
     //QRectF transRect = deviceTransform(view->viewportTransform()).inverted().mapRect(parrect);
-    //painter->setClipRect( par);
+    painter->setClipRect( par);
     //painter->fillRect(rect(), Qt::red);
     QPainterPath path;
     path.addRoundRect(boundingRect(), 40);
index 72d6994b9d6c9961f1e4d22049852f559206d45e..0a46691f6408c4e512c6432a604dae4469879458 100644 (file)
@@ -101,7 +101,7 @@ MainWindow::MainWindow(QWidget *parent)
 
   overviewDock = new QDockWidget(i18n("Project Overview"), this);
   overviewDock->setObjectName("project_overview");
-  m_overView = new CustomTrackView(NULL, this);
+  m_overView = new CustomTrackView(NULL, NULL, this);
   overviewDock->setWidget(m_overView);
   addDockWidget(Qt::TopDockWidgetArea, overviewDock);
 
diff --git a/src/moveclipcommand.cpp b/src/moveclipcommand.cpp
new file mode 100644 (file)
index 0000000..e0f0432
--- /dev/null
@@ -0,0 +1,43 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include "moveclipcommand.h"
+
+MoveClipCommand::MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt)
+         : m_view(view), m_startPos(startPos), m_endPos(endPos), m_doIt(doIt) {
+           setText(i18n("Move clip"));
+        }
+
+
+// virtual 
+void MoveClipCommand::undo()
+{
+// kDebug()<<"----  undoing action";
+  m_doIt = true;
+  if (m_doIt) m_view->moveClip(m_endPos, m_startPos);
+}
+// virtual 
+void MoveClipCommand::redo()
+{
+kDebug()<<"----  redoing action";
+  if (m_doIt) m_view->moveClip(m_startPos, m_endPos);
+  m_doIt = true;
+}
+
+#include "moveclipcommand.moc"
diff --git a/src/moveclipcommand.h b/src/moveclipcommand.h
new file mode 100644 (file)
index 0000000..023660d
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   Copyright (C) 2007 by Jean-Baptiste Mardelle (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.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+
+#ifndef MOVECLIPCOMMAND_H
+#define MOVECLIPCOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+
+#include <KDebug>
+
+#include "projectlist.h"
+#include "customtrackview.h"
+
+class MoveClipCommand : public QUndoCommand
+ {
+ public:
+     MoveClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool doIt);
+    virtual void undo();
+    virtual void redo();
+
+ private:
+     CustomTrackView *m_view;
+     QPointF m_startPos;
+     QPointF m_endPos;
+     bool m_doIt;
+ };
+
+#endif
+
index 8e2d70054d303a6445e81c743af7e3088d3fc1fa..411fd8d02a3ebebcd79d9820c43ed0d591164b12 100644 (file)
@@ -44,7 +44,7 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
   view->ruler_frame->setLayout(layout);
 
   m_scene = new QGraphicsScene();
-  m_trackview = new CustomTrackView(m_scene, this);
+  m_trackview = new CustomTrackView(m_doc->commandStack(), m_scene, this);
   m_trackview->scale(FRAME_SIZE, 1);
   m_trackview->setAlignment(Qt::AlignLeft | Qt::AlignTop);
   //m_scene->addRect(QRectF(0, 0, 100, 100), QPen(), QBrush(Qt::red));