clipitem.cpp
labelitem.cpp
moveclipcommand.cpp
+ resizeclipcommand.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
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;
#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)
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();
((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());
}
{
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 )
}
}
+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 )
{
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 );
--- /dev/null
+/***************************************************************************
+ * 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"
--- /dev/null
+/***************************************************************************
+ * 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
+