]> git.sesse.net Git - kdenlive/blobdiff - src/customtrackview.cpp
Allow loading and saving of only one category of markers
[kdenlive] / src / customtrackview.cpp
index 93b4ef32b0585ff9d62ab8f1799000593d3734f4..396625b5deb4101770251f36944502611001d9c1 100644 (file)
@@ -980,27 +980,34 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     else if (dragGroup && dragGroup->isSelected())
         itemSelected = true;
 
-    if (event->modifiers() == Qt::ControlModifier || itemSelected == false) {
+    if ((event->modifiers() == Qt::ControlModifier) || itemSelected == false) {
         if (event->modifiers() != Qt::ControlModifier) {
             resetSelectionGroup(false);
             m_scene->clearSelection();
             // A refresh seems necessary otherwise in zoomed mode, some clips disappear
             viewport()->update();
-        } else resetSelectionGroup();
+        } else {
+           resetSelectionGroup();
+       }
         dragGroup = NULL;
         if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) {
             dragGroup = static_cast <AbstractGroupItem *>(m_dragItem->parentItem());
         }
         bool selected = !m_dragItem->isSelected();
-        if (dragGroup)
+        /*if (dragGroup)
             dragGroup->setSelected(selected);
-        else
+        else*/
             m_dragItem->setSelected(selected);
-
+       if (selected == false) {
+           m_dragItem = NULL;
+       }
         groupSelectedItems();
-        ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
-        updateClipTypeActions(dragGroup == NULL ? clip : NULL);
-        m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+       if (m_dragItem) { 
+           ClipItem *clip = static_cast <ClipItem *>(m_dragItem);
+           updateClipTypeActions(dragGroup == NULL ? clip : NULL);
+           m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1);
+       }
+       else updateClipTypeActions(NULL);
     }
 
     if (collisionClip != NULL || m_dragItem == NULL) {
@@ -1013,9 +1020,11 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
     }
 
     // If clicked item is selected, allow move
-    if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event);
+    //if (!(event->modifiers() | Qt::ControlModifier) && m_operationMode == NONE)
+    QGraphicsView::mousePressEvent(event);
 
-    m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
+    if (m_dragItem) {
+       m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y()));
     if (m_selectionGroup && m_dragItem->parentItem() == m_selectionGroup) {
         // all other modes break the selection, so the user probably wants to move it
         m_operationMode = MOVE;
@@ -1026,6 +1035,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
        }
         else m_operationMode = m_dragItem->operationMode(mapToScene(event->pos()));
     }
+    } else m_operationMode = NONE;
     m_controlModifier = (event->modifiers() == Qt::ControlModifier);
 
     // Update snap points
@@ -1772,7 +1782,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect)
     }
 }
 
-void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group)
+void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *group, AbstractClipItem *dropTarget)
 {
     QList<QGraphicsItem *> itemList = group->childItems();
     QUndoCommand *effectCommand = new QUndoCommand();
@@ -1811,6 +1821,12 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem *
         m_commandStack->push(effectCommand);
         setDocumentModified();
     } else delete effectCommand;
+    if (dropTarget) {
+       clearSelection(false);
+       m_dragItem = dropTarget;
+       m_dragItem->setSelected(true);
+       emit clipItemSelected(static_cast<ClipItem *>(dropTarget));
+    }
 }
 
 void CustomTrackView::slotAddEffect(ClipItem *clip, QDomElement effect)
@@ -1887,12 +1903,23 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track)
                        clearSelection(false);
                        clip->setSelected(true);
                        m_dragItem = clip;
-                       emit clipItemSelected(clip);
                    }
+                   emit clipItemSelected(clip);
                    break;
                }
            }
        }
+       else {
+           for (int i = 0; i < itemList.count(); i++) {
+               if (itemList.at(i)->type() == AVWIDGET) {
+                   ClipItem *clip = static_cast<ClipItem *>(itemList.at(i));
+                   if (clip->isMainSelectedClip()) {
+                       emit clipItemSelected(clip);
+                       break;
+                   }
+               }
+           }
+       }
     } else delete effectCommand;
 }
 
