Commit 430ee962 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Select right part of a clip on clip cut

Fix various selection related crashes
parent bf29ac99
......@@ -647,6 +647,29 @@ void Core::clearSelection()
}
}
void Core::selectItem(int itemId)
{
if (m_mainWindow) {
m_mainWindow->getCurrentTimeline()->controller()->addSelection(itemId, true);
}
}
bool Core::isSelected(int itemId) const
{
if (m_mainWindow) {
return m_mainWindow->getCurrentTimeline()->controller()->selection().contains(itemId);
}
return false;
}
void Core::removeFromSelection(int itemId)
{
if (m_mainWindow) {
m_mainWindow->getCurrentTimeline()->controller()->removeSelection(itemId);
}
}
void Core::triggerAction(const QString &name)
{
QAction *action = m_mainWindow->actionCollection()->action(name);
......
......@@ -169,6 +169,9 @@ public:
void showClipKeyframes(ObjectId id, bool enable);
Mlt::Profile *thumbProfile();
void clearSelection();
void selectItem(int itemId);
bool isSelected(int itemId) const;
void removeFromSelection(int itemId);
/** @brief Returns the current project duration */
int projectDuration() const;
/** @brief Returns true if current project has some rendered timeline preview */
......
......@@ -126,6 +126,7 @@ void ClipModel::deregisterClipToBin()
{
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
binClip->deregisterTimelineClip(m_id);
pCore->removeFromSelection(m_id);
}
ClipModel::~ClipModel() {}
......
......@@ -141,8 +141,10 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
topElements.insert(root);
}
// We need to call clearSelection before attempting the split or the group split will be corrupted by the selection group (no undo support)
bool isSelected = pCore->isSelected(clipId);
pCore->clearSelection();
int count = 0;
QList <int> newIds;
for (int cid : clips) {
int start = timeline->getClipPosition(cid);
int duration = timeline->getClipPlaytime(cid);
......@@ -157,6 +159,7 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
}
// splitted elements go temporarily in the same group as original ones.
timeline->m_groups->setInGroupOf(newId, cid, undo, redo);
newIds << newId;
}
}
if (count > 0 && timeline->m_groups->isInGroup(clipId)) {
......@@ -173,6 +176,9 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
return false;
}
}
if (isSelected && !newIds.isEmpty()) {
pCore->selectItem(newIds.first());
}
return count > 0;
}
......
......@@ -496,6 +496,14 @@ bool TimelineItemModel::isInMultiSelection(int cid) const
return res;
}
bool TimelineItemModel::isSelected(int cid) const
{
if (m_temporarySelectionGroup == -1) {
return false;
}
return m_groups->getRootId(cid) == m_temporarySelectionGroup;
}
void TimelineItemModel::notifyChange(const QModelIndex &topleft, const QModelIndex &bottomright, bool start, bool duration, bool updateThumb)
{
QVector<int> roles;
......
......@@ -102,6 +102,7 @@ public:
/* @brief returns true if clip is in temporary selection group.
*/
bool isInMultiSelection(int cid) const;
bool isSelected(int cid) const;
virtual void _beginRemoveRows(const QModelIndex &, int, int) override;
virtual void _beginInsertRows(const QModelIndex &, int, int) override;
......
......@@ -7,7 +7,7 @@ import com.enums 1.0
Row {
id: thumbRow
anchors.fill: parent
visible: timeline.showThumbnails && mltService != 'color' && !isAudio
visible: timeline.showThumbnails && clipRoot.itemType != ProducerType.Color && !isAudio
opacity: parentTrack.isAudio || parentTrack.isHidden || clipStatus == ClipState.Disabled ? 0.2 : 1
property int thumbWidth: container.height * 16.0/9.0
property int scrollStart: Math.max(0, scrollView.flickableItem.contentX / timeline.scaleFactor - clipRoot.modelStart)
......
......@@ -1320,7 +1320,7 @@ Rectangle {
onFrameFormatChanged: ruler.adjustFormat()
onSelectionChanged: {
//cornerstone.selected = timeline.isMultitrackSelected()
if (dragProxy.draggedItem > -1 && !timeline.exists(dragProxy.draggedItem)) {
if (dragProxy.draggedItem > -1 && (!timeline.exists(dragProxy.draggedItem) || timeline.selection.indexOf(dragProxy.draggedItem) == -1)) {
endDrag()
}
var selectedTrack = timeline.selectedTrack()
......
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