Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 2aa802a9 authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2] Snapping works for clip resize

parent 6e9f2939
......@@ -392,9 +392,39 @@ bool TimelineModel::requestGroupDeletion(int cid)
}
bool TimelineModel::requestClipResize(int cid, int size, bool right, bool logUndo)
bool TimelineModel::requestClipResize(int cid, int size, bool right, bool logUndo, bool snapping)
{
Q_ASSERT(isClip(cid));
if (snapping) {
Fun temp_undo = [](){return true;};
Fun temp_redo = [](){return true;};
int in = getClipPosition(cid);
int out = in + getClipPlaytime(cid) - 1;
m_snaps->ignore({in,out});
int proposed_size = -1;
if (right) {
int target_pos = in + size - 1;
int snapped_pos = m_snaps->getClosestPoint(target_pos);
//TODO Make the number of frames adjustable
if (snapped_pos != -1 && qAbs(target_pos - snapped_pos) <= 10) {
proposed_size = snapped_pos - in;
}
} else {
int target_pos = out + 1 - size;
int snapped_pos = m_snaps->getClosestPoint(target_pos);
//TODO Make the number of frames adjustable
if (snapped_pos != -1 && qAbs(target_pos - snapped_pos) <= 10) {
proposed_size = out + 2 - snapped_pos;
}
}
m_snaps->unIgnore();
if (proposed_size != -1) {
if (m_allClips[cid]->requestResize(proposed_size, right, temp_undo, temp_redo)) {
temp_undo(); //undo temp move
size = proposed_size;
}
}
}
Fun undo = [](){return true;};
Fun redo = [](){return true;};
Fun update_model = [cid, right, this]() {
......
......@@ -179,8 +179,9 @@ public:
@param size is the new size of the clip
@param right is true if we change the right side of the clip, false otherwise
@param logUndo if set to true, an undo object is created
@param snap if set to true, the resize order will be coerced to use the snapping grid
*/
bool requestClipResize(int cid, int size, bool right, bool logUndo = true);
bool requestClipResize(int cid, int size, bool right, bool logUndo = true, bool snap = false);
/* @brief Similar to requestClipResize but takes a delta instead of absolute size
This action is undoable
......
......@@ -156,7 +156,7 @@ bool TimelineWidget::trimClip(int clipIndex, int delta, bool right, bool logUndo
bool TimelineWidget::resizeClip(int clipIndex, int duration, bool right, bool logUndo)
{
return m_model->requestClipResize(clipIndex, duration, right, logUndo);
return m_model->requestClipResize(clipIndex, duration, right, logUndo, true);
}
void TimelineWidget::insertClip(int track, int position, QString data_str)
......
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