@@ -3438,7 +3465,7 @@ void CustomTrackView::checkScrolling()
 void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
 {
     if (m_moveOpMode == SEEK) m_moveOpMode = NONE;
-    QGraphicsView::mouseReleaseEvent(event);
+    if (!m_controlModifier) QGraphicsView::mouseReleaseEvent(event);
     setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
 #if QT_VERSION >= 0x040600
     if (m_dragItem) m_dragItem->setGraphicsEffect(NULL);
@@ -5224,16 +5251,23 @@ void CustomTrackView::clipEnd()
     }
 }
 
-void CustomTrackView::slotAddClipMarker(const QString &id, GenTime t, QString c, QUndoCommand *groupCommand)
+void CustomTrackView::slotAddClipMarker(const QString &id, CommentedTime newMarker, QUndoCommand *groupCommand)
 {
-    QString oldcomment = m_document->clipManager()->getClipById(id)->markerComment(t);
-    AddMarkerCommand *command = new AddMarkerCommand(this, oldcomment, c, id, t, groupCommand);
+    CommentedTime oldMarker = m_document->clipManager()->getClipById(id)->markerAt(newMarker.time());
+    if (oldMarker == CommentedTime()) {
+       oldMarker = newMarker;
+       oldMarker.setMarkerType(-1);
+    }
+    AddMarkerCommand *command = new AddMarkerCommand(this, oldMarker, newMarker, id, groupCommand);
     if (!groupCommand) m_commandStack->push(command);
 }
 
 void CustomTrackView::slotDeleteClipMarker(const QString &comment, const QString &id, const GenTime &position)
 {
-    AddMarkerCommand *command = new AddMarkerCommand(this, comment, QString(), id, position);
+    CommentedTime oldmarker(position, comment);
+    CommentedTime marker = oldmarker;
+    marker.setMarkerType(-1);
+    AddMarkerCommand *command = new AddMarkerCommand(this, oldmarker, marker, id);
     m_commandStack->push(command);
 }
 
@@ -5250,7 +5284,10 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id)
     deleteMarkers->setText("Delete clip markers");
 
     for (int i = 0; i < markers.size(); i++) {
-        new AddMarkerCommand(this, markers.at(i).comment(), QString(), id, markers.at(i).time(), deleteMarkers);
+       CommentedTime oldMarker = markers.at(i);
+       CommentedTime marker = oldMarker;
+       marker.setMarkerType(-1);
+        new AddMarkerCommand(this, oldMarker, marker, id, deleteMarkers);
     }
     m_commandStack->push(deleteMarkers);
 }
