Fix composition selection issues

Reintroduce the select current item feature
parent c74e7908
......@@ -2601,62 +2601,32 @@ void MainWindow::slotClearPreviewRender()
void MainWindow::slotSelectTimelineClip()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectClip(true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineClip, true);
}
void MainWindow::slotSelectTimelineTransition()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectTransition(true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, true);
}
void MainWindow::slotDeselectTimelineClip()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectClip(false, true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineClip, false);
}
void MainWindow::slotDeselectTimelineTransition()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectTransition(false, true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, false);
}
void MainWindow::slotSelectAddTimelineClip()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectClip(true, true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineClip, true, true);
}
void MainWindow::slotSelectAddTimelineTransition()
{
// TODO refac
/*
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->selectTransition(true, true);
}
*/
getCurrentTimeline()->controller()->selectCurrentItem(ObjectType::TimelineComposition, true, true);
}
void MainWindow::slotGroupClips()
......
......@@ -668,7 +668,7 @@ int GroupsModel::fromJson(const QJsonObject &o, Fun &undo, Fun &redo)
int id = -1;
if (leaf == QLatin1String("clip")) {
id = ptr->getClipByPosition(trackId, pos);
} else if (leaf == QLatin1String("clip")) {
} else if (leaf == QLatin1String("composition")) {
id = ptr->getCompositionByPosition(trackId, pos);
}
return id;
......
......@@ -857,6 +857,7 @@ bool TimelineModel::requestGroupDeletion(int clipId, Fun &undo, Fun &redo)
std::queue<int> group_queue;
group_queue.push(m_groups->getRootId(clipId));
std::unordered_set<int> all_clips;
std::unordered_set<int> all_compositions;
while (!group_queue.empty()) {
int current_group = group_queue.front();
if (m_temporarySelectionGroup == current_group) {
......@@ -870,6 +871,9 @@ bool TimelineModel::requestGroupDeletion(int clipId, Fun &undo, Fun &redo)
if (isClip(c)) {
all_clips.insert(c);
one_child = c;
} else if (isComposition(c)) {
all_compositions.insert(c);
one_child = c;
} else {
Q_ASSERT(isGroup(c));
one_child = c;
......@@ -891,6 +895,13 @@ bool TimelineModel::requestGroupDeletion(int clipId, Fun &undo, Fun &redo)
return false;
}
}
for (int compo : all_compositions) {
bool res = requestCompositionDeletion(compo, undo, redo);
if (!res) {
undo();
return false;
}
}
return true;
}
......
......@@ -545,8 +545,12 @@ int TrackModel::getCompositionByPosition(int position)
{
READ_LOCK();
for (const auto &comp : m_compoPos) {
if (comp.second == position) {
return comp.first;
if (comp.first == position) {
return comp.second;
} else if (comp.first < position) {
if (comp.first + m_allCompositions[comp.second]->getPlaytime() >= position) {
return comp.second;
}
}
}
return -1;
......
......@@ -238,6 +238,28 @@ std::unordered_set<int> TimelineController::getCurrentSelectionIds() const
return selection;
}
void TimelineController::selectCurrentItem(ObjectType type, bool select, bool addToCurrent)
{
QList<int> toSelect;
int currentClip = type == ObjectType::TimelineClip ? m_model->getClipByPosition(m_activeTrack, timelinePosition()) : m_model->getCompositionByPosition(m_activeTrack, timelinePosition());
if (currentClip == -1) {
pCore->displayMessage(i18n("No item under timeline cursor in active track"), InformationMessage, 500);
return;
}
if (addToCurrent || !select) {
toSelect = m_selection.selectedItems;
}
if (select) {
if (!toSelect.contains(currentClip)) {
toSelect << currentClip;
setSelection(toSelect);
}
} else if (toSelect.contains(currentClip)) {
toSelect.removeAll(currentClip);
setSelection(toSelect);
}
}
void TimelineController::setSelection(const QList<int> &newSelection, int trackIndex, bool isMultitrack)
{
if (newSelection != selection() || trackIndex != m_selection.selectedTrack || isMultitrack != m_selection.isMultitrackSelected) {
......
......@@ -349,6 +349,8 @@ public:
void resetTrackHeight();
/** @brief timeline preview params changed, reset */
void resetPreview();
/** @brief Select the clip in active track under cursor */
void selectCurrentItem(ObjectType type, bool select, bool addToCurrent = false);
public slots:
void selectMultitrack();
......
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