]> git.sesse.net Git - kdenlive/commitdiff
Fully functionnal zone in monitors, enable drag & drop from clip monitor
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 24 Sep 2008 16:04:48 +0000 (16:04 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 24 Sep 2008 16:04:48 +0000 (16:04 +0000)
svn path=/branches/KDE4/; revision=2405

src/customtrackview.cpp
src/customtrackview.h
src/monitor.cpp
src/monitor.h
src/projectlistview.cpp
src/renderer.cpp
src/smallruler.cpp

index 29a7e14ebe3d31093d4f21ee7de19d3d3f0d67f6..132d68747e52d98d416df583d3e0bb3c487ed684 100644 (file)
@@ -749,7 +749,14 @@ void CustomTrackView::activateMonitor() {
 }
 
 void CustomTrackView::dragEnterEvent(QDragEnterEvent * event) {
-    if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
+    if (event->mimeData()->hasFormat("kdenlive/clip")) {
+        QStringList list = QString(event->mimeData()->data("kdenlive/clip")).split(";");
+        kDebug() << "DRAG ENTER EVENT, DATA: " << list;
+        DocClipBase *clip = m_document->getBaseClip(list.at(0));
+        if (clip == NULL) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0);
+        addItem(clip, event->pos(), QPoint(list.at(1).toInt(), list.at(2).toInt()));
+        event->acceptProposedAction();
+    } else if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
         kDebug() << "///////////////  DRAG ENTERED, TEXT: " << event->mimeData()->data("kdenlive/producerslist");
         QStringList ids = QString(event->mimeData()->data("kdenlive/producerslist")).split(";");
         //TODO: drop of several clips
@@ -1003,6 +1010,17 @@ void CustomTrackView::addItem(DocClipBase *clip, QPoint pos) {
     scene()->addItem(m_dropItem);
 }
 
+void CustomTrackView::addItem(DocClipBase *clip, QPoint pos, QPoint zone) {
+    ItemInfo info;
+    info.startPos = GenTime((int)(mapToScene(pos).x()), m_document->fps());
+    info.cropStart = GenTime(zone.x(), m_document->fps());
+    info.endPos = info.startPos + GenTime(zone.y() - zone.x(), m_document->fps());
+    info.track = (int)(pos.y() / m_tracksHeight);
+    kDebug() << "------------  ADDING CLIP ZONE ITEM----: " << zone;
+    m_dropItem = new ClipItem(clip, info, m_document->fps());
+    scene()->addItem(m_dropItem);
+}
+
 
 void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
     event->setDropAction(Qt::IgnoreAction);
@@ -1011,7 +1029,7 @@ void CustomTrackView::dragMoveEvent(QDragMoveEvent * event) {
         int pos = mapToScene(event->pos()).x();
         m_dropItem->setPos(pos, track * m_tracksHeight + 1);
         event->setDropAction(Qt::MoveAction);
-        if (event->mimeData()->hasFormat("kdenlive/producerslist")) {
+        if (event->mimeData()->hasFormat("kdenlive/producerslist") || event->mimeData()->hasFormat("kdenlive/clip")) {
             event->acceptProposedAction();
         }
     } else {
@@ -1051,6 +1069,7 @@ QStringList CustomTrackView::mimeTypes() const {
     // list of accepted mime types for drop
     qstrList.append("text/plain");
     qstrList.append("kdenlive/producerslist");
+    qstrList.append("kdenlive/clip");
     return qstrList;
 }
 
index 186c2d64161938a70cdae6909e7280d62a439c53..62de5b95cf2817f3b47bf5a9bc207e46f1f8768e 100644 (file)
@@ -146,6 +146,7 @@ private:
     KdenliveDoc *m_document;
     CustomTrackScene *m_scene;
     void addItem(DocClipBase *clip, QPoint pos);
+    void addItem(DocClipBase *clip, QPoint pos, QPoint zone);
     QGraphicsLineItem *m_cursorLine;
     ItemInfo m_dragItemInfo;
     OPERATIONTYPE m_operationMode;
index 78c0f5ad35aa7c6464747da16440258fbea67c86..57a55e68e04b1181ed3b54666ce3c926da94d437 100644 (file)
@@ -37,7 +37,7 @@
 #include "docclipbase.h"
 
 Monitor::Monitor(QString name, MonitorManager *manager, QWidget *parent)
-        : QWidget(parent), render(NULL), m_monitorManager(manager), m_name(name), m_isActive(false), m_currentClip(NULL) {
+        : QWidget(parent), render(NULL), m_monitorManager(manager), m_name(name), m_isActive(false), m_currentClip(NULL), m_dragStarted(false) {
     ui.setupUi(this);
     m_scale = 1;
     m_ruler = new SmallRuler();
@@ -198,10 +198,81 @@ void Monitor::slotSetZoneEnd() {
 // virtual
 void Monitor::mousePressEvent(QMouseEvent * event) {
     if (event->button() != Qt::RightButton) {
-        if (ui.video_frame->underMouse()) slotPlay();
+        if (ui.video_frame->underMouse()) {
+            m_dragStarted = true;
+            m_DragStartPosition = event->pos();
+        }
     } else m_contextMenu->popup(event->globalPos());
 }
 
+// virtual
+void Monitor::mouseReleaseEvent(QMouseEvent * event) {
+    if (m_dragStarted) {
+        if (ui.video_frame->underMouse()) {
+            slotPlay();
+        } else QWidget::mouseReleaseEvent(event);
+        m_dragStarted = false;
+    }
+}
+
+
+// virtual
+void Monitor::mouseMoveEvent(QMouseEvent *event) {
+    kDebug() << "// DRAG STARTED, MOUSE MOVED: ";
+    if (!m_dragStarted || m_currentClip == NULL) return;
+
+    if ((event->pos() - m_DragStartPosition).manhattanLength()
+            < QApplication::startDragDistance())
+        return;
+
+    {
+        QDrag *drag = new QDrag(this);
+        QMimeData *mimeData = new QMimeData;
+
+        QStringList list;
+        list.append(m_currentClip->getId());
+        QPoint p = m_ruler->zone();
+        list.append(QString::number(p.x()));
+        list.append(QString::number(p.y()));
+        QByteArray data;
+        data.append(list.join(";").toUtf8());
+        mimeData->setData("kdenlive/clip", data);
+        drag->setMimeData(mimeData);
+        QPixmap pix = m_currentClip->thumbnail();
+        drag->setPixmap(pix);
+        drag->setHotSpot(QPoint(0, 50));
+        drag->start(Qt::MoveAction);
+
+        //Qt::DropAction dropAction;
+        //dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
+
+        //Qt::DropAction dropAction = drag->exec();
+
+    }
+    //event->accept();
+}
+
+/*void Monitor::dragMoveEvent(QDragMoveEvent * event) {
+    event->setDropAction(Qt::IgnoreAction);
+    event->setDropAction(Qt::MoveAction);
+    if (event->mimeData()->hasText()) {
+        event->acceptProposedAction();
+    }
+}
+
+Qt::DropActions Monitor::supportedDropActions() const {
+    // returns what actions are supported when dropping
+    return Qt::MoveAction;
+}*/
+
+QStringList Monitor::mimeTypes() const {
+    QStringList qstrList;
+    // list of accepted mime types for drop
+    qstrList.append("kdenlive/clip");
+    return qstrList;
+}
+
+
 // virtual
 void Monitor::wheelEvent(QWheelEvent * event) {
     if (event->modifiers() == Qt::ControlModifier) {
index 09d34ccef35beb1f58e1dc65583bcd497af79215..df6c78c4243fe11f4ce95a38dd6f3a2c6e3fe56d 100644 (file)
@@ -55,7 +55,13 @@ public:
 
 protected:
     virtual void mousePressEvent(QMouseEvent * event);
+    virtual void mouseReleaseEvent(QMouseEvent * event);
     virtual void wheelEvent(QWheelEvent * event);
+    virtual void mouseMoveEvent(QMouseEvent *event);
+    virtual QStringList mimeTypes() const;
+    /*    virtual void dragMoveEvent(QDragMoveEvent * event);
+        virtual Qt::DropActions supportedDropActions() const;*/
+
 //    virtual void resizeEvent(QResizeEvent * event);
 //    virtual void paintEvent(QPaintEvent * event);
 
@@ -75,6 +81,8 @@ private:
     QAction *m_playAction;
     QMenu *m_contextMenu;
     DocClipBase *m_currentClip;
+    QPoint m_DragStartPosition;
+    bool m_dragStarted;
 
 private slots:
     void adjustRulerSize(int length);
index 4ef4653ca08df36a91d5b028b94d85f8642e4e7d..faefd9b7bf2071a5db961d4d880f1ac9de8fc515 100644 (file)
@@ -237,6 +237,7 @@ void ProjectListView::mouseMoveEvent(QMouseEvent *event) {
     }
 }
 
+// virtual
 void ProjectListView::dragMoveEvent(QDragMoveEvent * event) {
     QTreeWidgetItem * item = itemAt(event->pos());
     event->setDropAction(Qt::IgnoreAction);
index d510b56fe266c0f254f326356d7049b929194709..3675fd9fca9208943f0b43ca7b2e7e72b8b51b55 100644 (file)
@@ -1215,8 +1215,8 @@ void Render::mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *pr
     mlt_service_lock(service.get_service());
     Mlt::Producer trackProducer(tractor.track(info.track));
     Mlt::Playlist trackPlaylist((mlt_playlist) trackProducer.get_service());
-
-    Mlt::Producer *clip = prod->cut(info.cropStart.frames(m_fps), (info.endPos - info.startPos).frames(m_fps) - 1);
+    //kDebug()<<"/// INSERT cLIP: "<<info.cropStart.frames(m_fps)<<", "<<info.startPos.frames(m_fps)<<"-"<<info.endPos.frames(m_fps);
+    Mlt::Producer *clip = prod->cut((int) info.cropStart.frames(m_fps), (int)(info.endPos - info.startPos + info.cropStart).frames(m_fps) - 1);
     int newIndex = trackPlaylist.insert_at((int) info.startPos.frames(m_fps), *clip, 1);
 
     if (QString(prod->get("transparency")).toInt() == 1)
index 7575927a012d07b803cdb96c3fc51dd793771ca0..28f5edb6e8ad5bbc2dfcdbc5e17336735bb05d03 100644 (file)
@@ -53,14 +53,22 @@ void SmallRuler::adjustScale(int maximum) {
 
 void SmallRuler::setZone(int start, int end) {
     if (start != -1) {
-        if (end != -1 && start >= end) return;
-        else if (end == -1 && start >= m_zoneEnd) return;
-        m_zoneStart = start;
+        if (end != -1 && start >= end) {
+            m_zoneEnd = qMin(m_maxval, end + (start - m_zoneStart));
+            m_zoneStart = start;
+        } else if (end == -1 && start >= m_zoneEnd) {
+            m_zoneEnd = qMin(m_maxval, m_zoneEnd + (start - m_zoneStart));
+            m_zoneStart = start;
+        } else m_zoneStart = start;
     }
     if (end != -1) {
-        if (start != -1 && end <= start) end = m_zoneEnd;
-        else if (start == -1 && end <= m_zoneStart) end = m_zoneEnd;
-        m_zoneEnd = end;
+        if (start != -1 && end <= start) {
+            m_zoneStart = qMax(0, start - (m_zoneEnd - end));
+            m_zoneEnd = end;
+        } else if (start == -1 && end <= m_zoneStart) {
+            m_zoneStart = qMax(0, m_zoneStart - (m_zoneEnd - end));
+            m_zoneEnd = end;
+        } else m_zoneEnd = end;
     }
     update();
 }