Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

First step in reimplementing library

parent edeb5047
......@@ -23,7 +23,7 @@
#include "doc/kthumb.h"
#include "kdenlivesettings.h"
#include "project/projectmanager.h"
#include "core.h"
#include <QAction>
#include <QDropEvent>
......@@ -243,6 +243,7 @@ void LibraryWidget::setupActions(const QList<QAction *> &list)
for (QAction *action : list) {
m_toolBar->addAction(action);
menuList << action;
connect(this, &LibraryWidget::enableAddSelection, action, &QAction::setEnabled);
}
// Create spacer
......@@ -260,6 +261,8 @@ void LibraryWidget::slotAddToLibrary()
if (!isEnabled()) {
return;
}
emit saveTimelineSelection(m_directory);
/*
if (!m_manager->hasSelection()) {
showMessage(i18n("Select clips in timeline for the Library"));
return;
......@@ -273,7 +276,7 @@ void LibraryWidget::slotAddToLibrary()
// TODO: warn and ask for overwrite / rename
}
QString fullPath = m_directory.absoluteFilePath(name + QStringLiteral(".mlt"));
m_manager->slotSaveSelection(fullPath);
m_manager->slotSaveSelection(fullPath);*/
}
void LibraryWidget::showMessage(const QString &text, KMessageWidget::MessageType type)
......
......@@ -209,6 +209,8 @@ private:
signals:
void addProjectClips(const QList<QUrl> &);
void thumbReady(const QString &, const QString &);
void enableAddSelection(bool);
void saveTimelineSelection(QDir);
};
#endif
......@@ -1415,6 +1415,7 @@ void MainWindow::setupActions()
QAction *sentToLibrary = addAction(QStringLiteral("send_library"), i18n("Add Timeline Selection to Library"), pCore->library(), SLOT(slotAddToLibrary()),
QIcon::fromTheme(QStringLiteral("bookmark-new")));
sentToLibrary->setEnabled(false);
pCore->library()->setupActions(QList<QAction *>() << sentToLibrary);
......@@ -1904,6 +1905,8 @@ void MainWindow::connectDocument()
KdenliveSettings::setProject_fps(pCore->getCurrentFps());
m_projectMonitor->slotLoadClipZone(project->zone());
connect(m_projectMonitor, &Monitor::multitrackView, getMainTimeline()->controller(), &TimelineController::slotMultitrackView);
connect(getMainTimeline()->controller(), &TimelineController::timelineClipSelected, pCore->library(), &LibraryWidget::enableAddSelection);
connect(pCore->library(), &LibraryWidget::saveTimelineSelection, getMainTimeline()->controller(), &TimelineController::saveTimelineSelection);
// TODO REFAC: reconnect to new timeline
/*
......
......@@ -307,20 +307,6 @@ void ProjectManager::saveRecentFiles()
config->sync();
}
void ProjectManager::slotSaveSelection(const QString &path)
{
Q_UNUSED(path)
// TODO refac : look at this
// m_trackView->projectView()->exportTimelineSelection(path);
}
bool ProjectManager::hasSelection() const
{
return false;
// TODO refac : look at this
// return m_trackView->projectView()->hasSelection();
}
bool ProjectManager::saveFileAs()
{
QFileDialog fd(pCore->window());
......
......@@ -61,8 +61,6 @@ public:
void prepareSave();
/** @brief Disable all bin effects in current project */
void disableBinEffects(bool disable);
/** @brief Returns true if there is a selected item in timeline */
bool hasSelection() const;
/** @brief Returns current project's xml scene */
QString projectSceneList(const QString &outputFolder);
/** @brief returns a default hd profile depending on timezone*/
......@@ -98,8 +96,6 @@ public slots:
/** @brief Shows a save file dialog for saving the project.
* @return Whether the file was saved. */
bool saveFileAs();
/** @brief Saves current timeline selection to an MLT playlist. */
void slotSaveSelection(const QString &path = QString());
/** @brief Set properties to match outputFileName and save the document.
* Creates an autosave version of the output file too, at
......
......@@ -28,6 +28,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "timelineitemmodel.hpp"
#include "trackmodel.hpp"
#include <QInputDialog>
#include <QApplication>
#include <QDebug>
#include <klocalizedstring.h>
......@@ -783,3 +785,63 @@ void TimelineFunctions::enableMultitrackView(std::shared_ptr<TimelineItemModel>
field->unlock();
timeline->requestMonitorRefresh();
}
void TimelineFunctions::saveTimelineSelection(std::shared_ptr<TimelineItemModel> timeline, QList <int> selection, QDir targetDir)
{
bool ok;
QString name = QInputDialog::getText(qApp->activeWindow(), i18n("Add Clip to Library"), i18n("Enter a name for the clip in Library"), QLineEdit::Normal, QString(), &ok);
if (name.isEmpty() || !ok) {
return;
}
if (targetDir.exists(name + QStringLiteral(".mlt"))) {
// TODO: warn and ask for overwrite / rename
}
int offset = -1;
QString fullPath = targetDir.absoluteFilePath(name + QStringLiteral(".mlt"));
// Build a copy of selected tracks.
QMap <int, int> sourceTracks;
for (int i : selection) {
int sourceTrack = timeline->getItemTrackId(i);
int clipPos = timeline->getItemPosition(i);
if (offset < 0 || clipPos < offset) {
offset = clipPos;
}
int trackPos = timeline->getTrackMltIndex(sourceTrack);
if (!sourceTracks.contains(trackPos)) {
sourceTracks.insert(trackPos, sourceTrack);
}
}
// Build target timeline
Mlt::Tractor newTractor(*timeline->m_tractor->profile());
QScopedPointer<Mlt::Field>field(newTractor.field());
int ix = 0;
QMapIterator<int, int> i(sourceTracks);
while (i.hasNext()) {
i.next();
QScopedPointer<Mlt::Playlist> newTrackPlaylist(new Mlt::Playlist(*newTractor.profile()));
int trackId = i.value();
std::shared_ptr<TrackModel> track = timeline->getTrackById_const(trackId);
for (int itemId : selection) {
if (timeline->getItemTrackId(itemId) == trackId) {
// Copy clip on the destination track
if (timeline->isClip(itemId)) {
int clip_position = timeline->m_allClips[itemId]->getPosition();
auto clip_loc = track->getClipIndexAt(clip_position);
int target_track = clip_loc.first;
int target_clip = clip_loc.second;
QSharedPointer<Mlt::Producer> clip = track->getClipProducer(target_clip);
newTrackPlaylist->insert_at(clip_position - offset, clip.data());
} else {
// Composition
// TODO
}
}
}
newTractor.set_track(*newTrackPlaylist, ix);
ix++;
}
Mlt::Consumer xmlConsumer(*newTractor.profile(), ("xml:" + fullPath).toUtf8().constData());
xmlConsumer.set("terminate_on_pause", 1);
xmlConsumer.connect(newTractor);
xmlConsumer.run();
}
......@@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <memory>
#include <unordered_set>
#include <QDir>
/**
* @namespace TimelineFunction
* @brief This namespace contains a list of static methods for advanced timeline editing features
......@@ -90,6 +92,7 @@ struct TimelineFunctions
static bool requestSplitVideo(std::shared_ptr<TimelineItemModel> timeline, int clipId, int videoTarget);
static void setCompositionATrack(std::shared_ptr<TimelineItemModel> timeline, int cid, int aTrack);
static void enableMultitrackView(std::shared_ptr<TimelineItemModel> timeline, bool enable);
static void saveTimelineSelection(std::shared_ptr<TimelineItemModel> timeline, QList <int> selection, QDir targetDir);
};
#endif
......@@ -611,6 +611,19 @@ int TrackModel::getClipByPosition(int position)
return prod->get_int("_kdenlive_cid");
}
QSharedPointer<Mlt::Producer> TrackModel::getClipProducer(int clipId)
{
READ_LOCK();
QSharedPointer<Mlt::Producer> prod(nullptr);
if (m_playlists[0].count() > 0) {
prod = QSharedPointer<Mlt::Producer>(m_playlists[0].get_clip(clipId));
}
if ((!prod || prod->is_blank()) && m_playlists[1].count() > 0) {
prod = QSharedPointer<Mlt::Producer>(m_playlists[1].get_clip(clipId));
}
return prod;
}
int TrackModel::getCompositionByPosition(int position)
{
READ_LOCK();
......
......@@ -201,6 +201,7 @@ protected:
/* @brief This is an helper function that returns the sub-playlist in which the clip is inserted, along with its index in the playlist
@param position the position of the target clip*/
std::pair<int, int> getClipIndexAt(int position);
QSharedPointer<Mlt::Producer> getClipProducer(int clipId);
/* @brief This is an helper function that checks in all playlists if the given position is a blank */
bool isBlankAt(int position);
......
......@@ -1848,6 +1848,7 @@ void TimelineController::updateClipActions()
for(QAction *act : clipActions) {
act->setEnabled(false);
}
emit timelineClipSelected(false);
return;
}
std::shared_ptr<ClipModel> clip(nullptr);
......@@ -1880,6 +1881,7 @@ void TimelineController::updateClipActions()
}
act->setEnabled(enableAction);
}
emit timelineClipSelected(clip != nullptr);
}
const QString TimelineController::getAssetName(const QString &assetId, bool isTransition)
......@@ -2102,3 +2104,8 @@ void TimelineController::slotMultitrackView(bool enable)
{
TimelineFunctions::enableMultitrackView(m_model, enable);
}
void TimelineController::saveTimelineSelection(QDir targetDir)
{
TimelineFunctions::saveTimelineSelection(m_model, m_selection.selectedItems, targetDir);
}
......@@ -426,6 +426,8 @@ public slots:
void checkDuration();
/** @brief Dis / enable multi track view. */
void slotMultitrackView(bool enable);
/** @brief Save timeline selcted clips to target folder. */
void saveTimelineSelection(QDir targetDir);
private slots:
void slotUpdateSelection(int itemId);
......@@ -498,6 +500,9 @@ signals:
void workingPreviewChanged();
void useRulerChanged();
void updateZoom(double);
/* @brief emitted when timeline selection changes, true if a clip is selected
*/
void timelineClipSelected(bool);
Q_INVOKABLE void ungrabHack();
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment