]> git.sesse.net Git - kdenlive/commitdiff
Start porting timeline to QGraphicsView
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 20 Jan 2008 22:31:16 +0000 (22:31 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Sun, 20 Jan 2008 22:31:16 +0000 (22:31 +0000)
svn path=/branches/KDE4/; revision=1805

27 files changed:
src/CMakeLists.txt
src/addclipcommand.cpp
src/clipitem.cpp [new file with mode: 0644]
src/clipitem.h [new file with mode: 0644]
src/customruler.cpp
src/customruler.h
src/customtrackview.cpp [new file with mode: 0644]
src/customtrackview.h [new file with mode: 0644]
src/documentaudiotrack.cpp
src/documentaudiotrack.h
src/documenttrack.cpp
src/documenttrack.h
src/documentvideotrack.cpp
src/documentvideotrack.h
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/labelitem.cpp [new file with mode: 0644]
src/labelitem.h [new file with mode: 0644]
src/main.cpp
src/mainwindow.cpp
src/mainwindow.h
src/projectitem.cpp
src/projectlistview.cpp
src/renderer.cpp
src/trackview.cpp
src/trackview.h
src/widgets/timeline_ui.ui

index 988f4f82b21833057206e14ad5ee1059332056ff..47cde5dab000c9e7b5627b4003544b5a09581079 100644 (file)
@@ -50,6 +50,9 @@ set(kdenlive_SRCS
   trackpanelfunctionfactory.cpp
   trackpanelfunction.cpp
   trackpanelclipmovefunction.cpp
+  customtrackview.cpp
+  clipitem.cpp
+  labelitem.cpp
 )
 
 kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
index 0242f69410a0cd238c17757e253a314f0731a1c8..80e43df79dba7bce857d7a77fbc7d7220512d04b 100644 (file)
@@ -23,7 +23,7 @@ AddClipCommand::AddClipCommand(ProjectList *list, const QStringList &names, cons
          : 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 
diff --git a/src/clipitem.cpp b/src/clipitem.cpp
new file mode 100644 (file)
index 0000000..7912cbc
--- /dev/null
@@ -0,0 +1,168 @@
+/***************************************************************************
+ *   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"
diff --git a/src/clipitem.h b/src/clipitem.h
new file mode 100644 (file)
index 0000000..d80e096
--- /dev/null
@@ -0,0 +1,53 @@
+/***************************************************************************
+ *   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
index f1edad9a2e527a88ea812f3db0ff1d0a16228f13..4b26427cfa80019736f62805796bf4f0cde8db6e 100644 (file)
@@ -1,3 +1,21 @@
+/***************************************************************************
+ *   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>
@@ -88,6 +106,7 @@ void CustomRuler::mouseMoveEvent ( QMouseEvent * event )
 void CustomRuler::slotNewValue ( int _value )
 {
   m_cursorPosition = _value / pixelPerMark();
+  emit cursorMoved(m_cursorPosition / FRAME_SIZE);
   KRuler::slotNewValue(_value);
 }
 
index 9d50f2663b6ac2cc07ddd7e98d6b13f7c40b626a..ad468c8c12f5a1f6b5344ab38494dc1729bbfc0c 100644 (file)
@@ -24,6 +24,9 @@ class CustomRuler : public KRuler
 
   public slots:
     void slotNewValue ( int _value );
+
+  signals:
+    void cursorMoved(int);
 };
 
 #endif
diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp
new file mode 100644 (file)
index 0000000..376be5c
--- /dev/null
@@ -0,0 +1,207 @@
+/***************************************************************************
+ *   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"
diff --git a/src/customtrackview.h b/src/customtrackview.h
new file mode 100644 (file)
index 0000000..8d601ac
--- /dev/null
@@ -0,0 +1,63 @@
+/***************************************************************************
+ *   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
index 665445389ff72254f5aa8ee68fdfa27c54f31377..586e4e0086ca459a6e347b11ead38950d172da7f 100644 (file)
@@ -17,6 +17,7 @@ DocumentAudioTrack::DocumentAudioTrack(QDomElement xml, TrackView * view, QWidge
 }
 
 // virtual
+/*
 void DocumentAudioTrack::paintEvent(QPaintEvent *e )
 {
     QRect region = e->rect();
@@ -24,6 +25,6 @@ void DocumentAudioTrack::paintEvent(QPaintEvent *e )
     painter.fillRect(region, QBrush(Qt::green));
     painter.drawLine(region.bottomLeft (), region.bottomRight ());
 }
-
+*/
 
 #include "documentaudiotrack.moc"
index 45b58e964032ad6569bd8423a06a2092c1928c98..c806243ffc575acdd1928d33b31e19ea85696dd2 100644 (file)
@@ -12,7 +12,7 @@ class DocumentAudioTrack : public DocumentTrack
     DocumentAudioTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
 
   protected:
-    virtual void paintEvent(QPaintEvent * /*e*/);
+    //virtual void paintEvent(QPaintEvent * /*e*/);
 
   private:
     TrackView *m_trackView;
index 060f55a82a5dcf6f881518049f0a4a72b93bf00a..676165f194370e2579ceccc0907859f86da36b09 100644 (file)
@@ -75,6 +75,7 @@ QList <TrackViewClip> DocumentTrack::clipList()
 }
 
 // virtual
+/*
 void DocumentTrack::paintEvent(QPaintEvent *e )
 {
     QRect region = e->rect();
@@ -83,6 +84,6 @@ void DocumentTrack::paintEvent(QPaintEvent *e )
     painter.fillRect(region, QBrush(Qt::red));
     painter.drawLine(region.bottomLeft (), region.bottomRight ());
 }
-
+*/
 
 #include "documenttrack.moc"
index 2084634e7a77f50b0584f64175c5cc8a6ff7500a..27caf4d5bf27ad4ff6b6d0be9c9d58f4e5d49ef0 100644 (file)
@@ -30,7 +30,7 @@ class DocumentTrack : public QWidget
     QStringList applicableFunctions(const QString & mode);
 
   protected:
-    virtual void paintEvent(QPaintEvent * /*e*/);
+    //virtual void paintEvent(QPaintEvent * /*e*/);
 
   private:
     QDomElement m_xml;
index 042e62688190cc83c96df840e8504c3c0a94d47b..b92971fc293c0846321ef6ac6fead5560fb89254 100644 (file)
@@ -17,6 +17,7 @@ DocumentVideoTrack::DocumentVideoTrack(QDomElement xml, TrackView * view, QWidge
 }
 
 // virtual
+/*
 void DocumentVideoTrack::paintEvent(QPaintEvent *e )
 {
     QList <TrackViewClip> trackClipList = clipList();
@@ -39,6 +40,6 @@ void DocumentVideoTrack::paintEvent(QPaintEvent *e )
       painter.drawText(clipRect, Qt::AlignCenter, trackClipList.at(i).producer);
     }
 }
-
+*/
 
 #include "documentvideotrack.moc"
index 0168553e3401a8b160274398940be28d511ca964..83d45d9c50cac8781d56f84cbc2a477e9ad7873f 100644 (file)
@@ -13,7 +13,7 @@ class DocumentVideoTrack : public DocumentTrack
     DocumentVideoTrack(QDomElement xml, TrackView * view, QWidget *parent=0);
 
   protected:
-    virtual void paintEvent(QPaintEvent * /*e*/);
+    //virtual void paintEvent(QPaintEvent * /*e*/);
 
   private:
     TrackView *m_trackView;
index bab68a294643ccb287772492a346d688a182f9d2..b796a1006198a40565b65af00b9f75021e7fd33b 100644 (file)
@@ -28,7 +28,7 @@
 #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();
@@ -110,6 +110,23 @@ void KdenliveDoc::setRenderer(Render *render)
   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;
index 0b1967f1aaab8087bbaf1e60e53a1226ef0aa354..b0a2c0ff96796d718645e0ccd55e5eba4283649b 100644 (file)
@@ -37,7 +37,7 @@
 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();
@@ -50,6 +50,7 @@ class KdenliveDoc:public QObject {
     QDomDocument toXml();
     void setRenderer(Render *render);
     KUndoStack *commandStack();
+    QString producerName(int id);
 
   private:
     KUrl m_url;
diff --git a/src/labelitem.cpp b/src/labelitem.cpp
new file mode 100644 (file)
index 0000000..4547bf2
--- /dev/null
@@ -0,0 +1,68 @@
+/***************************************************************************
+ *   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"
diff --git a/src/labelitem.h b/src/labelitem.h
new file mode 100644 (file)
index 0000000..042a9e8
--- /dev/null
@@ -0,0 +1,37 @@
+/***************************************************************************
+ *   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
index f6a8888d0ccb0ed0a555581d312022241a0213d3..908c9ce875b0d5bdd5a315d852f5dd51ff7076c2 100644 (file)
@@ -26,7 +26,7 @@ int main (int argc, char *argv[])
   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();
index 39fa17f8b5a46263702c90fc94cde84c0aa88f9a..72d6994b9d6c9961f1e4d22049852f559206d45e 100644 (file)
@@ -99,6 +99,12 @@ MainWindow::MainWindow(QWidget *parent)
   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);
@@ -120,6 +126,21 @@ MainWindow::MainWindow(QWidget *parent)
   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();
@@ -156,7 +177,10 @@ void MainWindow::setupActions()
  
   KStandardAction::open(this, SLOT(openFile()),
                         actionCollection());
+
+  m_fileOpenRecent = KStandardAction::openRecent(this, SLOT(openFile(const KUrl &)),
+                        actionCollection());
+
   KStandardAction::save(this, SLOT(saveFile()),
                         actionCollection());
  
@@ -172,12 +196,24 @@ void MainWindow::setupActions()
   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()
 {
@@ -228,12 +264,15 @@ void MainWindow::saveFile()
  
 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());
@@ -254,6 +293,9 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //chang
   //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());
 
index 5c47b182a7a538f336fcaeb2e237dd0498dfc2c6..d429199a6c7751d71557eef1e82e73dc5fabce82 100644 (file)
  
 #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
 {
@@ -42,7 +45,9 @@ class MainWindow : public KXmlGuiWindow
   
   public:
     MainWindow(QWidget *parent=0);
-    void openFile(const QString &inputFileName);
+
+  protected:
+    virtual bool queryClose();
   
   private:
     KTabWidget* m_timelineArea;
@@ -74,7 +79,18 @@ class MainWindow : public KXmlGuiWindow
     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();
index 7ac2a3eb642b9284db66acbb9abb9659d6b00e0a..909e7b86f0edd9334c710679a2bee4c4910040c7 100644 (file)
@@ -160,6 +160,7 @@ void ProjectItem::slotSetToolTip()
 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;
@@ -191,6 +192,7 @@ void ProjectItem::setProperties(const QMap < QString, QString > &attributes, con
        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);
index 83bb7a6f7ead392ca10bca8ad954b79067713506..a8ebce7f86138d038ce3d58a44aa334d4699b478 100644 (file)
@@ -161,8 +161,8 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event)
       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;
@@ -199,7 +199,7 @@ QStringList ProjectListView::mimeTypes () const
 Qt::DropActions ProjectListView::supportedDropActions () const
 {
     // returns what actions are supported when dropping
-    return Qt::MoveAction | Qt::MoveAction;
+    return Qt::MoveAction;
 }
 
 #include "projectlistview.moc"
index 8bac2f4670b0f1b3ad42ae9a1f03cf09b8eef319..2fb82122f09051bf98c7d22727c013152385370e 100644 (file)
@@ -197,10 +197,6 @@ QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool bo
     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);
   
@@ -210,12 +206,6 @@ QPixmap Render::frameThumbnail(Mlt::Frame *frame, int width, int height, bool bo
        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;
@@ -419,7 +409,7 @@ void Render::getFileProperties(const QDomElement &xml, int clipId)
         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()) {
index 77b76dfeaf7ddf8ac1e77a8aa2a72a83dbd91ba2..fa770a59fd86aafd70cde71415aab0ff44aabfc8 100644 (file)
@@ -1,3 +1,22 @@
+/***************************************************************************
+ *   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();
@@ -23,39 +43,34 @@ TrackView::TrackView(KdenliveDoc *doc, QWidget *parent)
   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) 
@@ -63,10 +78,21 @@ void TrackView::registerFunction(const QString & name, TrackPanelFunction * func
   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++)
   {
@@ -74,23 +100,37 @@ void TrackView::parseDocument(QDomDocument doc)
       // 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());*/
 }
@@ -112,9 +152,10 @@ KdenliveDoc *TrackView::document()
 
 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();
@@ -123,12 +164,37 @@ int TrackView::slotAddAudioTrack(int ix, QDomElement xml)
 
 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();
 }
 
