Commit e1cd395a authored by Julius Künzel's avatar Julius Künzel
Browse files

Fix "Select Transition" should select mixes too

BUG: 440023
FIXED-IN: 21.12.0
parent 13b36b82
......@@ -2957,7 +2957,10 @@ void MainWindow::slotSelectTimelineClip()
void MainWindow::slotSelectTimelineTransition()
{
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, true);
bool res = getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, true, false, false);
if (!res) {
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineMix, true);
}
}
void MainWindow::slotDeselectTimelineClip()
......@@ -2967,7 +2970,10 @@ void MainWindow::slotDeselectTimelineClip()
void MainWindow::slotDeselectTimelineTransition()
{
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, false);
bool res = getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, false, false, false);
if (!res) {
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineMix, false);
}
}
void MainWindow::slotSelectAddTimelineClip()
......
......@@ -2377,6 +2377,11 @@ bool TrackModel::hasEndMix(int cid) const
return m_mixList.contains(cid);
}
int TrackModel::getSecondMixPartner(int cid) const
{
return hasEndMix(cid) ? m_mixList.find(cid).value() : -1;
}
QDomElement TrackModel::mixXml(QDomDocument &document, int cid) const
{
QDomElement container = document.createElement(QStringLiteral("mix"));
......
......@@ -320,6 +320,8 @@ protected:
bool hasStartMix(int cid) const;
/** @brief Returns true if this clip has a mix at end */
bool hasEndMix(int cid) const;
/** @brief Returns the cid of the second partner or -1 if the given clip has no end mix */
int getSecondMixPartner(int cid) const;
/** @brief Returns the cut position if the composition is over a cut between 2 clips, -1 otherwise
*/
int isOnCut(int cid);
......
......@@ -279,18 +279,53 @@ int TimelineController::selectedTrack() const
return selected_tracks.front().second;
}
void TimelineController::selectCurrentItem(ObjectType type, bool select, bool addToCurrent)
bool TimelineController::selectCurrentItem(ObjectType type, bool select, bool addToCurrent, bool showErrorMsg)
{
int currentClip = -1;
if (type == ObjectType::TimelineClip) {
currentClip = m_activeTrack == -2 ? m_model->getSubtitleByPosition(pCore->getTimelinePosition()) : m_model->getClipByPosition(m_activeTrack, pCore->getTimelinePosition());
} else if (type == ObjectType::TimelineComposition) {
currentClip = m_model->getCompositionByPosition(m_activeTrack, pCore->getTimelinePosition());
} else if (type == ObjectType::TimelineMix) {
if (m_activeTrack >= 0) {
currentClip = m_model->getClipByPosition(m_activeTrack, pCore->getTimelinePosition());
}
if (currentClip > -1) {
if (m_model->hasClipEndMix(currentClip)) {
int mixPartner = m_model->getTrackById_const(m_activeTrack)->getSecondMixPartner(currentClip);
int clipEnd = m_model->getClipPosition(currentClip) + m_model->getClipPlaytime(currentClip);
int mixStart = clipEnd - m_model->getMixDuration(mixPartner);
if (mixStart < pCore->getTimelinePosition() && pCore->getTimelinePosition() < clipEnd) {
if (select) {
m_model->requestMixSelection(mixPartner);
return true;
} else if (selectedMix() == mixPartner) {
m_model->requestClearSelection();
return true;
}
}
}
int delta = pCore->getTimelinePosition() - m_model->getClipPosition(currentClip);
if (m_model->getMixDuration(currentClip) >= delta) {
if (select) {
m_model->requestMixSelection(currentClip);
return true;
} else if (selectedMix() == currentClip) {
m_model->requestClearSelection();
return true;
}
return true;
} else {
currentClip = -1;
}
}
}
if (currentClip == -1) {
pCore->displayMessage(i18n("No item under timeline cursor in active track"), ErrorMessage, 500);
return;
if (showErrorMsg) {
pCore->displayMessage(i18n("No item under timeline cursor in active track"), ErrorMessage, 500);
}
return false;
}
if (!select) {
m_model->requestRemoveFromSelection(currentClip);
......@@ -302,6 +337,7 @@ void TimelineController::selectCurrentItem(ObjectType type, bool select, bool ad
showAsset(currentClip);
}
}
return true;
}
QList<int> TimelineController::selection() const
......
......@@ -99,8 +99,10 @@ public:
@param type is the type of the object (clip or composition)
@param select: true if the object should be selected and false if it should be deselected
@param addToCurrent: if true, the object will be added to the new selection
@param showErrorMsg inform the user that no item was selected
@return false if no item was found under timeline cursor in active track
*/
void selectCurrentItem(ObjectType type, bool select, bool addToCurrent = false);
bool selectCurrentItem(ObjectType type, bool select, bool addToCurrent = false, bool showErrorMsg = true);
/** @brief Select all timeline items
*/
......
Supports Markdown
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