Commit 7eaf219e authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2] Remove Snap logic from view (should go in model)

parent bf0d17db
/*
* Copyright (c) 2013 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var SNAP = 10
function snapClip(clip, repeater) {
// clip.x = left edge
var right = clip.x + clip.width
if (clip.x > -SNAP && clip.x < SNAP) {
// Snap around origin.
clip.x = 0
return
} else {
// Snap to other clips.
for (var i = 0; i < repeater.count; i++) {
var itemLeft = repeater.itemAt(i).x
var itemRight = itemLeft + repeater.itemAt(i).width
// Snap to blank
if (right > itemLeft - SNAP && right < itemLeft + SNAP) {
clip.x = itemLeft - clip.width
return
} else if (clip.x > itemRight - SNAP && clip.x < itemRight + SNAP) {
clip.x = itemRight
return
} else if (right > itemRight - SNAP && right < itemRight + SNAP) {
clip.x = itemRight - clip.width
return
} else if (clip.x > itemLeft - SNAP && clip.x < itemLeft + SNAP) {
clip.x = itemLeft
return
}
}
}
if (!timeline.scrub) {
var cursorX = scrollView.flickableItem.contentX + cursor.x
if (clip.x > cursorX - SNAP && clip.x < cursorX + SNAP)
// Snap around cursor/playhead.
clip.x = cursorX
if (right > cursorX - SNAP && right < cursorX + SNAP)
clip.x = cursorX - clip.width
}
}
function snapTrimIn(clip, delta) {
var x = clip.x + delta
var cursorX = scrollView.flickableItem.contentX + cursor.x
if (false) {
// Snap to other clips.
for (var i = 0; i < repeater.count; i++) {
if (i === clip.DelegateModel.itemsIndex || repeater.itemAt(i).isBlank)
continue
var itemLeft = repeater.itemAt(i).x
var itemRight = itemLeft + repeater.itemAt(i).width
if (x > itemLeft - SNAP && x < itemLeft + SNAP)
return Math.round((itemLeft - clip.x) / timeScale)
else if (x > itemRight - SNAP && x < itemRight + SNAP)
return Math.round((itemRight - clip.x) / timeScale)
}
}
if (x > -SNAP && x < SNAP) {
// Snap around origin.
return Math.round(-clip.x / timeScale)
} else if (x > cursorX - SNAP && x < cursorX + SNAP) {
// Snap around cursor/playhead.
return Math.round((cursorX - clip.x) / timeScale)
}
return delta
}
function snapTrimOut(clip, delta) {
var rightEdge = clip.x + clip.width
var x = rightEdge - delta
var cursorX = scrollView.flickableItem.contentX + cursor.x
if (delta < 0) {
// Snap to other clips.
for (var i = 0; i < repeater.count; i++) {
if (i === clip.DelegateModel.itemsIndex || repeater.itemAt(i).isBlank || repeater.itemAt(i).isTransition)
continue
var itemLeft = repeater.itemAt(i).x
var itemRight = itemLeft + repeater.itemAt(i).width
if (x > itemLeft - SNAP && x < itemLeft + SNAP)
return Math.round((rightEdge - itemLeft) / timeScale)
else if (x > itemRight - SNAP && x < itemRight + SNAP)
return Math.round((rightEdge - itemRight) / timeScale)
}
}
if (x > cursorX - SNAP && x < cursorX + SNAP) {
// Snap around cursor/playhead.
return Math.round((rightEdge - cursorX) / timeScale)
}
return delta
}
function snapDrop(pos, repeater) {
var left = scrollView.flickableItem.contentX + pos.x - headerWidth
var right = left + dropTarget.width
if (left > -SNAP && left < SNAP) {
// Snap around origin.
dropTarget.x = headerWidth
return
} else {
// Snap to other clips.
for (var i = 0; i < repeater.count; i++) {
var itemLeft = repeater.itemAt(i).x
var itemRight = itemLeft + repeater.itemAt(i).width
if (right > itemLeft - SNAP && right < itemLeft + SNAP) {
dropTarget.x = itemLeft - dropTarget.width + headerWidth - scrollView.flickableItem.contentX
return
} else if (left > itemRight - SNAP && left < itemRight + SNAP) {
dropTarget.x = itemRight + headerWidth - scrollView.flickableItem.contentX
return
}
}
}
if (!timeline.scrub) {
var cursorX = scrollView.flickableItem.contentX + cursor.x
if (left > cursorX - SNAP && left < cursorX + SNAP)
// Snap around cursor/playhead.
dropTarget.x = cursorX + headerWidth - scrollView.flickableItem.contentX
if (right > cursorX - SNAP && right < cursorX + SNAP)
dropTarget.x = cursorX - dropTarget.width + headerWidth - scrollView.flickableItem.contentX
}
}
......@@ -18,7 +18,6 @@
import QtQuick 2.0
import QtQml.Models 2.1
import 'Track.js' as Logic
Column{
id: trackRoot
......@@ -38,21 +37,12 @@ Column{
signal clipDragged(var clip, int x, int y)
signal clipDropped(var clip)
signal clipDraggedToTrack(var clip, int pos)
signal checkSnap(var clip)
function redrawWaveforms() {
for (var i = 0; i < repeater.count; i++)
repeater.itemAt(i).generateWaveform()
}
function snapClip(clip) {
Logic.snapClip(clip, repeater)
}
function snapDrop(clip) {
Logic.snapDrop(clip, repeater)
}
function clipAt(index) {
return repeater.itemAt(index)
}
......@@ -138,8 +128,6 @@ Column{
clip.draggedX = clip.x
}
onTrimmingIn: {
//if (!(mouse.modifiers & Qt.AltModifier) && timeline.snap && !timeline.ripple)
// delta = Logic.snapTrimIn(clip, delta)
if (timeline.resizeClip(clip.clipId, newDuration, false, false)) {
clip.lastValidDuration = newDuration
clip.originalX = clip.draggedX
......@@ -158,8 +146,6 @@ Column{
timeline.resizeClip(clip.clipId, clip.lastValidDuration, false, true)
}
onTrimmingOut: {
// if (!(mouse.modifiers & Qt.AltModifier) && timeline.snap && !timeline.ripple)
// delta = Logic.snapTrimOut(clip, delta)
if (timeline.resizeClip(clip.clipId, newDuration, true, false)) {
clip.lastValidDuration = newDuration
// Show amount trimmed as a time in a "bubble" help.
......
......@@ -475,10 +475,6 @@ Rectangle {
}
}
}
onCheckSnap: {
for (var i = 0; i < tracksRepeater.count; i++)
tracksRepeater.itemAt(i).snapClip(clip)
}
Image {
anchors.right: parent.right
anchors.left: parent.left
......
......@@ -19,7 +19,6 @@
<file alias="Clip.qml">timeline2/view/qml/Clip.qml</file>
<file alias="PulsingAnimation.qml">timeline2/view/qml/PulsingAnimation.qml</file>
<file alias="CornerSelectionShadow.qml">timeline2/view/qml/CornerSelectionShadow.qml</file>
<file alias="Track.js">timeline2/view/qml/Track.js</file>
<file alias="Timeline.js">timeline2/view/qml/Timeline.js</file>
</qresource>
</RCC>
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