]> git.sesse.net Git - kdenlive/commitdiff
improvements to move and resize clips
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Jan 2008 20:31:33 +0000 (20:31 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 21 Jan 2008 20:31:33 +0000 (20:31 +0000)
svn path=/branches/KDE4/; revision=1808

src/CMakeLists.txt
src/clipitem.cpp
src/customtrackview.cpp
src/customtrackview.h
src/resizeclipcommand.cpp [new file with mode: 0644]
src/resizeclipcommand.h [new file with mode: 0644]

index 91dc981fd6c975274072287f0cde19252b5b7911..a88311b12b7c43dc1a2f338b5bb7b83f494a348d 100644 (file)
@@ -54,6 +54,7 @@ set(kdenlive_SRCS
   clipitem.cpp
   labelitem.cpp
   moveclipcommand.cpp
+  resizeclipcommand.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 028aa787e3c2483a99ff2e2e28c162914a9d4bcb..ed4c46136aeb177cd585e8c722066e66f845ccd2 100644 (file)
@@ -130,10 +130,18 @@ int ClipItem::operationMode(QPointF pos)
     double originalX = rect().x();
     if (m_resizeMode == 1) {
       setRect(moveX, rect().y(), originalX + rect().width() - moveX, rect().height());
+      QList <QGraphicsItem *> childrenList = children();
+      for (int i = 0; i < childrenList.size(); ++i) {
+       childrenList.at(i)->moveBy((moveX - originalX) / 2 , 0);
+      }
       return;
     }
     if (m_resizeMode == 2) {
       setRect(originalX, rect().y(), moveX - originalX, rect().height());
+      QList <QGraphicsItem *> childrenList = children();
+      for (int i = 0; i < childrenList.size(); ++i) {
+       childrenList.at(i)->moveBy(-(moveX - originalX) / 2 , 0);
+      }
       return;
     }
     int moveTrack = (int) event->scenePos().y() / 50;
index e76cbc239a55bcd5f6b9a30f15dce4fcf585bad3..eae91025d69dc3a73b9c6fb6c0e36c9bfc29ac0a 100644 (file)
@@ -30,6 +30,7 @@
 #include "clipitem.h"
 #include "definitions.h"
 #include "moveclipcommand.h"
+#include "resizeclipcommand.h"
 
 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)
@@ -94,11 +95,14 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
     setDragMode(QGraphicsView::RubberBandDrag);
   else {
     QGraphicsItem * item = itemAt(event->pos());
-    if (item) {
+    if (item && item->type() != 70000) item = item->parentItem();
+    if (item && item->type() == 70000) {
       m_dragItem = (ClipItem *) item;
-      m_operationMode = m_dragItem->operationMode(item->mapFromScene(event->pos()));
+      m_operationMode = m_dragItem->operationMode(item->mapFromScene(mapToScene(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());
+      else m_startPos = QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y());
+
+     kDebug()<<"//////// ITEM CLICKED: "<<m_startPos;
       /*while (item->parentItem()) 
        item = item->parentItem();
 
@@ -112,6 +116,8 @@ void CustomTrackView::mousePressEvent ( QMouseEvent * event )
          ((ClipItem *) item )->setResizeMode(2);
     */}
     else {
+      kDebug()<<"//////// NO ITEM FOUND ON CLICK";
+      m_dragItem = NULL;
       setCursor(Qt::ArrowCursor);
       emit cursorMoved((int) mapToScene(event->x(), 0).x());
     }
@@ -210,10 +216,23 @@ 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);
-  
+  if (m_dragItem == NULL) return;
+  //kDebug()<<"/// MOVING CLIP: "<<m_startPos<<", END: "<<QPoint(m_dragItem->rect().x(),m_dragItem->rect().y());
+  if (m_operationMode == 0) {
+    // move clip
+    MoveClipCommand *command = new MoveClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()), false);
+    m_commandStack->push(command);
+  }
+  else if (m_operationMode == 1) {
+    // resize start
+    ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x(), m_dragItem->rect().y()), true, false);
+    m_commandStack->push(command);
+  }
+  else if (m_operationMode == 2) {
+    // resize end
+    ResizeClipCommand *command = new ResizeClipCommand(this, m_startPos, QPointF(m_dragItem->rect().x() + m_dragItem->rect().width(), m_dragItem->rect().y()), false, false);
+    m_commandStack->push(command);
+  }
 }
 
 void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos )
