Commit e034e781 authored by luyikei's avatar luyikei

Timeline: Support Qt5.6

parent 237cbea9
......@@ -3,9 +3,8 @@ import QtQuick 2.0
Rectangle {
id: clip
// NEVER SET X DIRECTLY. BINDING WILL BE REMOVED.
x: clipInfo ? ftop( clipInfo["position"] ) : 0
width: clipInfo ? ftop( clipInfo["end"] - clipInfo["begin"] + 1 ) : 0
z: 10001
x: ftop( position )
width: ftop( end - begin + 1 )
gradient: Gradient {
GradientStop {
id: gStop1
......@@ -25,46 +24,70 @@ Rectangle {
property alias name: text.text
property int trackId
// Usualy it is set -1. If not, the clip will be moved to the new track immediately.
property int newTrackId: -1
property int newTrackId
property int position
property int begin
property int end
property string uuid
property string type
property bool selected: false
property var clipInfo
onClipInfoChanged: {
if ( !clipInfo )
return;
position = clipInfo["position"];
begin = clipInfo["begin"];
end = clipInfo["end"];
}
onPositionChanged: {
clipInfo["position"] = position;
}
onBeginChanged: {
clipInfo["begin"] = begin;
}
onEndChanged: {
clipInfo["end"] = end;
}
function setPixelPosition( pixels )
{
if ( pixels >= 0 )
clipInfo["position"] = ptof( pixels );
position = ptof( pixels );
// FIXME: Qt bug. Sometimes binding is lost.
x = Qt.binding( function() { return ftop( position ); } );
}
function pixelPosition()
{
return ftop( clipInfo["position"] );
return ftop( position );
}
function move() {
// This function updates Backend
if ( newTrackId > -1 )
if ( newTrackId !== trackId )
moveClipTo( track.type, uuid, newTrackId );
else
workflow.moveClip( trackId, uuid, clipInfo["position"] )
workflow.moveClip( trackId, uuid, position )
}
function resize() {
// This function updates Backend
workflow.resizeClip( uuid, clipInfo["begin"], clipInfo["end"], clipInfo["position"] )
workflow.resizeClip( uuid, begin, end, position )
}
Component.onCompleted: {
clipInfo["item"] = clip;
clipInfo["track"] = track;
selected = true;
newTrackId = trackId;
}
Component.onDestruction: {
Drag.drop();
selected = false;
}
......@@ -77,9 +100,10 @@ Rectangle {
font.pointSize: trackHeight / 4
}
Drag.keys: ["Clip"]
Drag.active: dragArea.drag.active
Drag.hotSpot: Qt.point( width / 2 , height / 2 )
Drag.keys: "Clip"
Drag.hotSpot: Qt.point( width / 2, height / 2 )
MouseArea {
id: dragArea
anchors.fill: parent
......@@ -92,7 +116,7 @@ Rectangle {
property bool resizing: false
onPositionChanged: {
// If it's too short, don't resize.
// If it's too short, don't resize.
if ( width < 6 ) {
resizing = false;
return;
......@@ -103,17 +127,17 @@ Rectangle {
if ( resizing === true ) {
if ( mouseX < width / 2 ) {
var newPos = ptof( clip.x + mouseX );
var newBegin = clipInfo["begin"] + ( newPos - clipInfo["position"] );
if ( newBegin < 0 || newPos < 0 || newBegin >= clipInfo["end"] )
var newBegin = begin + ( newPos - position );
if ( newBegin < 0 || newPos < 0 || newBegin >= end )
return;
clipInfo["begin"] = newBegin;
clipInfo["position"] = newPos;
begin = newBegin;
position = newPos;
}
else {
var newEnd = ptof( mouseX + ftop( clipInfo["begin"] ) );
if ( newEnd <= clipInfo["begin"] || newEnd + 1 > clipInfo["length"] )
var newEnd = ptof( mouseX + ftop( begin ) );
if ( newEnd <= begin || newEnd + 1 > clipInfo["length"] )
return;
clipInfo["end"] = newEnd;
end = newEnd;
}
}
}
......@@ -144,13 +168,10 @@ Rectangle {
}
onReleased: {
for ( var i = 0; i < selectedClips.length; ++i )
if ( selectedClips[i]["item"] ) {
if ( resizing === true )
selectedClips[i]["item"].resize();
else
selectedClips[i]["item"].move();
}
if ( resizing === true )
resize();
else
dragFinished();
}
states: [
......@@ -172,11 +193,6 @@ Rectangle {
]
}
onXChanged: {
if ( x < 0 )
setPixelPosition( 0 );
}
onYChanged: {
// Don't move outside its TrackContainer
// For Top
......@@ -190,11 +206,11 @@ Rectangle {
onSelectedChanged: {
if ( selected === true ) {
selectedClips.push( clipInfo );
selectedClips.push( clip );
}
else {
for ( var i = 0; i < selectedClips.length; ++i )
if ( !selectedClips[i]["item"] || selectedClips[i]["item"] === clip ) {
if ( !selectedClips[i] || selectedClips[i] === clip ) {
selectedClips.splice( i, 1 );
--i;
}
......
......@@ -11,8 +11,8 @@ Item {
property ListModel clips
Row {
height: parent.height
width: parent.width
anchors.fill: parent
Rectangle {
id: trackInfo
width: initPosOfCursor
......@@ -70,6 +70,7 @@ Item {
}
DropArea {
id: dropArea
anchors.fill: parent
keys: ["Clip", "vlmc/uuid"]
......@@ -95,11 +96,13 @@ Item {
aClipInfo = null;
vClipInfo = null;
clearSelectedClips();
adjustTracks( "Audio" );
adjustTracks( "Video" );
}
}
onExited: {
if ( currentUuid ) {
if ( currentUuid !== "" ) {
removeClipFromTrack( "Audio", trackId, "tempUuid" );
removeClipFromTrack( "Video", trackId, "tempUuid" );
}
......@@ -107,6 +110,7 @@ Item {
onEntered: {
if ( drag.keys.indexOf( "vlmc/uuid" ) >= 0 ) {
clearSelectedClips();
if ( currentUuid === drag.getDataAsString( "vlmc/uuid" ) ) {
if ( aClipInfo )
{
......@@ -124,8 +128,6 @@ Item {
currentUuid = "" + newClipInfo["uuid"];
newClipInfo["position"] = ptof( drag.x );
newClipInfo["uuid"] = "tempUuid";
clearSelectedClips();
if ( newClipInfo["audio"] )
aClipInfo = addClip( "Audio", trackId, newClipInfo );
if ( newClipInfo["video"] )
......@@ -139,36 +141,43 @@ Item {
if ( drag.source.resizing === true )
return;
// Find the previous X of the clip
var newX = drag.x;
for ( var i = 0; i < selectedClips.length; ++i ) {
var target = selectedClips[i]["item"];
if ( !target )
{
selectedClips.splice( i, 1 );
--i;
continue;
}
if ( drag.keys.indexOf( "vlmc/uuid" ) < 0 ) {
var newX = drag.source.mapToItem( clipArea, 0, 0 ).x; // FIXME: Mysterious QML Bug, you can't use drag.x
drag.source.y = drag.source.y - drag.y + track.height / 2 - 1;
}
else
newX = Math.max( drag.x, 0 );
if ( drag.keys.indexOf( "vlmc/uuid" ) < 0 )
newX = drag.source.x; // FIXME: Mysterious QML Bug, you can't use drag.x
for ( var i = 0; i < selectedClips.length; ++i ) {
var target = selectedClips[i];
var oldx = target.pixelPosition();
newX = Math.max( newX, 0 );
if ( drag.source === target ) {
var oldTrackId = target.newTrackId;
target.newTrackId = trackId;
for ( var j = 0; j < selectedClips.length; ++j ) {
if ( drag.source !== selectedClips[j] )
selectedClips[j].newTrackId = trackId - oldTrackId + selectedClips[j].trackId;
}
}
// Collision detection
var isCollided = true;
var clips = trackContainer( target.type )["tracks"].get( trackId )["clips"];
for ( var j = 0; j < clips.count + 2 && isCollided; ++j ) {
var currentTrack = trackContainer( target.type )["tracks"].get( target.newTrackId );
if ( currentTrack )
var clips = currentTrack["clips"];
else
clips = [];
for ( j = 0; j < clips.count + 2 && isCollided; ++j ) {
isCollided = false;
for ( var k = 0; k < clips.count; ++k ) {
var clip = clips.get( k );
if ( clip.uuid === target.uuid )
continue;
var sw = target.width; // Width of the source clip
var cx = clip["item"].x;
var cw = clip["item"].width;
var cx = ftop( clip["position"] );
var cw = ftop( clip["end"] - clip["begin"] + 1);
// Set a right position
if ( cx + cw > newX && newX + sw > cx ) {
isCollided = true;
......@@ -191,29 +200,22 @@ Item {
if ( isCollided ) {
for ( k = 0; k < clips.count; ++k ) {
clip = clips.get( k );
if ( clip["item"].x + clip["item"].width > target.pixelPosition() )
target.setPixelPosition( clip["item"].x + clip["item"].width );
cx = ftop( clip["position"] );
cw = ftop( clip["end"] - clip["begin"] + 1);
if ( cx + cw > target.pixelPosition() )
target.setPixelPosition( cx + cw );
}
}
if ( drag.keys.indexOf( "vlmc/uuid" ) < 0 ) {
if ( target.trackId !== trackId )
target.newTrackId = trackId ;
else
target.newTrackId = -1;
if ( drag.source.uuid !== target.uuid ) {
if ( target.newTrackId !== -1 ) {
if ( target.newTrackId !== target.trackId ) {
drag.source.parent.parent.parent.z = ++maxZ;
if ( drag.source.uuid !== target.uuid ) {
addClip( target.type, target.newTrackId, target.clipInfo );
removeClipFromTrack( target.type, target.trackId, target.uuid );
--i;
}
}
else {
target.y = target.y - drag.y + track.height / 2 - 1;
target.parent.parent.parent.z = maxZ++; // FIXME: Ugly workaround for z-index
}
}
}
}
......@@ -228,7 +230,10 @@ Item {
trackId: model.trackId
type: track.type
uuid: model.uuid
clipInfo: findClipFromTrack( track.type, model.trackId, model.uuid );
position: model.position
begin: model.begin
end: model.end
clipInfo: model
}
}
}
......
......@@ -20,9 +20,9 @@ Rectangle {
function clearSelectedClips() {
while ( selectedClips.length ) {
var clipInfo = selectedClips.pop();
if ( clipInfo["item"] )
clipInfo["item"].selected = false;
var clip = selectedClips.pop();
if ( clip )
clip.selected = false;
}
}
......@@ -72,9 +72,6 @@ Rectangle {
if ( clipDict["uuid"] === "tempUuid" )
return newDict;
while ( tracks.count < trackId + 2 ) {
addTrack( trackType );
}
return newDict;
}
......@@ -83,6 +80,7 @@ Rectangle {
var ret = false;
var tracks = trackContainer( trackType )["tracks"];
var clips = tracks.get( trackId )["clips"];
for ( var j = 0; j < clips.count; j++ ) {
var clip = clips.get( j );
if ( clip.uuid === uuid ) {
......@@ -94,9 +92,6 @@ Rectangle {
if ( uuid === "tempUuid" )
return ret;
while ( tracks.count > 1 && tracks.get( tracks.count - 2 )["clips"].count === 0 )
removeTrack( trackType );
return ret;
}
......@@ -149,6 +144,29 @@ Rectangle {
removeClipFromTrack( trackType, oldId, uuid );
}
function adjustTracks( trackType ) {
var tracks = trackContainer( trackType )["tracks"];
while ( tracks.count > 1 && tracks.get( tracks.count - 1 )["clips"].count === 0 &&
tracks.get( tracks.count - 2 )["clips"].count === 0 )
removeTrack( trackType );
if ( tracks.get( tracks.count - 1 )["clips"].count > 0 )
addTrack( trackType );
}
function dragFinished() {
var length = selectedClips.length;
for ( var i = length - 1; i >= 0; --i ) {
if ( selectedClips[i] ) {
selectedClips[i].move();
}
}
adjustTracks( "Audio" );
adjustTracks( "Video" );
}
ListModel {
id: trackContainers
......@@ -276,8 +294,8 @@ Rectangle {
standardButtons: StandardButton.Yes | StandardButton.No
onYes: {
while ( selectedClips.length ) {
workflow.removeClip( selectedClips[0]["uuid"] );
removeClipFromTrackContainer( selectedClips[0]["item"].type, selectedClips[0]["uuid"] );
workflow.removeClip( selectedClips[0] );
removeClipFromTrackContainer( selectedClips[0].type, selectedClips[0].uuid );
}
}
}
......
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