Various fixes for markers/guides

parent 288781b6
......@@ -1221,7 +1221,7 @@ void Bin::setMonitor(Monitor *monitor)
connect(m_monitor, SIGNAL(requestAudioThumb(QString)), this, SLOT(slotSendAudioThumb(QString)));
connect(m_monitor, &Monitor::refreshCurrentClip, this, &Bin::slotOpenCurrent);
connect(m_monitor, SIGNAL(updateClipMarker(QString, QList<CommentedTime>)), this, SLOT(slotAddClipMarker(QString, QList<CommentedTime>)));
connect(this, &Bin::openClip, [&](std::shared_ptr<ProjectClip> clip) { m_monitor->slotOpenClip(clip.get()); });
connect(this, &Bin::openClip, [&](std::shared_ptr<ProjectClip> clip) { m_monitor->slotOpenClip(clip); });
}
int Bin::getFreeFolderId()
......
......@@ -272,17 +272,30 @@ int MarkerListModel::rowCount(const QModelIndex &parent) const
return static_cast<int>(m_markerList.size());
}
CommentedTime MarkerListModel::getMarker(const GenTime &pos) const
CommentedTime MarkerListModel::getMarker(const GenTime &pos, bool *ok) const
{
READ_LOCK();
if (m_markerList.count(pos) <= 0) {
// return empty marker
*ok = false;
return CommentedTime();
}
*ok = true;
CommentedTime t(pos, m_markerList.at(pos).first, m_markerList.at(pos).second);
return t;
}
QList <CommentedTime> MarkerListModel::getAllMarkers() const
{
READ_LOCK();
QList <CommentedTime> markers;
for (const auto &marker : m_markerList) {
CommentedTime t(marker.first, marker.second.first, marker.second.second);
markers << t;
}
return markers;
}
bool MarkerListModel::hasMarker(int frame) const
{
READ_LOCK();
......
......@@ -88,7 +88,10 @@ public:
static std::array<QColor, 5> markerTypes;
/* @brief Returns a marker data at given pos */
CommentedTime getMarker(const GenTime &pos) const;
CommentedTime getMarker(const GenTime &pos, bool *ok) const;
/* @brief Returns all markers in model */
QList <CommentedTime> getAllMarkers() const;
/* @brief Returns true if a marker exists at given pos
Notice that add/remove queries are done in real time (gentime), but this request is made in frame
......
......@@ -671,17 +671,15 @@ void ProjectClip::addClipMarker(QList<CommentedTime> newMarkers, QUndoCommand *g
bool ProjectClip::deleteClipMarkers(QUndoCommand *command)
{
QList<CommentedTime> markers = commentedSnapMarkers();
QList<CommentedTime> markers = m_markerModel->getAllMarkers();
if (markers.isEmpty()) {
return false;
}
QList<CommentedTime> newMarkers;
for (int i = 0; i < markers.size(); ++i) {
CommentedTime marker = markers.at(i);
for (auto &marker : markers) {
marker.setMarkerType(-1);
newMarkers << marker;
}
new AddMarkerCommand(this, markers, newMarkers, command);
//TODO: group all markers in one undo/redo operation
addMarkers(markers);
return true;
}
......@@ -700,9 +698,9 @@ void ProjectClip::addMarkers(QList<CommentedTime> &markers)
emit refreshClipDisplay();
}
CommentedTime ProjectClip::getMarker(const GenTime &pos) const
CommentedTime ProjectClip::getMarker(const GenTime &pos, bool *ok) const
{
return m_markerModel->getMarker(pos);
return m_markerModel->getMarker(pos, ok);
}
/*QVariant ProjectClip::getData(DataType type) const
......
......@@ -198,7 +198,7 @@ public:
bool isSplittable() const;
/** @brief Returns a marker data at given pos */
CommentedTime getMarker(const GenTime &pos) const;
CommentedTime getMarker(const GenTime &pos, bool *ok) const;
protected:
friend class ClipModel;
......
......@@ -2275,17 +2275,14 @@ void MainWindow::slotAddClipMarker()
{
KdenliveDoc *project = pCore->projectManager()->current();
ClipController *clip = nullptr;
std::shared_ptr<ProjectClip> clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
pos = GenTime((int)((m_projectMonitor->position() - item->startPos() + item->cropStart()).frames(pCore->getCurrentFps()) * item->speed() + 0.5),
pCore->getCurrentFps());
clip = pCore->binController()->getController(item->getBinId()).get();
}
if (m_timelineTabs->getCurrentTimeline()) {
//TODO
//m_timelineTabs->getCurrentTimeline()->addMarkerInCurrentClip();
}
return;
} else {
clip = m_clipMonitor->currentController();
pos = m_clipMonitor->position();
......@@ -2294,11 +2291,11 @@ void MainWindow::slotAddClipMarker()
m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
return;
}
QString id = clip->clipId();
QString id = clip->AbstractProjectItem::clipId();
CommentedTime marker(pos, i18n("Marker"), KdenliveSettings::default_marker_type());
QPointer<MarkerDialog> d = new MarkerDialog(clip, marker, project->timecode(), i18n("Add Marker"), this);
QPointer<MarkerDialog> d = new MarkerDialog(clip.get(), marker, project->timecode(), i18n("Add Marker"), this);
if (d->exec() == QDialog::Accepted) {
pCore->bin()->slotAddClipMarker(id, QList<CommentedTime>() << d->newMarker());
clip->addMarkers(QList<CommentedTime>() << d->newMarker());
QString hash = clip->getClipHash();
if (!hash.isEmpty()) {
project->cacheImage(hash + QLatin1Char('#') + QString::number(d->newMarker().time().frames(pCore->getCurrentFps())), d->markerImage());
......@@ -2309,14 +2306,14 @@ void MainWindow::slotAddClipMarker()
void MainWindow::slotDeleteClipMarker(bool allowGuideDeletion)
{
ClipController *clip = nullptr;
std::shared_ptr<ProjectClip>clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
clip = pCore->binController()->getController(item->getBinId()).get();
clip = pCore->bin()->getBinClip(item->getBinId());
}
}
} else {
......@@ -2328,9 +2325,10 @@ void MainWindow::slotDeleteClipMarker(bool allowGuideDeletion)
return;
}
QString id = clip->clipId();
QString comment = clip->markerComment(pos);
if (comment.isEmpty()) {
QString id = clip->AbstractProjectItem::clipId();
bool markerFound = false;
CommentedTime marker = clip->getMarker(pos, &markerFound);
if (!markerFound) {
if (allowGuideDeletion && m_projectMonitor->isActive()) {
slotDeleteGuide();
} else {
......@@ -2338,17 +2336,19 @@ void MainWindow::slotDeleteClipMarker(bool allowGuideDeletion)
}
return;
}
pCore->bin()->deleteClipMarker(comment, id, pos);
marker.setMarkerType(-1);
QList <CommentedTime> markers = {marker};
clip->addMarkers(markers);
}
void MainWindow::slotDeleteAllClipMarkers()
{
ClipController *clip = nullptr;
std::shared_ptr<ProjectClip>clip(nullptr);
if (m_projectMonitor->isActive()) {
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
clip = pCore->binController()->getController(item->getBinId()).get();
clip = pCore->bin()->getBinClip(item->getBinId());
}
}
} else {
......@@ -2358,19 +2358,19 @@ void MainWindow::slotDeleteAllClipMarkers()
m_messageLabel->setMessage(i18n("Cannot find clip to remove marker"), ErrorMessage);
return;
}
pCore->bin()->deleteAllClipMarkers(clip->clipId());
pCore->bin()->deleteAllClipMarkers(clip->AbstractProjectItem::clipId());
}
void MainWindow::slotEditClipMarker()
{
ClipController *clip = nullptr;
std::shared_ptr<ProjectClip>clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
pos = (m_projectMonitor->position() - item->startPos() + item->cropStart()) / item->speed();
clip = pCore->binController()->getController(item->getBinId()).get();
clip = pCore->bin()->getBinClip(item->getBinId());
}
}
} else {
......@@ -2382,16 +2382,17 @@ void MainWindow::slotEditClipMarker()
return;
}
QString id = clip->clipId();
CommentedTime oldMarker = clip->markerAt(pos);
if (oldMarker == CommentedTime()) {
QString id = clip->AbstractProjectItem::clipId();
bool markerFound = false;
CommentedTime oldMarker = clip->getMarker(pos, &markerFound);
if (!markerFound) {
m_messageLabel->setMessage(i18n("No marker found at cursor time"), ErrorMessage);
return;
}
QPointer<MarkerDialog> d = new MarkerDialog(clip, oldMarker, pCore->projectManager()->current()->timecode(), i18n("Edit Marker"), this);
QPointer<MarkerDialog> d = new MarkerDialog(clip.get(), oldMarker, pCore->projectManager()->current()->timecode(), i18n("Edit Marker"), this);
if (d->exec() == QDialog::Accepted) {
pCore->bin()->slotAddClipMarker(id, QList<CommentedTime>() << d->newMarker());
clip->addMarkers(QList<CommentedTime>() << d->newMarker());
QString hash = clip->getClipHash();
if (!hash.isEmpty()) {
pCore->projectManager()->current()->cacheImage(hash + QLatin1Char('#') + QString::number(d->newMarker().time().frames(pCore->getCurrentFps())),
......@@ -2400,7 +2401,8 @@ void MainWindow::slotEditClipMarker()
if (d->newMarker().time() != pos) {
// remove old marker
oldMarker.setMarkerType(-1);
pCore->bin()->slotAddClipMarker(id, QList<CommentedTime>() << oldMarker);
QList <CommentedTime> markers = {oldMarker};
clip->addMarkers(markers);
}
}
delete d;
......@@ -2408,23 +2410,22 @@ void MainWindow::slotEditClipMarker()
void MainWindow::slotAddMarkerGuideQuickly()
{
if (!pCore->projectManager()->currentTimeline() || !pCore->projectManager()->current()) {
if (!m_timelineTabs->getCurrentTimeline() || !pCore->currentDoc()) {
return;
}
if (m_clipMonitor->isActive()) {
ClipController *clip = m_clipMonitor->currentController();
std::shared_ptr<ProjectClip>clip(m_clipMonitor->currentController());
GenTime pos = m_clipMonitor->position();
if (!clip) {
m_messageLabel->setMessage(i18n("Cannot find clip to add marker"), ErrorMessage);
return;
}
// TODO: allow user to set default marker category
CommentedTime marker(pos, pCore->projectManager()->current()->timecode().getDisplayTimecode(pos, false), KdenliveSettings::default_marker_type());
pCore->bin()->slotAddClipMarker(clip->clipId(), QList<CommentedTime>() << marker);
clip->addMarkers(QList<CommentedTime>() << marker);
} else {
pCore->projectManager()->currentTimeline()->projectView()->slotAddGuide(false);
m_timelineTabs->getCurrentTimeline()->controller()->switchGuide();
}
}
......
......@@ -510,7 +510,6 @@ ClipType ClipController::clipType() const
QPixmap ClipController::pixmap(int framePosition, int width, int height)
{
// int currentPosition = position();
m_masterProducer->seek(framePosition);
Mlt::Frame *frame = m_masterProducer->get_frame();
if (frame == nullptr || !frame->is_valid()) {
......@@ -545,7 +544,6 @@ QPixmap ClipController::pixmap(int framePosition, int width, int height)
QPixmap pixmap;
pixmap.convertFromImage(image);
delete frame;
return pixmap;
}
......
......@@ -895,8 +895,10 @@ void ClipPropertiesController::slotEditMarker()
auto current = m_markerTree->currentIndex();
if (!current.isValid()) return;
GenTime pos(markerModel->data(current, MarkerListModel::PosRole).toDouble());
CommentedTime marker = markerModel->getMarker(pos);
QScopedPointer<MarkerDialog> d(new MarkerDialog(m_controller, marker, m_tc, i18n("Add Marker"), this));
bool markerFound = false;
CommentedTime marker = markerModel->getMarker(pos, &markerFound);
Q_ASSERT(markerFound);
QScopedPointer<MarkerDialog> d(new MarkerDialog(m_controller, marker, m_tc, i18n("Edit Marker"), this));
if (d->exec() == QDialog::Accepted) {
marker = d->newMarker();
markerModel->editMarker(pos, marker.time(), marker.comment(), marker.markerType());
......
......@@ -968,7 +968,7 @@ void Monitor::slotExtractCurrentZone()
emit extractZone(m_controller->AbstractProjectItem::clipId());
}
ProjectClip *Monitor::currentController() const
std::shared_ptr<ProjectClip> Monitor::currentController() const
{
return m_controller;
}
......@@ -1331,7 +1331,7 @@ void Monitor::updateClipProducer(const QString &playlist)
render->play(1.0);
}
void Monitor::slotOpenClip(ProjectClip *controller, int in, int out)
void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int out)
{
m_controller = controller;
m_snaps.reset(new SnapModel());
......
......@@ -100,7 +100,7 @@ public:
void updateTimecodeFormat();
void updateMarkers();
/** @brief Controller for the clip currently displayed (only valid for clip monitor). */
ProjectClip *currentController() const;
std::shared_ptr<ProjectClip> currentController() const;
/** @brief Add timeline guides to the ruler and context menu */
void setGuides(const QMap<double, QString> &guides);
void reloadProducer(const QString &id);
......@@ -177,7 +177,7 @@ protected:
virtual QStringList mimeTypes() const;
private:
ProjectClip *m_controller;
std::shared_ptr<ProjectClip> m_controller;
/** @brief The QQuickView that handles our monitor display (video and qml overlay) **/
GLWidget *m_glMonitor;
/** @brief Container for our QQuickView monitor display (QQuickView needs to be embedded) **/
......@@ -284,7 +284,7 @@ public slots:
// void slotSetClipProducer(DocClipBase *clip, QPoint zone = QPoint(), bool forceUpdate = false, int position = -1);
void updateClipProducer(Mlt::Producer *prod);
void updateClipProducer(const QString &playlist);
void slotOpenClip(ProjectClip *controller, int in = -1, int out = -1);
void slotOpenClip(std::shared_ptr<ProjectClip> controller, int in = -1, int out = -1);
void slotRefreshMonitor(bool visible);
void slotSeek(int pos);
void stop() override;
......
......@@ -879,9 +879,6 @@ void ProjectManager::updateTimeline()
pCore->bin()->slotProducerReady(info, pCore->binController()->getController(id).get());
}
// TODO this is for testing purposes, remove.
m_project->getGuideModel()->addMarker(GenTime(10.), "Guide 1", 0);
m_project->getGuideModel()->addMarker(GenTime(15.), "Guide 2", 2);
m_project->loadThumbs();
pCore->monitorManager()->projectMonitor()->setProducer(m_mainTimelineModel->producer());
......
......@@ -61,8 +61,6 @@ MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const T
int width = Kdenlive::DefaultThumbHeight * m_dar;
QPixmap p(width, Kdenlive::DefaultThumbHeight);
p.fill(Qt::transparent);
QString colour = clip->getProducerProperty(QStringLiteral("colour"));
switch (m_clip->clipType()) {
case Video:
case AV:
......@@ -74,13 +72,10 @@ MarkerDialog::MarkerDialog(ClipController *clip, const CommentedTime &t, const T
case Image:
case Text:
case QText:
case Color:
m_previewTimer->start();
// p = m_clip->pixmap(m_in->getValue(), width, height);
break;
case Color:
colour = colour.replace(0, 2, QLatin1Char('#'));
p.fill(QColor(colour.left(7)));
break;
// UNKNOWN, AUDIO, VIRTUAL:
default:
p.fill(Qt::black);
......
......@@ -313,7 +313,9 @@ void TimelineController::setOutPoint()
void TimelineController::editMarker(const QString &cid, int frame)
{
std::shared_ptr<ProjectClip> clip = pCore->bin()->getBinClip(cid);
CommentedTime marker = clip->getMarker(GenTime(frame, pCore->getCurrentFps()));
bool markerFound = false;
CommentedTime marker = clip->getMarker(GenTime(frame, pCore->getCurrentFps()), &markerFound);
Q_ASSERT(markerFound);
QPointer<MarkerDialog> d = new MarkerDialog(clip.get(), marker, pCore->bin()->projectTimecode(), i18n("Edit Marker"), qApp->activeWindow());
if (d->exec() == QDialog::Accepted) {
QList<CommentedTime> markers;
......@@ -330,7 +332,9 @@ void TimelineController::editMarker(const QString &cid, int frame)
void TimelineController::editGuide(int frame)
{
CommentedTime marker = pCore->projectManager()->current()->getGuideModel().get()->getMarker(GenTime(frame, pCore->getCurrentFps()));
bool markerFound = false;
CommentedTime marker = pCore->projectManager()->current()->getGuideModel().get()->getMarker(GenTime(frame, pCore->getCurrentFps()), &markerFound);
Q_ASSERT(markerFound);
QPointer<MarkerDialog> d = new MarkerDialog(nullptr, marker, pCore->bin()->projectTimecode(), i18n("Edit Marker"), qApp->activeWindow());
if (d->exec() == QDialog::Accepted) {
QList<CommentedTime> markers;
......@@ -347,8 +351,12 @@ void TimelineController::editGuide(int frame)
void TimelineController::switchGuide(int frame)
{
CommentedTime marker = pCore->projectManager()->current()->getGuideModel().get()->getMarker(GenTime(frame, pCore->getCurrentFps()));
if (marker.time() == GenTime(0)) {
bool markerFound = false;
if (frame == -1) {
frame = m_position;
}
CommentedTime marker = pCore->projectManager()->current()->getGuideModel().get()->getMarker(GenTime(frame, pCore->getCurrentFps()), &markerFound);
if (!markerFound) {
marker = CommentedTime(GenTime(frame, pCore->getCurrentFps()), i18n("guide"));
} else {
marker.setMarkerType(-1);
......
......@@ -149,7 +149,7 @@ public:
Q_INVOKABLE void editGuide(int frame);
/* @brief Add a timeline guide
*/
Q_INVOKABLE void switchGuide(int frame);
Q_INVOKABLE void switchGuide(int frame = -1);
/* @brief Request monitor refresh
*/
Q_INVOKABLE void requestRefresh();
......
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