]> git.sesse.net Git - kdenlive/commitdiff
Fix clip and transition move / resize through the double click move / resize widget
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 11 Feb 2009 10:00:15 +0000 (10:00 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Wed, 11 Feb 2009 10:00:15 +0000 (10:00 +0000)
svn path=/branches/KDE4/; revision=3043

src/clipdurationdialog.cpp
src/clipdurationdialog.h
src/customtrackview.cpp
src/customtrackview.h

index 73afbec7e30a1cab25e6f1088e85625b0cdd5541..36e676064383590474d8a3a8259c5a01b5fea325 100644 (file)
@@ -52,6 +52,35 @@ ClipDurationDialog::ClipDurationDialog(AbstractClipItem *clip, Timecode tc, QWid
 ClipDurationDialog::~ClipDurationDialog() {
 }
 
+void ClipDurationDialog::setMargins(GenTime min, GenTime max) {
+    m_min = min;
+    m_max = max;
+    connect(m_view.clip_position, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckStart()));
+    connect(m_view.clip_duration, SIGNAL(textChanged(const QString &)), this, SLOT(slotCheckDuration()));
+}
+
+void ClipDurationDialog::slotCheckStart() {
+    int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
+    int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    GenTime start(pos, m_fps);
+    GenTime duration(dur, m_fps);
+    if (start < m_min) {
+        m_view.clip_position->setText(m_tc.getTimecode(m_min, m_fps));
+    } else if (start + duration > m_max) {
+        m_view.clip_position->setText(m_tc.getTimecode(m_max - duration, m_fps));
+    }
+}
+
+void ClipDurationDialog::slotCheckDuration() {
+    int pos = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
+    int dur = m_tc.getFrameCount(m_view.clip_duration->text(), m_fps);
+    GenTime start(pos, m_fps);
+    GenTime duration(dur, m_fps);
+    if (start + duration > m_max) {
+        m_view.clip_duration->setText(m_tc.getTimecode(m_max - start, m_fps));
+    }
+}
+
 void ClipDurationDialog::slotPosUp() {
     int position = m_tc.getFrameCount(m_view.clip_position->text(), m_fps);
     //if (duration >= m_clip->duration().frames(m_fps)) return;
index 7791f7c75a15e2159af53c9b020bd943a2f5efb0..17cfe06b5d139eb5a3ff4cc287dde1bc3d3efc91 100644 (file)
@@ -37,9 +37,11 @@ public:
     GenTime startPos() const;
     GenTime cropStart() const;
     GenTime duration() const;
+    void setMargins(GenTime min, GenTime max);
 
 protected:
     void wheelEvent(QWheelEvent * event);
+
 private slots:
     void slotPosUp();
     void slotPosDown();
@@ -47,13 +49,16 @@ private slots:
     void slotDurDown();
     void slotCropUp();
     void slotCropDown();
+    void slotCheckDuration();
+    void slotCheckStart();
 
 private:
     Ui::ClipDurationDialog_UI m_view;
     AbstractClipItem *m_clip;
     Timecode m_tc;
     double m_fps;
-
+    GenTime m_min;
+    GenTime m_max;
 };
 
 
index 26dca3839b2f4471b080709dd8e1fabed8e1fe28..f665516830ee1ed167563370df24abfaa9513ee2 100644 (file)
@@ -862,38 +862,51 @@ void CustomTrackView::mouseDoubleClickEvent(QMouseEvent *event) {
         }
     } else if (m_dragItem) {
         ClipDurationDialog d(m_dragItem, m_document->timecode(), this);
+        GenTime minimum;
+        GenTime maximum;
+        if (m_dragItem->type() == TRANSITIONWIDGET) {
+            getTransitionAvailableSpace(m_dragItem, minimum, maximum);
+        } else {
+            getClipAvailableSpace(m_dragItem, minimum, maximum);
+        }
+        //kDebug()<<"// GOT MOVE POS: "<<minimum.frames(25)<<" - "<<maximum.frames(25);
+        d.setMargins(minimum, maximum);
         if (d.exec() == QDialog::Accepted) {
-            if (d.startPos() != m_dragItem->startPos()) {
-                if (m_dragItem->type() == AVWIDGET) {
-                    ItemInfo startInfo;
-                    startInfo.startPos = m_dragItem->startPos();
-                    startInfo.endPos = m_dragItem->endPos();
-                    startInfo.track = m_dragItem->track();
-                    ItemInfo endInfo;
-                    endInfo.startPos = d.startPos();
-                    endInfo.endPos = m_dragItem->endPos() + (endInfo.startPos - startInfo.startPos);
-                    endInfo.track = m_dragItem->track();
-                    MoveClipCommand *command = new MoveClipCommand(this, startInfo, endInfo, true);
-                    m_commandStack->push(command);
-                } else {
-                    //TODO: move transition
+            if (m_dragItem->type() == TRANSITIONWIDGET) {
+                // move & resize transition
+                ItemInfo startInfo;
+                startInfo.startPos = m_dragItem->startPos();
+                startInfo.endPos = m_dragItem->endPos();
+                startInfo.track = m_dragItem->track();
+                ItemInfo endInfo;
+                endInfo.startPos = d.startPos();
+                endInfo.endPos = endInfo.startPos + d.duration();
+                endInfo.track = m_dragItem->track();
+                MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, endInfo, true);
+                m_commandStack->push(command);
+            } else {
+                // move and resize clip
+                QUndoCommand *moveCommand = new QUndoCommand();
+                moveCommand->setText(i18n("Edit clip"));
+                ItemInfo clipInfo;
+                clipInfo.startPos = m_dragItem->startPos();
+                clipInfo.endPos = m_dragItem->endPos();
+                clipInfo.track = m_dragItem->track();
+                if (d.startPos() != m_dragItem->startPos()) {
+                    ItemInfo startInfo = clipInfo;
+                    clipInfo.startPos = d.startPos();
+                    clipInfo.endPos = m_dragItem->endPos() + (clipInfo.startPos - startInfo.startPos);
+                    clipInfo.track = m_dragItem->track();
+                    new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand);
                 }
-            }
-            if (d.duration() != m_dragItem->duration()) {
-                if (m_dragItem->type() == AVWIDGET) {
-                    ItemInfo startInfo;
-                    startInfo.startPos = m_dragItem->startPos();
-                    startInfo.endPos = m_dragItem->endPos();
-                    startInfo.track = m_dragItem->track();
+                if (d.duration() != m_dragItem->duration()) {
                     ItemInfo endInfo;
-                    endInfo.startPos = startInfo.startPos;
+                    endInfo.startPos = clipInfo.startPos;
                     endInfo.endPos = endInfo.startPos + d.duration();
                     endInfo.track = m_dragItem->track();
-                    ResizeClipCommand *command = new ResizeClipCommand(this, startInfo, endInfo, true);
-                    m_commandStack->push(command);
-                } else {
-                    //TODO: resize transition
+                    new ResizeClipCommand(this, clipInfo, endInfo, true, moveCommand);
                 }
+                m_commandStack->push(moveCommand);
             }
         }
     } else {
@@ -3538,4 +3551,34 @@ void CustomTrackView::clipNameChanged(const QString id, const QString name) {
     viewport()->update();
 }
 
+void CustomTrackView::getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum) {
+    minimum = GenTime();
+    maximum = GenTime();
+    QList<QGraphicsItem *> selection;
+    selection = m_scene->items(0, item->track() * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), 2);
+    selection.removeAll(item);
+    for (int i = 0; i < selection.count(); i++) {
+        AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
+        if (clip && clip->type() == AVWIDGET) {
+            if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
+            if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
+        }
+    }
+}
+
+void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum) {
+    minimum = GenTime();
+    maximum = GenTime();
+    QList<QGraphicsItem *> selection;
+    selection = m_scene->items(0, (item->track() + 1) * m_tracksHeight, sceneRect().width(), 2);
+    selection.removeAll(item);
+    for (int i = 0; i < selection.count(); i++) {
+        AbstractClipItem *clip = static_cast <AbstractClipItem *>(selection.at(i));
+        if (clip && clip->type() == TRANSITIONWIDGET) {
+            if (clip->endPos() <= item->startPos() && clip->endPos() > minimum) minimum = clip->endPos();
+            if (clip->startPos() > item->startPos() && (clip->startPos() < maximum || maximum == GenTime())) maximum = clip->startPos();
+        }
+    }
+}
+
 #include "customtrackview.moc"
index 951abb536016fb4e8e7ffadb4ea398a674b6d3ce..3b25d901d933f6e3bebdec58e84da367e79d030b 100644 (file)
@@ -223,6 +223,11 @@ private:
     bool insertPossible(AbstractGroupItem *group, const QPoint &pos) const;
     void resetSelectionGroup(bool selectItems = true);
     void groupSelectedItems(bool force = false);
+    /** Get available space for clip move (min and max free positions) */
+    void getClipAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
+    /** Get available space for transition move (min and max free positions) */
+    void getTransitionAvailableSpace(AbstractClipItem *item, GenTime &minimum, GenTime &maximum);
+
 
 private slots:
     void slotRefreshGuides();