From f6e50cc80312002481d8e5cc27cf15d082c59cfd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Mon, 21 Jan 2008 20:31:33 +0000 Subject: [PATCH] improvements to move and resize clips svn path=/branches/KDE4/; revision=1808 --- src/CMakeLists.txt | 1 + src/clipitem.cpp | 8 +++++ src/customtrackview.cpp | 61 ++++++++++++++++++++++++++++++++++----- src/customtrackview.h | 1 + src/resizeclipcommand.cpp | 43 +++++++++++++++++++++++++++ src/resizeclipcommand.h | 49 +++++++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 src/resizeclipcommand.cpp create mode 100644 src/resizeclipcommand.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91dc981f..a88311b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 ) diff --git a/src/clipitem.cpp b/src/clipitem.cpp index 028aa787..ed4c4613 100644 --- a/src/clipitem.cpp +++ b/src/clipitem.cpp @@ -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 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 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; diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index e76cbc23..eae91025 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -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: "<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: "<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: "<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: "<setRect(QRectF(endPos.x(), endPos.y(), item->rect().width() - diff, item->rect().height())); + QList 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: "<rect().x()<<", "<rect().width()<<", "<setRect(QRectF(item->rect().x(), item->rect().y(), endPos.x() - item->rect().x(), item->rect().height())); + QList 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 ) { diff --git a/src/customtrackview.h b/src/customtrackview.h index d29a3260..5d8c90ba 100644 --- a/src/customtrackview.h +++ b/src/customtrackview.h @@ -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 index 00000000..52634cc3 --- /dev/null +++ b/src/resizeclipcommand.cpp @@ -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 index 00000000..8b575f0f --- /dev/null +++ b/src/resizeclipcommand.h @@ -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 +#include +#include + +#include + +#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 + -- 2.39.2