trackpanelfunctionfactory.cpp
trackpanelfunction.cpp
trackpanelclipmovefunction.cpp
+ customtrackview.cpp
+ clipitem.cpp
+ labelitem.cpp
)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
: m_list(list), m_names(names), m_xml(xml), m_id(id), m_url(url), m_group(group), m_doIt(doIt) {
if (doIt) setText(i18n("Add clip"));
else setText(i18n("Delete clip"));
- }
+ }
// virtual
--- /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 <QPainter>
+#include <QStyleOptionGraphicsItem>
+
+#include <KDebug>
+
+
+#include "clipitem.h"
+
+ClipItem::ClipItem(int clipType, QString name, int producer, const QRectF & rect)
+ : QGraphicsRectItem(rect), m_resizeMode(0), m_grabPoint(0), m_producer(producer)
+{
+ setToolTip(name);
+ //setCursor(Qt::SizeHorCursor);
+ setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemClipsChildrenToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+ //producer = "sjis isjisjsi sij ssao sa sao ";
+ m_label = new LabelItem( name, this);
+ QRectF textRect = m_label->boundingRect();
+ m_textWidth = textRect.width();
+ m_label->setPos(rect.x() + rect.width()/2 - m_textWidth/2, rect.y() + rect.height() / 2 - textRect.height()/2);
+}
+
+int ClipItem::type () const
+{
+ return 70000;
+}
+
+// virtual
+ void ClipItem::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+ {
+ painter->setClipRect( option->exposedRect );
+ painter->fillRect(rect(), Qt::red);
+ //kDebug()<<"ITEM REPAINTÂ RECT: "<<boundingRect().width();
+ //painter->drawText(rect(), Qt::AlignCenter, m_name);
+ painter->drawRect(rect());
+ //painter->drawRoundRect(-10, -10, 20, 20);
+ }
+
+// 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_grabPoint = event->pos().x() - rect().x();
+ }
+ QGraphicsRectItem::mousePressEvent(event);
+ }
+
+// virtual
+ void ClipItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
+ {
+ m_resizeMode = 0;
+ QGraphicsRectItem::mouseReleaseEvent(event);
+ }
+
+ void ClipItem::moveTo(double x, double offset)
+ {
+ double origX = rect().x();
+ double origY = rect().y();
+ setRect(x, origY + offset, rect().width(), rect().height());
+
+ QList <QGraphicsItem *> collisionList = collidingItems();
+ for (int i = 0; i < collisionList.size(); ++i) {
+ QGraphicsItem *item = collisionList.at(i);
+ if (item->type() == 70000)
+ {
+ if (offset == 0)
+ {
+ QRectF other = ((QGraphicsRectItem *)item)->rect();
+ QPointF pos = mapFromItem(item, other.x()+other.width(), 0);
+ //mapToItem(collisionList.at(i), collisionList.at(i)->boundingRect()).boundingRect();
+ if (x < origX) {
+ kDebug()<<"COLLISION, MOVING TO------";
+ origX = other.x() + other.width();
+ }
+ else if (x > origX) {
+ kDebug()<<"COLLISION, MOVING TO+++";
+ origX = other.x() - rect().width();
+ }
+ }
+ setRect(origX, origY, rect().width(), rect().height());
+ offset = 0;
+ origX = rect().x();
+ break;
+ }
+ }
+
+ QList <QGraphicsItem *> childrenList = children();
+ for (int i = 0; i < childrenList.size(); ++i) {
+ childrenList.at(i)->moveBy(rect().x() - origX , offset);
+ }
+ }
+
+// virtual
+ void ClipItem::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
+ {
+ double moveX = event->scenePos().x();
+ double originalX = rect().x();
+ if (m_resizeMode == 1) {
+ setRect(moveX, rect().y(), originalX + rect().width() - moveX, rect().height());
+ return;
+ }
+ if (m_resizeMode == 2) {
+ setRect(originalX, rect().y(), moveX - originalX, rect().height());
+ return;
+ }
+ int moveTrack = (int) event->scenePos().y() / 50;
+ int currentTrack = (int) rect().y() / 50;
+ int offset = moveTrack - currentTrack;
+ if (offset != 0) offset = 50 * offset;
+ moveTo(moveX - m_grabPoint, offset);
+
+ }
+
+
+// virtual
+/*
+void CustomTrackView::mousePressEvent ( QMouseEvent * event )
+{
+ int pos = event->x();
+ if (event->modifiers() == Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else if (event->modifiers() == Qt::ShiftModifier)
+ setDragMode(QGraphicsView::RubberBandDrag);
+ else {
+ QGraphicsItem * item = itemAt(event->pos());
+ if (item) {
+ }
+ else emit cursorMoved((int) mapToScene(event->x(), 0).x());
+ }
+ kDebug()<<pos;
+ QGraphicsView::mousePressEvent(event);
+}
+
+void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
+{
+ QGraphicsView::mouseReleaseEvent(event);
+ setDragMode(QGraphicsView::NoDrag);
+}
+*/
+
+#include "clipitem.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 CLIPITEM_H
+#define CLIPITEM_H
+
+#include <QGraphicsRectItem>
+#include <QGraphicsSceneMouseEvent>
+
+#include "labelitem.h"
+
+class ClipItem : public QGraphicsRectItem
+{
+
+ public:
+ ClipItem(int clipType, QString name, int producer, const QRectF & rect);
+ virtual void paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget);
+ virtual int type () const;
+ void moveTo(double x, double offset);
+
+ protected:
+ virtual void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
+ virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event );
+ virtual void mousePressEvent ( QGraphicsSceneMouseEvent * event );
+
+ private:
+ LabelItem *m_label;
+ int m_textWidth;
+ uint m_resizeMode;
+ int m_grabPoint;
+ int m_producer;
+};
+
+#endif
+/***************************************************************************
+ * 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 <QMouseEvent>
#include <QStylePainter>
void CustomRuler::slotNewValue ( int _value )
{
m_cursorPosition = _value / pixelPerMark();
+ emit cursorMoved(m_cursorPosition / FRAME_SIZE);
KRuler::slotNewValue(_value);
}
public slots:
void slotNewValue ( int _value );
+
+ signals:
+ void cursorMoved(int);
};
#endif
--- /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 <QMouseEvent>
+#include <QStylePainter>
+#include <QGraphicsItem>
+#include <QDomDocument>
+
+#include <KDebug>
+#include <KUrl>
+
+#include "customtrackview.h"
+#include "clipitem.h"
+#include "definitions.h"
+
+CustomTrackView::CustomTrackView(QGraphicsScene * scene, QWidget *parent)
+ : QGraphicsView(scene, parent), m_tracksCount(0), m_cursorPos(0), m_dropItem(NULL)
+{
+ setMouseTracking(true);
+ setAcceptDrops(true);
+}
+
+// virtual
+void CustomTrackView::mouseMoveEvent ( QMouseEvent * event )
+{
+ int pos = event->x();
+ if (event->modifiers() == Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else if (event->modifiers() == Qt::ShiftModifier)
+ setDragMode(QGraphicsView::RubberBandDrag);
+ else {
+ QGraphicsItem * item = itemAt(event->pos());
+ if (item) {
+ while (item->parentItem())
+ item = item->parentItem();
+ int cursorPos = event->x();
+ QRectF itemRect = item->sceneBoundingRect();
+ int itemStart = mapFromScene(itemRect.x(), 0).x();
+ int itemEnd = mapFromScene(itemRect.x() + itemRect.width(), 0).x();
+ if (abs(itemStart - cursorPos) < 6 || abs(itemEnd - cursorPos) < 6)
+ setCursor(Qt::SizeHorCursor);
+ else setCursor(Qt::OpenHandCursor);
+
+ }
+ else {
+ setCursor(Qt::ArrowCursor);
+ }
+ }
+ QGraphicsView::mouseMoveEvent(event);
+}
+
+// virtual
+void CustomTrackView::mousePressEvent ( QMouseEvent * event )
+{
+ int pos = event->x();
+ if (event->modifiers() == Qt::ControlModifier)
+ setDragMode(QGraphicsView::ScrollHandDrag);
+ else if (event->modifiers() == Qt::ShiftModifier)
+ setDragMode(QGraphicsView::RubberBandDrag);
+ else {
+ QGraphicsItem * item = itemAt(event->pos());
+ if (item) {
+ /*while (item->parentItem())
+ item = item->parentItem();
+
+ int cursorPos = event->x();
+ QRectF itemRect = item->sceneBoundingRect();
+ int itemStart = mapFromScene(itemRect.x(), 0).x();
+ int itemEnd = mapFromScene(itemRect.x() + itemRect.width(), 0).x();
+ if (abs(itemStart - cursorPos) < 6)
+ ((ClipItem *) item )->setResizeMode(1);
+ else if (abs(itemEnd - cursorPos) < 6)
+ ((ClipItem *) item )->setResizeMode(2);
+ */}
+ else {
+ setCursor(Qt::ArrowCursor);
+ emit cursorMoved((int) mapToScene(event->x(), 0).x());
+ }
+ }
+ //kDebug()<<pos;
+ QGraphicsView::mousePressEvent(event);
+}
+
+void CustomTrackView::dragEnterEvent ( QDragEnterEvent * event )
+{
+ if (event->mimeData()->hasText()) {
+ QString clip = event->mimeData()->text();
+ addItem(clip, event->pos());
+ event->acceptProposedAction();
+ }
+}
+
+
+void CustomTrackView::addItem(QString producer, QPoint pos)
+{
+ QDomDocument doc;
+ doc.setContent(producer);
+ QDomElement elem = doc.documentElement();
+ int in = elem.attribute("in", 0).toInt();
+ int out = elem.attribute("duration", 0).toInt();
+ if (out == 0) out = elem.attribute("out", 0).toInt() - in;
+ kDebug()<<"ADDING CLIP: "<<producer<<", OUT: "<<out<<", POS: "<<mapToScene(pos);
+ int trackTop = ((int) mapToScene(pos).y()/50) * 50 + 1;
+ QString clipName = elem.attribute("name");
+ if (clipName.isEmpty()) clipName = KUrl(elem.attribute("resource")).fileName();
+ m_dropItem = new ClipItem(elem.attribute("type").toInt(), clipName, elem.attribute("id").toInt(), QRectF(mapToScene(pos).x(), trackTop, out, 49));
+ scene()->addItem(m_dropItem);
+}
+
+
+void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
+ event->setDropAction(Qt::IgnoreAction);
+ if (m_dropItem) {
+ int trackTop = ((int) mapToScene(event->pos()).y()/50) * 50 + 1;
+ m_dropItem->moveTo(mapToScene(event->pos()).x(), trackTop - m_dropItem->rect().y());
+ }
+ //if (item) {
+ event->setDropAction(Qt::MoveAction);
+ if (event->mimeData()->hasText()) {
+ event->acceptProposedAction();
+ }
+ //}
+}
+
+void CustomTrackView::dragLeaveEvent ( QDragLeaveEvent * event ) {
+ if (m_dropItem) delete m_dropItem;
+ m_dropItem = NULL;
+}
+
+void CustomTrackView::dropEvent ( QDropEvent * event ) {
+ m_dropItem = NULL;
+}
+
+
+QStringList CustomTrackView::mimeTypes () const
+{
+ QStringList qstrList;
+ // list of accepted mime types for drop
+ qstrList.append("text/plain");
+ return qstrList;
+}
+
+Qt::DropActions CustomTrackView::supportedDropActions () const
+{
+ // returns what actions are supported when dropping
+ return Qt::MoveAction;
+}
+
+void CustomTrackView::addTrack ()
+{
+ m_tracksCount++;
+}
+
+void CustomTrackView::removeTrack ()
+{
+ m_tracksCount--;
+}
+
+void CustomTrackView::setCursorPos(int pos)
+{
+ m_cursorPos = pos;
+}
+
+int CustomTrackView::cursorPos()
+{
+ return m_cursorPos;
+}
+
+void CustomTrackView::mouseReleaseEvent ( QMouseEvent * event )
+{
+ QGraphicsView::mouseReleaseEvent(event);
+ setDragMode(QGraphicsView::NoDrag);
+}
+
+void CustomTrackView::drawBackground ( QPainter * painter, const QRectF & rect )
+{
+ //kDebug()<<"///// DRAWINGÂ BG: "<<rect.x()<<", width: "<<rect.width();
+ painter->drawRect(rect);
+ for (uint i = 0; i < m_tracksCount;i++)
+ {
+ painter->drawLine(rect.x(), 50 * i, rect.x() + rect.width(), 50 * i);
+ }
+}
+
+void CustomTrackView::drawForeground ( QPainter * painter, const QRectF & rect )
+{
+ //kDebug()<<"///// DRAWINGÂ FB: "<<rect.x()<<", width: "<<rect.width();
+ painter->drawLine(m_cursorPos, rect.y(), m_cursorPos, rect.y() + rect.height());
+}
+
+#include "customtrackview.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 CUSTOMTRACKVIEW_H
+#define CUSTOMTRACKVIEW_H
+
+#include <QGraphicsView>
+
+#include "clipitem.h"
+
+class CustomTrackView : public QGraphicsView
+{
+ Q_OBJECT
+
+ public:
+ CustomTrackView(QGraphicsScene * scene, QWidget *parent=0);
+ virtual void mousePressEvent ( QMouseEvent * event );
+ virtual void mouseReleaseEvent ( QMouseEvent * event );
+ virtual void mouseMoveEvent ( QMouseEvent * event );
+ void addTrack();
+ void removeTrack();
+ void setCursorPos(int pos);
+ int cursorPos();
+
+ protected:
+ virtual void drawBackground ( QPainter * painter, const QRectF & rect );
+ virtual void drawForeground ( QPainter * painter, const QRectF & rect );
+ virtual void dragEnterEvent ( QDragEnterEvent * event );
+ virtual void dragMoveEvent(QDragMoveEvent * event);
+ virtual void dragLeaveEvent ( QDragLeaveEvent * event );
+ virtual void dropEvent ( QDropEvent * event );
+ virtual QStringList mimeTypes() const;
+ virtual Qt::DropActions supportedDropActions () const;
+
+ private:
+ int m_tracksCount;
+ int m_cursorPos;
+ ClipItem *m_dropItem;
+ void addItem(QString producer, QPoint pos);
+
+ signals:
+ void cursorMoved(int);
+
+};
+
+#endif
}
// virtual
+/*
void DocumentAudioTrack::paintEvent(QPaintEvent *e )
{
QRect region = e->rect();
painter.fillRect(region, QBrush(Qt::green));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
}
-
+*/
#include "documentaudiotrack.moc"
DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
- virtual void paintEvent(QPaintEvent * /*e*/);
+ //virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
}
// virtual
+/*
void DocumentTrack::paintEvent(QPaintEvent *e )
{
QRect region = e->rect();
painter.fillRect(region, QBrush(Qt::red));
painter.drawLine(region.bottomLeft (), region.bottomRight ());
}
-
+*/
#include "documenttrack.moc"
QStringList applicableFunctions(const QString & mode);
protected:
- virtual void paintEvent(QPaintEvent * /*e*/);
+ //virtual void paintEvent(QPaintEvent * /*e*/);
private:
QDomElement m_xml;
}
// virtual
+/*
void DocumentVideoTrack::paintEvent(QPaintEvent *e )
{
QList <TrackViewClip> trackClipList = clipList();
painter.drawText(clipRect, Qt::AlignCenter, trackClipList.at(i).producer);
}
}
-
+*/
#include "documentvideotrack.moc"
DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
protected:
- virtual void paintEvent(QPaintEvent * /*e*/);
+ //virtual void paintEvent(QPaintEvent * /*e*/);
private:
TrackView *m_trackView;
#include "kdenlivedoc.h"
-KdenliveDoc::KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
+KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL)
{
m_commandStack = new KUndoStack();
if (m_render) m_render->setSceneList(m_document);
}
+QString KdenliveDoc::producerName(int id)
+{
+ QString result = "unnamed";
+ QDomNodeList prods = producersList();
+ int ct = prods.count();
+ for (int i = 0; i < ct ; i++)
+ {
+ QDomElement e = prods.item(i).toElement();
+ if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
+ result = e.attribute("name");
+ if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
+ break;
+ }
+ }
+ return result;
+}
+
QDomDocument KdenliveDoc::generateSceneList()
{
QDomDocument doc;
class KdenliveDoc:public QObject {
Q_OBJECT public:
- KdenliveDoc(KUrl url, double fps, int width, int height, QWidget *parent = 0);
+ KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent = 0);
~KdenliveDoc();
QString documentName();
QDomNodeList producersList();
QDomDocument toXml();
void setRenderer(Render *render);
KUndoStack *commandStack();
+ QString producerName(int id);
private:
KUrl m_url;
--- /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 <QPainter>
+#include <QStyleOptionGraphicsItem>
+
+#include <KDebug>
+
+
+#include "labelitem.h"
+
+LabelItem::LabelItem(QString text, QGraphicsRectItem *parent)
+ : QGraphicsSimpleTextItem(text, parent)
+{
+ //setParentItem(parent);
+ setFlags(QGraphicsItem::ItemIgnoresTransformations);
+}
+
+int LabelItem::type () const
+{
+ return 70001;
+}
+
+// virtual
+/*
+ void LabelItem::paint(QPainter *painter,
+ const QStyleOptionGraphicsItem *option,
+ QWidget *widget)
+ {
+ //painter->setClipRect( option->exposedRect );
+ QRectF rep = option->exposedRect;
+ QGraphicsRectItem *parent = (QGraphicsRectItem *) parentItem();
+ QRectF par = parent->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->fillRect(rect(), Qt::red);
+ QPainterPath path;
+ path.addPolygon(mapFromParent(parentItem()->boundingRect()));
+ //painter->fillPath(path, QColor(200, 100, 200, 150));
+ //painter->setClipPath(path);
+ painter->fillRect(boundingRect(), QColor(200, 100, 200, 150));
+ painter->drawText(boundingRect(), Qt::AlignCenter, text());
+ //painter->drawRect(rect());
+ //painter->drawRoundRect(-10, -10, 20, 20);
+ }*/
+
+#include "labelitem.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 LABELITEM_H
+#define LABELITEM_H
+
+#include <QGraphicsRectItem>
+#include <QGraphicsSimpleTextItem>
+#include <QGraphicsSceneMouseEvent>
+
+class LabelItem : public QGraphicsSimpleTextItem
+{
+
+ public:
+ LabelItem(QString text, QGraphicsRectItem *parent = 0);
+ //virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ virtual int type () const;
+};
+
+#endif
KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); //new
if(args->count()) //new
{
- window->openFile(args->url(0).url()); //new
+ window->openFile(args->url(0)); //new
}
return app.exec();
m_undoView->setStack(m_commandStack);
addDockWidget(Qt::TopDockWidgetArea, undoViewDock);
+ overviewDock = new QDockWidget(i18n("Project Overview"), this);
+ overviewDock->setObjectName("project_overview");
+ m_overView = new CustomTrackView(NULL, this);
+ overviewDock->setWidget(m_overView);
+ addDockWidget(Qt::TopDockWidgetArea, overviewDock);
+
setupActions();
tabifyDockWidget (projectListDock, effectListDock);
tabifyDockWidget (projectListDock, effectStackDock);
newFile();
}
+//virtual
+bool MainWindow::queryClose()
+{
+ saveOptions();
+ switch ( KMessageBox::warningYesNoCancel( this, i18n("Save changes to document ?")) ) {
+ case KMessageBox::Yes :
+ // save document here. If saving fails, return false;
+ return true;
+ case KMessageBox::No :
+ return true;
+ default: // cancel
+ return false;
+ }
+}
+
void MainWindow::slotRaiseMonitor(bool clipMonitor)
{
if (clipMonitor) clipMonitorDock->raise();
KStandardAction::open(this, SLOT(openFile()),
actionCollection());
-
+
+ m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
+ actionCollection());
+
KStandardAction::save(this, SLOT(saveFile()),
actionCollection());
KStandardAction::redo(this, SLOT(redo()),
actionCollection());*/
- KStandardAction::preferences(this, SLOT(slotPreferences()),
- actionCollection());
+ readOptions();
/*m_redo = m_commandStack->createRedoAction(actionCollection());
m_undo = m_commandStack->createUndoAction(actionCollection());*/
}
+
+void MainWindow::saveOptions()
+{
+ KSharedConfigPtr config = KGlobal::config ();
+ m_fileOpenRecent->saveEntries(KConfigGroup (config, "Recent Files"));
+ config->sync();
+}
+
+void MainWindow::readOptions()
+{
+ KSharedConfigPtr config = KGlobal::config ();
+ m_fileOpenRecent->loadEntries(KConfigGroup (config, "Recent Files"));
+}
void MainWindow::newFile()
{
void MainWindow::openFile() //changed
{
- openFile(KFileDialog::getOpenFileName(KUrl(), "application/vnd.kde.kdenlive,*.kdenlive"));
+ KUrl url = KFileDialog::getOpenUrl(KUrl(), "application/vnd.kde.kdenlive;*.kdenlive");
+ if (url.isEmpty()) return;
+ m_fileOpenRecent->addUrl (url);
+ openFile(url);
}
-void MainWindow::openFile(const QString &inputFileName) //new
+void MainWindow::openFile(const KUrl &url) //new
{
- KdenliveDoc *doc = new KdenliveDoc(KUrl(inputFileName), 25, 720, 576);
+ KdenliveDoc *doc = new KdenliveDoc(url, 25, 720, 576);
TrackView *trackView = new TrackView(doc);
m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, QIcon(), doc->documentName()));
m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), doc->url().path());
//m_undoView->setStack(0);
m_commandStack = doc->commandStack();
+ m_overView->setScene(trackView->projectScene());
+ m_overView->scale(m_overView->width() / trackView->duration(), m_overView->height() / (50 * trackView->tracksNumber()));
+ //m_overView->fitInView(m_overView->itemAt(0, 50), Qt::KeepAspectRatio);
QAction *redo = m_commandStack->createRedoAction(actionCollection());
QAction *undo = m_commandStack->createUndoAction(actionCollection());
#include <QDockWidget>
#include <QUndoView>
+#include <QLabel>
#include <KXmlGuiWindow>
#include <KTextEdit>
#include <KListWidget>
#include <KTabWidget>
#include <KUndoStack>
+#include <KRecentFilesAction>
#include "projectlist.h"
#include "monitor.h"
#include "monitormanager.h"
#include "kdenlivedoc.h"
#include "trackview.h"
+#include "customtrackview.h"
class MainWindow : public KXmlGuiWindow
{
public:
MainWindow(QWidget *parent=0);
- void openFile(const QString &inputFileName);
+
+ protected:
+ virtual bool queryClose();
private:
KTabWidget* m_timelineArea;
KUndoStack *m_commandStack;
QAction *m_undo;
QAction *m_redo;
-
+
+ QDockWidget *overviewDock;
+ CustomTrackView *m_overView;
+
+ KRecentFilesAction *m_fileOpenRecent;
+ void readOptions();
+ void saveOptions();
+
+ public slots:
+ void openFile(const KUrl &url);
+
+
private slots:
void newFile();
void activateDocument();
void ProjectItem::setProperties(const QMap < QString, QString > &attributes, const QMap < QString, QString > &metadata)
{
if (attributes.contains("duration")) {
+ if (m_clipType == DocClipBase::AUDIO || m_clipType == DocClipBase::VIDEO || m_clipType == DocClipBase::AV) m_element.setAttribute("duration", attributes["duration"].toInt());
m_duration = GenTime(attributes["duration"].toInt(), 25);
setData(1, DurationRole, Timecode::getEasyTimecode(m_duration, 25));
m_durationKnown = true;
if (m_element.isNull()) {
QDomDocument doc;
m_element = doc.createElement("producer");
+ m_element.setAttribute("duration", attributes["duration"].toInt());
}
m_element.setAttribute("resource", attributes["filename"]);
m_element.setAttribute("type", (int) m_clipType);
mimeData->setText(doc.toString());
//mimeData->setImageData(image);
drag->setMimeData(mimeData);
- drag->setPixmap(clickItem->icon(0).pixmap(40 *16/9.0, 40));
- drag->setHotSpot(QPoint(0, 20));
+ drag->setPixmap(clickItem->icon(0).pixmap(50 *16/9.0, 50));
+ drag->setHotSpot(QPoint(0, 50));
drag->start(Qt::MoveAction);
//Qt::DropAction dropAction;
Qt::DropActions ProjectListView::supportedDropActions () const
{
// returns what actions are supported when dropping
- return Qt::MoveAction | Qt::MoveAction;
+ return Qt::MoveAction;
}
#include "projectlistview.moc"
QPixmap pix(width, height);
mlt_image_format format = mlt_image_rgb24a;
- /*if (border) {
- width = width -2;
- height = height -2;
- }*/
uint8_t *thumb = frame->get_image(format, width, height);
QImage image(thumb, width, height, QImage::Format_ARGB32);
QPainter painter(&pix);
painter.drawRect(0, 0, width - 1, height - 1);
}
- /*if (!border) pix = pix.fromImage(image);
- //bitBlt(&pix, 0, 0, &image, 0, 0, width, height);
- else {
- pix.fill(black);
- bitBlt(&pix, 1, 1, &image, 0, 0, width, height);
- }*/
}
else pix.fill(Qt::black);
return pix;
Mlt::Filter m_convert("avcolour_space");
m_convert.set("forced", mlt_image_rgb24a);
producer.attach(m_convert);
-
+ producer.set("profile", "hdv_1080_50i");
Mlt::Frame * frame = producer.get_frame();
if (frame->is_valid()) {
+/***************************************************************************
+ * 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 <QMouseEvent>
#include <QStylePainter>
#include "documentaudiotrack.h"
#include "headertrack.h"
#include "trackview.h"
+#include "clipitem.h"
#include "trackpanelclipmovefunction.h"
TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
- : QWidget(parent), m_doc(doc), m_scale(1.0), m_panelUnderMouse(NULL), m_function(NULL)
+ : QWidget(parent), m_doc(doc), m_scale(1.0), m_panelUnderMouse(NULL), m_function(NULL), m_projectTracks(0), m_projectDuration(0)
{
setMouseTracking(true);
view = new Ui::TimeLine_UI();
layout->addWidget(m_ruler);
view->ruler_frame->setLayout(layout);
- m_tracksLayout = new QVBoxLayout;
- m_tracksLayout->setContentsMargins (0, 0, 0, 0);
- m_scrollArea = new QScrollArea;
-
- m_tracksLayout->addWidget(m_scrollArea);
- m_scrollArea->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOn);
- m_scrollArea->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
- m_scrollArea->setWidgetResizable( true );
-
- m_scrollBox = new QFrame(m_scrollArea);
- //m_scrollBox ->setFlat(false);
- m_scrollBox ->setFocusPolicy(Qt::WheelFocus);
- m_scrollBox->setSizePolicy( QSizePolicy::Preferred,QSizePolicy::Fixed );
-
- m_tracksAreaLayout = new QVBoxLayout(m_scrollBox);
- m_tracksAreaLayout->setContentsMargins (0, 0, 0, 0);
- m_tracksAreaLayout->setSpacing(0);
-//MyScroll->setGeometry(...);
- m_scrollArea->setWidget(m_scrollBox);
-
- view->tracks_frame->setLayout(m_tracksLayout);
+ m_scene = new QGraphicsScene();
+ m_trackview = new CustomTrackView(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));
m_headersLayout = new QVBoxLayout;
m_headersLayout->setContentsMargins (0, 0, 0, 0);
view->headers_frame->setLayout(m_headersLayout);
+ QVBoxLayout *tracksLayout = new QVBoxLayout;
+ tracksLayout->setContentsMargins (0, 0, 0, 0);
+ view->tracks_frame->setLayout(tracksLayout);
+ tracksLayout->addWidget(m_trackview);
+
parseDocument(doc->toXml());
TrackPanelClipMoveFunction *m_moveFunction = new TrackPanelClipMoveFunction(this);
registerFunction("move", m_moveFunction);
setEditMode("move");
+ view->horizontalSlider->setValue(0);
+ m_currentZoom = view->horizontalSlider->value();
connect(view->horizontalSlider, SIGNAL(valueChanged ( int )), this, SLOT(slotChangeZoom( int )));
+ connect(m_ruler, SIGNAL(cursorMoved ( int )), this, SLOT(slotCursorMoved( int )));
+ connect(m_trackview, SIGNAL(cursorMoved ( int )), this, SLOT(slotCursorMoved( int )));
+
+ m_cursorLine = m_scene->addLine(0, 0, 0, 200); //m_trackview->height());
}
void TrackView::registerFunction(const QString & name, TrackPanelFunction * function)
m_factory.registerFunction(name, function);
}
+int TrackView::duration()
+{
+ return m_projectDuration;
+}
+
+int TrackView::tracksNumber()
+{
+ return m_projectTracks;
+}
+
void TrackView::parseDocument(QDomDocument doc)
{
QDomNodeList tracks = doc.elementsByTagName("playlist");
m_projectDuration = 300;
+ m_projectTracks = tracks.count();
int duration;
for (int i = 0; i < tracks.count(); i++)
{
// this is an audio track
duration = slotAddAudioTrack(i, tracks.item(i).toElement());
}
- else duration = slotAddVideoTrack(i, tracks.item(i).toElement());
+ else if (!tracks.item(i).toElement().attribute("id", QString::null).isEmpty())
+ duration = slotAddVideoTrack(i, tracks.item(i).toElement());
if (duration > m_projectDuration) m_projectDuration = duration;
}
- m_tracksAreaLayout->insertStretch (1000);
//m_scrollBox->setGeometry(0, 0, 300 * zoomFactor(), m_scrollArea->height());
}
+void TrackView::slotCursorMoved(int pos)
+{
+ kDebug()<<"///// CURSOR: "<<pos;
+ //m_cursorLine->setPos(pos, 0);
+ m_trackview->setCursorPos(pos);
+ m_trackview->invalidateScene(QRectF(), QGraphicsScene::ForegroundLayer);
+}
+
void TrackView::slotChangeZoom(int factor)
{
m_ruler->setPixelPerMark(factor);
- m_scale = m_ruler->pixelPerMark();
+ //m_scale = m_ruler->pixelPerMark();
+ m_scale = (double) m_ruler->comboScale[m_currentZoom] / m_ruler->comboScale[factor];
+ //else m_scale = (double) m_ruler->comboScale[m_currentZoom] / m_ruler->comboScale[factor];
+ m_currentZoom = factor;
+ kDebug()<<"///// ZOOMING: "<<m_scale;
+ m_trackview->scale(m_scale, 1);
+ /*
for (int i = 0; i < documentTracks.count(); i++) {
kDebug()<<"------REPAINTING OBJECT";
documentTracks.at(i)->update();
//documentTracks.at(i)->setFixedWidth(300 * zoomFactor());
}
- m_scrollBox->setFixedWidth(( m_projectDuration + 300) * zoomFactor());
+ m_scrollBox->setFixedWidth(( m_projectDuration + 300) * zoomFactor());*/
/*m_scrollArea->horizontalScrollBar()->setMaximum(300 * zoomFactor());
m_scrollArea->horizontalScrollBar()->setPageStep(FRAME_SIZE * zoomFactor());*/
}
int TrackView::slotAddAudioTrack(int ix, QDomElement xml)
{
- DocumentTrack *track = new DocumentAudioTrack(xml, this, m_scrollBox);
+ m_trackview->addTrack();
+ DocumentTrack *track = new DocumentAudioTrack(xml, this, m_trackview);
HeaderTrack *header = new HeaderTrack();
- m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
+ //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
m_headersLayout->addWidget(header); //, ix, Qt::AlignTop);
documentTracks.insert(ix, track);
return track->duration();
int TrackView::slotAddVideoTrack(int ix, QDomElement xml)
{
- DocumentTrack *track = new DocumentVideoTrack(xml, this, m_scrollBox);
+ m_trackview->addTrack();
+ DocumentTrack *track = new DocumentVideoTrack(xml, this, m_trackview);
HeaderTrack *header = new HeaderTrack();
- m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
+ int trackTop = 50 * ix;
+ int trackBottom = trackTop + 50;
+ // parse track
+ int position = 0;
+ for(QDomNode n = xml.firstChild(); !n.isNull(); n = n.nextSibling())
+ {
+ QDomElement elem = n.toElement();
+ if (elem.tagName() == "blank") {
+ position += elem.attribute("length", 0).toInt();
+ }
+ else if (elem.tagName() == "entry") {
+ int in = elem.attribute("in", 0).toInt();
+ int out = elem.attribute("out", 0).toInt() - in;
+ QString clipName = m_doc->producerName(elem.attribute("producer").toInt());
+ //kDebug()<<"++++++++++++++\n\n / / /ADDING CLIP: "<<clip.cropTime<<", out: "<<clip.duration<<", Producer: "<<clip.producer<<"\n\n++++++++++++++++++++";
+ ClipItem *item = new ClipItem(elem.attribute("type").toInt(), clipName, elem.attribute("producer").toInt(), QRectF(position, trackTop + 1, out, 49));
+ m_scene->addItem(item);
+ position += out;
+
+ //m_clipList.append(clip);
+ }
+ }
+ //m_trackDuration = position;
+
+ //m_tracksAreaLayout->addWidget(track); //, ix, Qt::AlignTop);
m_headersLayout->addWidget(header); //, ix, Qt::AlignTop);
documentTracks.insert(ix, track);
- return track->duration();
+ return position;
//track->show();
}
return NULL;
}
+QGraphicsScene *TrackView::projectScene()
+{
+ return m_scene;
+}
+
+CustomTrackView *TrackView::projectView()
+{
+ return m_trackview;
+}
+
void TrackView::setEditMode(const QString & editMode)
{
m_editMode = editMode;
+/***************************************************************************
+ * 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 TRACKVIEW_H
#define TRACKVIEW_H
#include <QVBoxLayout>
#include <KRuler>
#include <QGroupBox>
+#include <QGraphicsScene>
+#include <QGraphicsLineItem>
#define FRAME_SIZE 90
#include "documenttrack.h"
#include "trackpanelfunctionfactory.h"
#include "trackpanelfunction.h"
+#include "customtrackview.h"
class TrackView : public QWidget
{
const int mapLocalToValue(int x) const;
void setEditMode(const QString & editMode);
const QString & editMode() const;
+ QGraphicsScene *projectScene();
+ CustomTrackView *projectView();
+ int duration();
+ int tracksNumber();
public slots:
KdenliveDoc *document();
private:
Ui::TimeLine_UI *view;
CustomRuler *m_ruler;
+ CustomTrackView *m_trackview;
double m_scale;
QList <DocumentTrack*> documentTracks;
int m_projectDuration;
+ int m_projectTracks;
TrackPanelFunctionFactory m_factory;
DocumentTrack *m_panelUnderMouse;
/** The currently applied function. This lasts from mousePressed until mouseRelease. */
TrackPanelFunction *m_function;
QString m_editMode;
+ QGraphicsScene *m_scene;
+ uint m_currentZoom;
+ QGraphicsLineItem *m_cursorLine;
KdenliveDoc *m_doc;
QVBoxLayout *m_tracksLayout;
private slots:
void slotChangeZoom(int factor);
+ void slotCursorMoved(int pos);
};
#endif
<rect>
<x>0</x>
<y>0</y>
- <width>326</width>
- <height>145</height>
+ <width>308</width>
+ <height>130</height>
</rect>
</property>
<layout class="QGridLayout" >