@@ -5259,18 +5296,39 @@ void CustomTrackView::slotSaveClipMarkers(const QString &id)
 {
     DocClipBase *base = m_document->clipManager()->getClipById(id);
     QList < CommentedTime > markers = base->commentedSnapMarkers();
-    QString data;
-    for (int i = 0; i < markers.count(); i++) {
-       data.append(QString::number(markers.at(i).time().seconds()));
-       data.append("\t");
-       data.append(QString::number(markers.at(i).time().seconds()));
-       data.append("\t");
-       data.append(markers.at(i).comment());
-       data.append("\n");
-    }
-    if (!data.isEmpty()) {
-       QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers"));
+    if (!markers.isEmpty()) {
+       // Set  up categories
+       QComboBox *cbox = new QComboBox;
+       cbox->insertItem(0, i18n("All categories"));
+       for (int i = 0; i < 5; ++i) {
+           cbox->insertItem(i + 1, i18n("Category %1", i));
+           cbox->setItemData(i + 1, CommentedTime::markerColor(i), Qt::DecorationRole);
+       }
+       cbox->setCurrentIndex(0);
+       KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox);
+       fd.setMode(KFile::File);
+       fd.setOperationMode(KFileDialog::Saving);
+       fd.exec();
+       QString url = fd.selectedFile();
+       //QString url = KFileDialog::getSaveFileName(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Save markers"));
        if (url.isEmpty()) return;
+
+       QString data;
+       int category = cbox->currentIndex() - 1;
+       for (int i = 0; i < markers.count(); i++) {
+           if (category >= 0) {
+               // Save only the markers in selected category
+               if (markers.at(i).markerType() != category) continue;
+           }
+           data.append(QString::number(markers.at(i).time().seconds()));
+           data.append("\t");
+           data.append(QString::number(markers.at(i).time().seconds()));
+           data.append("\t");
+           data.append(markers.at(i).comment());
+           data.append("\n");
+       }
+       delete cbox;
+       
        QFile file(url);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            emit displayMessage(i18n("Cannot open file %1", url), ErrorMessage);
@@ -5283,11 +5341,25 @@ void CustomTrackView::slotSaveClipMarkers(const QString &id)
 
 void CustomTrackView::slotLoadClipMarkers(const QString &id)
 {
-    KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file"));
+    QComboBox *cbox = new QComboBox;
+    for (int i = 0; i < 5; ++i) {
+       cbox->insertItem(i, i18n("Category %1", i));
+       cbox->setItemData(i, CommentedTime::markerColor(i), Qt::DecorationRole);
+    }
+    cbox->setCurrentIndex(KdenliveSettings::default_marker_type());
+    KFileDialog fd(KUrl("kfiledialog:///projectfolder"), "text/plain", this, cbox);
+    fd.setMode(KFile::File);
+    fd.setOperationMode(KFileDialog::Opening);
+    fd.exec();
+    QString url = fd.selectedFile();
+       
+    //KUrl url = KFileDialog::getOpenUrl(KUrl("kfiledialog:///projectfolder"), "text/plain", this, i18n("Load marker file"));
     if (url.isEmpty()) return;
-    QFile file(url.path());
+    int category = cbox->currentIndex();
+    delete cbox;
+    QFile file(url);
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
-       emit displayMessage(i18n("Cannot open file %1", url.fileName()), ErrorMessage);
+       emit displayMessage(i18n("Cannot open file %1", KUrl(url).fileName()), ErrorMessage);
        return;
     }
     QString data = QString::fromUtf8(file.readAll());
@@ -5326,19 +5398,24 @@ void CustomTrackView::slotLoadClipMarkers(const QString &id)
        }
        if (!markerText.isEmpty()) {
            // Marker found, add it
-           slotAddClipMarker(id, GenTime(time1), markerText, command);
-           if (time2 > 0 && time2 != time1) slotAddClipMarker(id, GenTime(time2), markerText, command);
+           //TODO: allow user to set a marker category
+           CommentedTime marker1(GenTime(time1), markerText, category);
+           slotAddClipMarker(id, marker1, command);
+           if (time2 > 0 && time2 != time1) {
+               CommentedTime marker2(GenTime(time2), markerText, category);
+               slotAddClipMarker(id, marker2, command);
+           }
        }
     }
     if (command->childCount() > 0) m_commandStack->push(command);
     else delete command;
 }
 
-void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString &comment)
+void CustomTrackView::addMarker(const QString &id, const CommentedTime marker)
 {
     DocClipBase *base = m_document->clipManager()->getClipById(id);
-    if (!comment.isEmpty()) base->addSnapMarker(pos, comment);
-    else base->deleteSnapMarker(pos);
+    if (marker.markerType() < 0) base->deleteSnapMarker(marker.time());
+    else base->addSnapMarker(marker);
     emit updateClipMarkers(base);
     setDocumentModified();
     viewport()->update();
@@ -5555,7 +5632,9 @@ void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect)
 {
     painter->setClipRect(rect);
     QPen pen1 = painter->pen();
-    pen1.setColor(palette().dark().color());
+    QColor lineColor = palette().dark().color();
+    lineColor.setAlpha(100);
+    pen1.setColor(lineColor);
     painter->setPen(pen1);
     double min = rect.left();
     double max = rect.right();