[vlmc-devel] Timeline: Use a property to set the position of cursor

Yikai Lu git at videolan.org
Mon Jul 18 15:39:54 CEST 2016


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Mon Jul 18 17:03:13 2016 +0900| [ebf408ea587a2711f32e75642922d5065a022680] | committer: Yikai Lu

Timeline: Use a property to set the position of cursor

> https://code.videolan.org/videolan/vlmc/commit/ebf408ea587a2711f32e75642922d5065a022680
---

 src/Gui/timeline/Cursor.qml |  6 ++++--
 src/Gui/timeline/Ruler.qml  | 13 +++++++------
 src/Gui/timeline/main.qml   |  5 +----
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/Gui/timeline/Cursor.qml b/src/Gui/timeline/Cursor.qml
index 14e2423..991d23c 100644
--- a/src/Gui/timeline/Cursor.qml
+++ b/src/Gui/timeline/Cursor.qml
@@ -3,9 +3,11 @@ import QtQuick 2.0
 Rectangle {
     width: 2
     color: "#c24a00"
+    x: ftop( cursorPosition ) + initPosOfCursor
 
-    onXChanged: {
-         x = x > initPosOfCursor ? x : initPosOfCursor;
+    Component.onCompleted: {
+        // FIXME: Binding is lost
+        x = Qt.binding( function() { return ftop( cursorPosition ) + initPosOfCursor; } );
     }
 
     function position() {
diff --git a/src/Gui/timeline/Ruler.qml b/src/Gui/timeline/Ruler.qml
index 0cc9a2e..14717bb 100644
--- a/src/Gui/timeline/Ruler.qml
+++ b/src/Gui/timeline/Ruler.qml
@@ -119,27 +119,28 @@ Rectangle {
         anchors.fill: parent
 
         onPressed: {
-            cursor.x = mouseX + initPosOfCursor;
+            cursorPosition = ptof( mouseX );
         }
 
         onReleased: {
-            workflow.setPosition( ptof( mouseX ) );
+            workflow.setPosition( cursorPosition );
         }
 
         onClicked: {
-            workflow.setPosition( ptof( mouseX ) );
+            cursorPosition = ptof( mouseX );
+            workflow.setPosition( cursorPosition );
         }
 
         onPositionChanged: {
-            cursor.x = mouseX + initPosOfCursor;
-            workflow.setPosition( ptof( mouseX ) );
+            cursorPosition = ptof( mouseX );
+            workflow.setPosition( cursorPosition );
         }
     }
 
     Connections {
         target: workflow
         onFrameChanged: {
-            cursor.x = ftop( newFrame ) + initPosOfCursor;
+            cursorPosition = newFrame;
         }
     }
 }
diff --git a/src/Gui/timeline/main.qml b/src/Gui/timeline/main.qml
index 30e720d..014edcc 100644
--- a/src/Gui/timeline/main.qml
+++ b/src/Gui/timeline/main.qml
@@ -10,6 +10,7 @@ Rectangle {
     focus: true
 
     property int length // in frames
+    property int cursorPosition: 0 // in frames
     property int initPosOfCursor: 100
     property double ppu: 10 // Pixels Per minimum Unit
     property double unit: 3000 // In milliseconds therefore ppu / unit = Pixels Per milliseconds
@@ -187,8 +188,6 @@ Rectangle {
         // Make unit a multiple of fps. This can change the scale but let's ignore it.
         newUnit -= newUnit % mUnit;
 
-        var cursorPos = cursor.position();
-
         // If "almost" the same value, don't bother redrawing the ruler.
         if ( Math.abs( unit - newUnit ) > 0.01 )
             unit = newUnit;
@@ -196,8 +195,6 @@ Rectangle {
         if ( Math.abs( ppu - newPpu ) > 0.0001 )
             ppu = newPpu;
 
-        cursor.x = ftop( cursorPos ) + initPosOfCursor;
-
         // Let's scroll to the cursor position!
         var newContentX = cursor.x - sView.width / 2;
         // Never show the background behind the timeline



More information about the Vlmc-devel mailing list