Commit b75a85de authored by luyikei's avatar luyikei

Timeline: Move zerofill and timecode functions to main.qml

parent 77a2806a
......@@ -60,14 +60,6 @@ Rectangle {
}
}
function zerofill( number, width ) {
var str = "" + number;
while ( str.length < width ) {
str = "0" + str;
}
return str;
}
Component.onCompleted: {
if ( index % 10 == 0 ) {
// Text
......@@ -79,16 +71,7 @@ Rectangle {
);
obj.text = Qt.binding( function()
{
var seconds = Math.floor( index * unit / 1000 );
var minutes = Math.floor( seconds / 60 );
var hours = Math.floor( minutes / 60 );
return zerofill( hours, 3 ) + ':' + // hours
zerofill( minutes % 60, 2 ) + ':' + // minutes
zerofill( seconds % 60, 2 ) + ':' + // seconds
// The second Math.round prevents the first value from exceeding fps.
// e.g. 30 % Math.round( 29.97 ) = 0
zerofill( Math.round( ptof( index * ppu ) % fps ) % Math.round( fps ), 2 ); // frames in a minute
return timecodeFromFrames( ptof( x ) );
} );
scale.color = "#AA7777";
scale.width = 2;
......
......@@ -29,6 +29,27 @@ Rectangle {
}
}
function zerofill( number, width ) {
var str = "" + number;
while ( str.length < width ) {
str = "0" + str;
}
return str;
}
function timecodeFromFrames( frames ) {
var seconds = Math.floor( frames / Math.round( fps ) );
var minutes = Math.floor( seconds / 60 );
var hours = Math.floor( minutes / 60 );
return zerofill( hours, 3 ) + ':' + // hours
zerofill( minutes % 60, 2 ) + ':' + // minutes
zerofill( seconds % 60, 2 ) + ':' + // seconds
// The second Math.round prevents the first value from exceeding fps.
// e.g. 30 % Math.round( 29.97 ) = 0
zerofill( Math.floor( frames % Math.round( fps ) ), 2 ); // frames in a minute
}
// Convert length in frames to pixels
function ftop( frames )
{
......
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