Disable marker actions when timeline cursor is not on selected clip

Fixes #564
parent 89b7f9ee
Pipeline #16005 passed with stage
in 15 minutes and 34 seconds
......@@ -1468,19 +1468,26 @@ void MainWindow::setupActions()
QIcon::fromTheme(QStringLiteral("edit-select")), Qt::SHIFT + Qt::Key_Minus);
addAction(QStringLiteral("select_add_timeline_transition"), i18n("Add Transition To Selection"), this, SLOT(slotSelectAddTimelineTransition()),
QIcon::fromTheme(QStringLiteral("edit-select")), Qt::ALT + Qt::SHIFT + Qt::Key_Plus);
addAction(QStringLiteral("add_clip_marker"), i18n("Add Marker"), this, SLOT(slotAddClipMarker()), QIcon::fromTheme(QStringLiteral("bookmark-new")));
addAction(QStringLiteral("delete_clip_marker"), i18n("Delete Marker"), this, SLOT(slotDeleteClipMarker()), QIcon::fromTheme(QStringLiteral("edit-delete")));
addAction(QStringLiteral("delete_all_clip_markers"), i18n("Delete All Markers"), this, SLOT(slotDeleteAllClipMarkers()),
QIcon::fromTheme(QStringLiteral("edit-delete")));
QAction *editClipMarker = addAction(QStringLiteral("edit_clip_marker"), i18n("Edit Marker"), this, SLOT(slotEditClipMarker()),
QIcon::fromTheme(QStringLiteral("document-properties")));
editClipMarker->setData(QStringLiteral("edit_marker"));
addAction(QStringLiteral("add_marker_guide_quickly"), i18n("Add Marker/Guide quickly"), this, SLOT(slotAddMarkerGuideQuickly()),
QIcon::fromTheme(QStringLiteral("bookmark-new")), Qt::Key_Asterisk);
// Clip actions. We set some category info on the action data to enable/disable it contextually in timelinecontroller
KActionCategory *clipActionCategory = new KActionCategory(i18n("Current Selection"), actionCollection());
QAction *addMarker = addAction(QStringLiteral("add_clip_marker"), i18n("Add Marker"), this, SLOT(slotAddClipMarker()), QIcon::fromTheme(QStringLiteral("bookmark-new")), QKeySequence(), clipActionCategory);
addMarker->setData('P');
QAction *delMarker = addAction(QStringLiteral("delete_clip_marker"), i18n("Delete Marker"), this, SLOT(slotDeleteClipMarker()), QIcon::fromTheme(QStringLiteral("edit-delete")), QKeySequence(), clipActionCategory);
delMarker->setData('P');
QAction *editClipMarker = addAction(QStringLiteral("edit_clip_marker"), i18n("Edit Marker"), this, SLOT(slotEditClipMarker()),
QIcon::fromTheme(QStringLiteral("document-properties")), QKeySequence(), clipActionCategory);
editClipMarker->setObjectName(QStringLiteral("edit_marker"));
editClipMarker->setData('P');
QAction *splitAudio = addAction(QStringLiteral("clip_split"), i18n("Split Audio"), this, SLOT(slotSplitAV()),
QIcon::fromTheme(QStringLiteral("document-new")), QKeySequence(), clipActionCategory);
// "S" will be handled specifically to change the action name depending on current selection
......
......@@ -509,7 +509,7 @@ void Monitor::setupMenu(QMenu *goMenu, QMenu *overlayMenu, QAction *playZone, QA
m_contextMenu->addMenu(markerMenu);
QList<QAction *> list = markerMenu->actions();
for (int i = 0; i < list.count(); ++i) {
if (list.at(i)->data().toString() == QLatin1String("edit_marker")) {
if (list.at(i)->objectName() == QLatin1String("edit_marker")) {
m_editMarker = list.at(i);
break;
}
......
......@@ -1119,14 +1119,12 @@ void TimelineController::cutClipUnderCursor(int position, int track)
const auto selection = m_model->getCurrentSelection();
if (track == -1) {
for (int cid : selection) {
if (m_model->isClip(cid)) {
if (m_model->isClip(cid) && positionIsInItem(cid)) {
if (TimelineFunctions::requestClipCut(m_model, cid, position)) {
foundClip = true;
// Cutting clips in the selection group is handled in TimelineFunctions
break;
}
} else {
qDebug() << "//// TODO: COMPOSITION CUT!!!";
}
}
}
......@@ -1204,14 +1202,25 @@ int TimelineController::getMouseTrack()
return returnedValue.toInt();
}
void TimelineController::refreshItem(int id)
bool TimelineController::positionIsInItem(int id)
{
int in = m_model->getItemPosition(id);
int position = pCore->getTimelinePosition();
if (in > position || (m_model->isClip(id) && m_model->m_allClips[id]->isAudioOnly())) {
return;
if (in > position) {
return false;
}
if (position <= in + m_model->getItemPlaytime(id)) {
return true;
}
return false;
}
void TimelineController::refreshItem(int id)
{
if (m_model->isClip(id) && m_model->m_allClips[id]->isAudioOnly()) {
return;
}
if (positionIsInItem(id)) {
pCore->requestMonitorRefresh();
}
}
......@@ -2343,6 +2352,7 @@ void TimelineController::updateClipActions()
if (m_model->isClip(item)) {
clip = m_model->getClipPtr(item);
}
bool enablePositionActions = positionIsInItem(item);
for (QAction *act : clipActions) {
bool enableAction = true;
const QChar actionData = act->data().toChar();
......@@ -2370,6 +2380,8 @@ void TimelineController::updateClipActions()
}
} else if (actionData == QLatin1Char('C') && clip == nullptr) {
enableAction = false;
} else if (actionData == QLatin1Char('P')) {
enableAction = enablePositionActions;
}
act->setEnabled(enableAction);
}
......
......@@ -395,6 +395,9 @@ public:
/* @brief Seeks to a clip start (or end) based on it's clip id
*/
void seekToClip(int cid, bool seekToEnd);
/* @brief Returns true if timeline cursor is inside the item
*/
bool positionIsInItem(int id);
/* @brief Returns the number of tracks (audioTrakcs, videoTracks)
*/
QPoint getTracksCount() const;
......
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