mostly working rubber selection in timeline

parent f4192f9f
......@@ -58,6 +58,7 @@ TimelineModel::TimelineModel(Mlt::Profile *profile, std::weak_ptr<DocUndoStack>
, m_lock(QReadWriteLock::Recursive)
, m_timelineEffectsEnabled(true)
, m_id(getNextId())
, m_temporarySelectionGroup(-1)
{
// Create black background track
m_blackClip->set("id", "black_track");
......@@ -781,13 +782,18 @@ bool TimelineModel::requestClipTrim(int clipId, int delta, bool right, bool ripp
return requestItemResize(clipId, m_allClips[clipId]->getPlaytime() - delta, right, logUndo);
}
int TimelineModel::requestClipsGroup(const std::unordered_set<int> &ids, bool logUndo)
int TimelineModel::requestClipsGroup(const std::unordered_set<int> &ids, bool logUndo, bool temporarySelection)
{
QWriteLocker locker(&m_lock);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
if (temporarySelection && m_temporarySelectionGroup > -1) {
requestClipUngroup(m_temporarySelectionGroup, undo, redo);
m_temporarySelectionGroup = -1;
}
int result = requestClipsGroup(ids, undo, redo);
if (result > -1 && logUndo) {
m_temporarySelectionGroup = result;
PUSH_UNDO(undo, redo, i18n("Group clips"));
}
return result;
......
......@@ -365,7 +365,7 @@ public:
Typically, ids would be ids of clips, but for convenience, some of them can be ids of groups as well.
@param ids Set of ids to group
*/
int requestClipsGroup(const std::unordered_set<int> &ids, bool logUndo = true);
int requestClipsGroup(const std::unordered_set<int> &ids, bool logUndo = true, bool temporarySelection = false);
int requestClipsGroup(const std::unordered_set<int> &ids, Fun &undo, Fun &redo);
/* @brief Destruct the topmost group containing clip
......@@ -589,6 +589,9 @@ protected:
bool m_id; // id of the timeline itself
// id of the currently selected group in timeline, should be destroyed on each new selection
int m_temporarySelectionGroup;
// what follows are some virtual function that corresponds to the QML. They are implemented in TimelineItemModel
protected:
virtual void _beginRemoveRows(const QModelIndex &, int, int) = 0;
......
......@@ -170,7 +170,6 @@ Rectangle {
originalTrackId = clipRoot.trackId
startX = parent.x
clipRoot.forceActiveFocus();
clipRoot.clicked(clipRoot, mouse.modifiers === Qt.ShiftModifier)
}
onPositionChanged: {
if (mouse.y < 0 || mouse.y > height) {
......@@ -190,6 +189,7 @@ Rectangle {
} else {
parent.dropped(clipRoot)
}
clipRoot.clicked(clipRoot, mouse.modifiers === Qt.ShiftModifier)
}
onDoubleClicked: timeline.position = clipRoot.x / timeline.scaleFactor
onWheel: zoomByWheel(wheel)
......
......@@ -796,7 +796,7 @@ Rectangle {
currentTrack = track.DelegateModel.itemsIndex
if (shiftClick === 1) {
timeline.addSelection(clip.clipId)
} else {
} else if (!timeline.isInSelection(clip.clipId) ) {
timeline.selection = [ clip.clipId ]
}
timeline.showAsset(clip.clipId)
......
......@@ -31,6 +31,7 @@
#include "timeline2/model/timelineitemmodel.hpp"
#include "timeline2/model/trackmodel.hpp"
#include "timeline2/model/compositionmodel.hpp"
#include <timeline2/model/groupsmodel.hpp>
#include "timelinewidget.h"
#include "utils/KoIconUtils.h"
......@@ -80,6 +81,9 @@ void TimelineController::addSelection(int newSelection)
return;
}
m_selection.selectedClips << newSelection;
std::unordered_set<int> ids;
ids.insert(m_selection.selectedClips.cbegin(), m_selection.selectedClips.cend());
m_model->requestClipsGroup(ids, true, true);
emit selectionChanged();
if (!m_selection.selectedClips.isEmpty())
......@@ -152,6 +156,9 @@ void TimelineController::setSelection(const QList<int> &newSelection, int trackI
m_selection.selectedClips = newSelection;
m_selection.selectedTrack = trackIndex;
m_selection.isMultitrackSelected = isMultitrack;
std::unordered_set<int> ids;
ids.insert(m_selection.selectedClips.cbegin(), m_selection.selectedClips.cend());
m_model->requestClipsGroup(ids, true, true);
emit selectionChanged();
if (!m_selection.selectedClips.isEmpty())
......@@ -359,7 +366,6 @@ void TimelineController::editMarker(const QString &cid, int frame)
void TimelineController::editGuide(int frame)
{
bool markerFound = false;
if (frame == -1) {
frame = m_position;
}
......@@ -466,6 +472,7 @@ void TimelineController::selectItems(QVariantList arg, int startFrame, int endFr
for (int x: clipsToSelect) {
m_selection.selectedClips << x;
}
m_model->requestClipsGroup(clipsToSelect, true, true);
emit selectionChanged();
}
......@@ -627,3 +634,11 @@ void TimelineController::focusItem(int itemId)
int start = m_model->getItemPosition(itemId);
setPosition(start);
}
bool TimelineController::isInSelection(int cid) const
{
if (m_model->m_temporarySelectionGroup == -1 || !m_model->m_groups->isInGroup(cid)) {
return false;
}
return (m_model->m_groups->getRootId(cid) == m_model->m_temporarySelectionGroup);
}
......@@ -119,6 +119,8 @@ public:
Q_INVOKABLE void triggerAction(const QString &name);
Q_INVOKABLE bool isInSelection(int cid) const;
/* @brief Do we want to display video thumbnails
*/
bool showThumbnails() 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