@@ -137,6 +203,16 @@ DocumentTrack *TrackView::panelAt(int y)
   return NULL;
 }
 
+QGraphicsScene *TrackView::projectScene()
+{
+  return m_scene;
+}
+
+CustomTrackView *TrackView::projectView()
+{
+  return m_trackview;
+}
+
 void TrackView::setEditMode(const QString & editMode)
 {
   m_editMode = editMode;
index 410ecef0a208854b47b73a69744b23444a2e8562..8f82af1f15eeecad614f08b401165e9b4cad879e 100644 (file)
@@ -1,3 +1,23 @@
+/***************************************************************************
+ *   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
 
@@ -5,6 +25,8 @@
 #include <QVBoxLayout>
 #include <KRuler>
 #include <QGroupBox>
+#include <QGraphicsScene>
+#include <QGraphicsLineItem>
 
 #define FRAME_SIZE 90
 
@@ -14,6 +36,7 @@
 #include "documenttrack.h"
 #include "trackpanelfunctionfactory.h"
 #include "trackpanelfunction.h"
+#include "customtrackview.h"
 
 class TrackView : public QWidget
 {
@@ -30,6 +53,10 @@ 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();
@@ -37,14 +64,19 @@ class TrackView : public QWidget
   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;
@@ -60,6 +92,7 @@ class TrackView : public QWidget
 
   private slots:
     void slotChangeZoom(int factor);
+    void slotCursorMoved(int pos);
 };
 
 #endif
index f66d016e367cf9cddb5cd96b5041b1f40eda7be6..cf3c75008dbfff60f48658d06b9a8bf17ca2f22b 100644 (file)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>326</width>
-    <height>145</height>
+    <width>308</width>
+    <height>130</height>
    </rect>
   </property>
   <layout class="QGridLayout" >