customtrackview.cpp
clipitem.cpp
labelitem.cpp
+ moveclipcommand.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
//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);
QWidget *widget);
virtual int type () const;
void moveTo(double x, double offset);
+ int operationMode(QPointF pos);
protected:
virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
#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);
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();
{
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();
#define CUSTOMTRACKVIEW_H
#include <QGraphicsView>
+#include <KUndoStack>
#include "clipitem.h"
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 );
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 );
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);
//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);
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);
--- /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 "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"
--- /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 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
+
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));