]> git.sesse.net Git - kdenlive/blobdiff - src/abstractgroupitem.cpp
Fix drag & drop of effects:
[kdenlive] / src / abstractgroupitem.cpp
index ec106a3528c018f62c5c55cab01e2e21810f3adc..897ed0c0e023e21f8fc9faa26baa600a04d790d9 100644 (file)
 #include "abstractclipitem.h"
 #include "kdenlivesettings.h"
 #include "customtrackscene.h"
+#include "customtrackview.h"
 
 #include <KDebug>
 
 #include <QPainter>
 #include <QStyleOptionGraphicsItem>
+#include <QDomDocument>
+#include <QMimeData>
 
 
 AbstractGroupItem::AbstractGroupItem(double fps): QGraphicsItemGroup(), m_fps(fps) {
     setZValue(2);
     setFlags(QGraphicsItem::ItemClipsToShape | QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
+    setAcceptDrops(true);
 }
 
 int AbstractGroupItem::type() const {
     return GROUPWIDGET;
 }
 
-const int AbstractGroupItem::track() const {
+int AbstractGroupItem::track() const {
     return (int)(scenePos().y() / KdenliveSettings::trackheight());
 }
 
@@ -89,7 +93,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
         newPos.setX(xpos);
 
         QPointF start = pos();
-        int startTrack = (start.y() + trackHeight / 2) / trackHeight;
+        //int startTrack = (start.y() + trackHeight / 2) / trackHeight;
         int newTrack = (newPos.y()) / trackHeight;
         //kDebug()<<"// GROUP NEW T:"<<newTrack<<",START T:"<<startTrack<<",MAX:"<<projectScene()->tracksCount() - 1;
         newTrack = qMin(newTrack, projectScene()->tracksCount() - (int)(boundingRect().height() + 5) / trackHeight);
@@ -175,3 +179,21 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
     return QGraphicsItemGroup::itemChange(change, value);
 }
 
+//virtual
+void AbstractGroupItem::dropEvent(QGraphicsSceneDragDropEvent * event) {
+    QString effects = QString(event->mimeData()->data("kdenlive/effectslist"));
+    QDomDocument doc;
+    doc.setContent(effects, true);
+    QDomElement e = doc.documentElement();
+    CustomTrackView *view = (CustomTrackView *) scene()->views()[0];
+    if (view) view->slotAddGroupEffect(e, this);
+}
+
+//virtual
+void AbstractGroupItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event) {
+    event->setAccepted(event->mimeData()->hasFormat("kdenlive/effectslist"));
+}
+
+void AbstractGroupItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) {
+    Q_UNUSED(event);
+}