From 0ecaca991853809ccb21f4232a7edfee3e660237 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sat, 20 Oct 2012 17:03:02 +0200 Subject: [PATCH] Allow loading and saving of only one category of markers --- src/clipproperties.cpp | 15 ++++--- src/customtrackview.cpp | 67 ++++++++++++++++++++++++-------- src/kdenlivesettings.kcfg | 5 +++ src/mainwindow.cpp | 4 +- src/markerdialog.cpp | 1 + src/widgets/clipproperties_ui.ui | 3 ++ 6 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/clipproperties.cpp b/src/clipproperties.cpp index 3fd5b351..99166634 100644 --- a/src/clipproperties.cpp +++ b/src/clipproperties.cpp @@ -773,11 +773,16 @@ void ClipProperties::slotEditMarker() void ClipProperties::slotDeleteMarker() { QList < CommentedTime > marks = m_clip->commentedSnapMarkers(); - int pos = m_view.markers_list->currentIndex().row(); - if (pos < 0 || pos > marks.count() - 1) return; - CommentedTime marker = marks.at(pos); - marker.setMarkerType(-1); - emit addMarker(m_clip->getId(), marker); + QList < CommentedTime > toDelete; + for (int i = 0; i < marks.count(); i++) { + if (m_view.markers_list->topLevelItem(i)->isSelected()) { + CommentedTime marker = marks.at(i); + marker.setMarkerType(-1); + toDelete << marker; + } + } + for (int i = 0; i < toDelete.count(); i++) + emit addMarker(m_clip->getId(), toDelete.at(i)); } const QString &ClipProperties::clipId() const diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index a82b48bb..396625b5 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -5296,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); @@ -5320,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()); @@ -5364,10 +5399,10 @@ void CustomTrackView::slotLoadClipMarkers(const QString &id) if (!markerText.isEmpty()) { // Marker found, add it //TODO: allow user to set a marker category - CommentedTime marker1(GenTime(time1), markerText); + CommentedTime marker1(GenTime(time1), markerText, category); slotAddClipMarker(id, marker1, command); if (time2 > 0 && time2 != time1) { - CommentedTime marker2(GenTime(time2), markerText); + CommentedTime marker2(GenTime(time2), markerText, category); slotAddClipMarker(id, marker2, command); } } diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index 96a4f57f..ca309317 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -821,6 +821,11 @@ true + + + 0 + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9d6e64d0..5f9e0661 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2835,7 +2835,7 @@ void MainWindow::slotAddClipMarker() return; } QString id = clip->getId(); - CommentedTime marker(pos, i18n("Marker")); + CommentedTime marker(pos, i18n("Marker"), KdenliveSettings::default_marker_type()); QPointer d = new MarkerDialog(clip, marker, m_activeDocument->timecode(), i18n("Add Marker"), this); if (d->exec() == QDialog::Accepted) @@ -2948,7 +2948,7 @@ void MainWindow::slotAddMarkerGuideQuickly() return; } //TODO: allow user to set default marker category - CommentedTime marker(pos, m_activeDocument->timecode().getDisplayTimecode(pos, false)); + CommentedTime marker(pos, m_activeDocument->timecode().getDisplayTimecode(pos, false), KdenliveSettings::default_marker_type()); m_activeTimeline->projectView()->slotAddClipMarker(clip->getId(), marker); } else { m_activeTimeline->projectView()->slotAddGuide(false); diff --git a/src/markerdialog.cpp b/src/markerdialog.cpp index 5846662f..e789cc15 100644 --- a/src/markerdialog.cpp +++ b/src/markerdialog.cpp @@ -128,6 +128,7 @@ void MarkerDialog::slotUpdateThumb() CommentedTime MarkerDialog::newMarker() { + KdenliveSettings::setDefault_marker_type(marker_type->currentIndex()); return CommentedTime(m_in->gentime(), marker_comment->text(), marker_type->currentIndex()); } diff --git a/src/widgets/clipproperties_ui.ui b/src/widgets/clipproperties_ui.ui index 21544e81..c926aa92 100644 --- a/src/widgets/clipproperties_ui.ui +++ b/src/widgets/clipproperties_ui.ui @@ -418,6 +418,9 @@ true + + QAbstractItemView::ExtendedSelection + false -- 2.39.2