@@ -230,6 +249,34 @@ void CustomTrackView::moveClip ( const QPointF &startPos, const QPointF &endPos
   }
 }
 
+void CustomTrackView::resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart )
+{
+  int offset;
+  if (resizeClipStart) offset = 1;
+  else offset = -1;
+  ClipItem *item = (ClipItem *) scene()->itemAt(startPos.x() + offset, startPos.y() + 1);
+  if (!item) {
+    kDebug()<<"----------------  ERROR, CANNOT find clip to resize at: "<<startPos;
+    return;
+  }
+  qreal diff = endPos.x() - startPos.x();
+  if (resizeClipStart) {
+    item->setRect(QRectF(endPos.x(), endPos.y(), item->rect().width() - diff, item->rect().height()));
+    QList <QGraphicsItem *> childrenList = item->children();
+    for (int i = 0; i < childrenList.size(); ++i) {
+      childrenList.at(i)->moveBy(diff / 2 , endPos.y() - startPos.y());
+    }
+  }
+  else {
+    //kdDebug()<<"///////  RESIZE CLIP END: "<<item->rect().x()<<", "<<item->rect().width()<<", "<<startPos<<", "<<endPos;
+    item->setRect(QRectF(item->rect().x(), item->rect().y(), endPos.x() - item->rect().x(), item->rect().height()));
+    QList <QGraphicsItem *> childrenList = item->children();
+    for (int i = 0; i < childrenList.size(); ++i) {
+      childrenList.at(i)->moveBy(-diff/2, endPos.y() - startPos.y());
+    }
+  }
+}
+
 
 void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )  
 {
index d29a3260b40720fd52b573562f0458537a5c6c33..5d8c90ba04b8f18b1fc21659f01aa5fb298b9ab3 100644 (file)
@@ -41,6 +41,7 @@ class CustomTrackView : public QGraphicsView
     int cursorPos();
     void initView();
     void moveClip ( const QPointF &startPos, const QPointF &endPos );
+    void resizeClip ( const QPointF &startPos, const QPointF &endPos, bool resizeClipStart );
 
   protected:
     virtual void drawBackground ( QPainter * painter, const QRectF & rect );
diff --git a/src/resizeclipcommand.cpp b/src/resizeclipcommand.cpp
new file mode 100644 (file)
index 0000000..52634cc
--- /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 "resizeclipcommand.h"
+
+ResizeClipCommand::ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt)
+         : m_view(view), m_startPos(startPos), m_endPos(endPos), m_resizeClipStart(resizeClipStart), m_doIt(doIt) {
+           setText(i18n("Resize clip"));
+        }
+
+
+// virtual 
+void ResizeClipCommand::undo()
+{
+// kDebug()<<"----  undoing action";
+  m_doIt = true;
+  if (m_doIt) m_view->resizeClip(m_endPos, m_startPos, m_resizeClipStart);
+}
+// virtual 
+void ResizeClipCommand::redo()
+{
+kDebug()<<"----  redoing action";
+  if (m_doIt) m_view->resizeClip(m_startPos, m_endPos, m_resizeClipStart);
+  m_doIt = true;
+}
+
+#include "resizeclipcommand.moc"
diff --git a/src/resizeclipcommand.h b/src/resizeclipcommand.h
new file mode 100644 (file)
index 0000000..8b575f0
--- /dev/null
@@ -0,0 +1,49 @@
+/***************************************************************************
+ *   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 RESIZECLIPCOMMAND_H
+#define RESIZECLIPCOMMAND_H
+
+#include <QUndoCommand>
+#include <QGraphicsView>
+#include <QPointF>
+
+#include <KDebug>
+
+#include "projectlist.h"
+#include "customtrackview.h"
+
+class ResizeClipCommand : public QUndoCommand
+ {
+ public:
+     ResizeClipCommand(CustomTrackView *view, const QPointF startPos, const QPointF endPos, bool resizeClipStart, bool doIt);
+    virtual void undo();
+    virtual void redo();
+
+ private:
+     CustomTrackView *m_view;
+     QPointF m_startPos;
+     QPointF m_endPos;
+     bool m_resizeClipStart;
+     bool m_doIt;
+ };
+
+#endif
+