Fix clip marker menu. Fixes #168

parent 876d46d8
Pipeline #2971 passed with stage
in 14 minutes and 6 seconds
......@@ -2215,7 +2215,11 @@ void MainWindow::slotAddClipMarker()
std::shared_ptr<ProjectClip> clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
return;
int selectedClip = getMainTimeline()->controller()->getMainSelectedClip();
if (selectedClip > -1) {
getMainTimeline()->controller()->addMarker(selectedClip);
return;
}
} else {
clip = m_clipMonitor->currentController();
pos = GenTime(m_clipMonitor->position(), pCore->getCurrentFps());
......@@ -2233,16 +2237,11 @@ void MainWindow::slotDeleteClipMarker(bool allowGuideDeletion)
std::shared_ptr<ProjectClip> clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
// TODO refac retrieve active clip
/*
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
pos = (GenTime(m_projectMonitor->position(), pCore->getCurrentFps()) - item->startPos() + item->cropStart()) / item->speed();
clip = pCore->bin()->getBinClip(item->getBinId());
}
int selectedClip = getMainTimeline()->controller()->getMainSelectedClip();
if (selectedClip > -1) {
getMainTimeline()->controller()->deleteMarker(selectedClip);
return;
}
*/
} else {
clip = m_clipMonitor->currentController();
pos = GenTime(m_clipMonitor->position(), pCore->getCurrentFps());
......@@ -2270,15 +2269,11 @@ void MainWindow::slotDeleteAllClipMarkers()
{
std::shared_ptr<ProjectClip> clip(nullptr);
if (m_projectMonitor->isActive()) {
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
clip = pCore->bin()->getBinClip(item->getBinId());
}
int selectedClip = getMainTimeline()->controller()->getMainSelectedClip();
if (selectedClip > -1) {
getMainTimeline()->controller()->deleteAllMarkers(selectedClip);
return;
}
*/
} else {
clip = m_clipMonitor->currentController();
}
......@@ -2298,16 +2293,11 @@ void MainWindow::slotEditClipMarker()
std::shared_ptr<ProjectClip> clip(nullptr);
GenTime pos;
if (m_projectMonitor->isActive()) {
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
ClipItem *item = pCore->projectManager()->currentTimeline()->projectView()->getActiveClipUnderCursor();
if (item) {
pos = (GenTime(m_projectMonitor->position(), pCore->getCurrentFps()) - item->startPos() + item->cropStart()) / item->speed();
clip = pCore->bin()->getBinClip(item->getBinId());
}
int selectedClip = getMainTimeline()->controller()->getMainSelectedClip();
if (selectedClip > -1) {
getMainTimeline()->controller()->editMarker(selectedClip);
return;
}
*/
} else {
clip = m_clipMonitor->currentController();
pos = GenTime(m_clipMonitor->position(), pCore->getCurrentFps());
......@@ -2345,7 +2335,14 @@ void MainWindow::slotAddMarkerGuideQuickly()
CommentedTime marker(pos, pCore->currentDoc()->timecode().getDisplayTimecode(pos, false), KdenliveSettings::default_marker_type());
clip->getMarkerModel()->addMarker(marker.time(), marker.comment(), marker.markerType());
} else {
getMainTimeline()->controller()->switchGuide();
int selectedClip = getMainTimeline()->controller()->getMainSelectedClip();
if (selectedClip == -1) {
// Add timeline guide
getMainTimeline()->controller()->switchGuide();
} else {
// Add marker to main clip
getMainTimeline()->controller()->addQuickMarker(selectedClip);
}
}
}
......
......@@ -405,6 +405,30 @@ void TimelineController::deleteSelectedClips()
m_model->requestItemDeletion(*sel.begin());
}
int TimelineController::getMainSelectedClip()
{
auto sel = m_model->getCurrentSelection();
if (sel.empty() || sel.size() > 2) {
return -1;
}
int itemId = *(sel.begin());
if (sel.size() == 2) {
int parentGroup = m_model->m_groups->getRootId(itemId);
if (parentGroup == -1 || m_model->m_groups->getType(parentGroup) != GroupType::AVSplit) {
return -1;
}
}
if (m_model->isClip(itemId)) {
int position = timelinePosition();
int start = m_model->getClipPosition(itemId);
int end = start + m_model->getClipPlaytime(itemId);
if (position >= start && position <= end) {
return itemId;
}
}
return -1;
}
void TimelineController::copyItem()
{
std::unordered_set<int> selectedIds = m_model->getCurrentSelection();
......@@ -621,6 +645,9 @@ void TimelineController::setOutPoint()
void TimelineController::editMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
if (position == -1) {
position = timelinePosition();
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to edit marker"), InformationMessage, 500);
return;
......@@ -633,6 +660,9 @@ void TimelineController::editMarker(int cid, int position)
void TimelineController::addMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
if (position == -1) {
position = timelinePosition();
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to add marker"), InformationMessage, 500);
return;
......@@ -645,6 +675,9 @@ void TimelineController::addMarker(int cid, int position)
void TimelineController::addQuickMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
if (position == -1) {
position = timelinePosition();
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to add marker"), InformationMessage, 500);
return;
......@@ -658,6 +691,9 @@ void TimelineController::addQuickMarker(int cid, int position)
void TimelineController::deleteMarker(int cid, int position)
{
Q_ASSERT(m_model->isClip(cid));
if (position == -1) {
position = timelinePosition();
}
if (position < m_model->getClipPosition(cid) || position > (m_model->getClipPosition(cid) + m_model->getClipPlaytime(cid))) {
pCore->displayMessage(i18n("Cannot find clip to remove marker"), InformationMessage, 500);
return;
......
......@@ -208,6 +208,11 @@ public:
Q_INVOKABLE void triggerAction(const QString &name);
/* @brief Returns id of the timeline selcted clip if there is only 1 clip selected
* or an AVSplit group. Returns -1 otherwise
*/
int getMainSelectedClip();
/* @brief Do we want to display video thumbnails
*/
bool showThumbnails() const;
......@@ -231,16 +236,16 @@ public:
Q_INVOKABLE void unGroupSelection(int cid = -1);
/* @brief Ask for edit marker dialog
*/
Q_INVOKABLE void editMarker(int cid, int position);
Q_INVOKABLE void editMarker(int cid, int position = -1);
/* @brief Ask for marker add dialog
*/
Q_INVOKABLE void addMarker(int cid, int position);
Q_INVOKABLE void addMarker(int cid, int position = -1);
/* @brief Ask for quick marker add (without dialog)
*/
Q_INVOKABLE void addQuickMarker(int cid, int position);
Q_INVOKABLE void addQuickMarker(int cid, int position = -1);
/* @brief Ask for marker delete
*/
Q_INVOKABLE void deleteMarker(int cid, int position);
Q_INVOKABLE void deleteMarker(int cid, int position = -1);
/* @brief Ask for all markers delete
*/
Q_INVOKABLE void deleteAllMarkers(int cid);
......
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