MarqueeText.qml
author sl
Wed, 04 Jun 2014 08:12:37 +0200
changeset 32 1c2a7f563019
parent 30 c0f274a21d33
child 33 cf5eba52cb1d
permissions -rw-r--r--
Messing around to try to get our animation to start and stop properly.
That's still not working though.
     1 import QtQuick 2.2
     2 import QtQuick.Controls 1.2
     3 
     4 Item {
     5     id:item
     6     height: scrollingText.height
     7     clip: true
     8     antialiasing: false
     9     property int pixelsPerSeconds:25
    10     property alias text: scrollingText.text
    11     property alias separator: separatorText.text
    12 
    13     Label {
    14         id:scrollingText
    15         antialiasing: item.antialiasing
    16     }
    17 
    18     Label {
    19         id:separatorText
    20         text:" || "
    21         x:scrollingText.x+scrollingText.width
    22         antialiasing: item.antialiasing
    23     }
    24 
    25     Label {
    26         id:followingText
    27         text:scrollingText.text
    28         x:scrollingText.x+scrollingText.width+separatorText.width
    29         antialiasing: item.antialiasing
    30     }
    31 
    32     ParallelAnimation {
    33         id: animation
    34         loops: Animation.Infinite;
    35         //Reset to zero and restart onStopped so that we keep looping
    36         //onStopped: {scrollingText.x=0;running=true;}
    37 
    38         property int lengthInPixels:scrollingText.width-separatorText.width-scrollingText.x;
    39         property int durationInMs:(animation.lengthInPixels)*1000/pixelsPerSeconds;
    40 
    41         NumberAnimation {
    42             target: scrollingText;
    43             properties: "x"
    44             from: scrollingText.x;
    45             to: scrollingText.x-animation.lengthInPixels;
    46             duration:animation.durationInMs
    47         }
    48 
    49         NumberAnimation {
    50             target: separatorText;
    51             properties: "x"
    52             from: separatorText.x;
    53             to: separatorText.x-animation.lengthInPixels;
    54             duration: animation.durationInMs
    55         }
    56 
    57         NumberAnimation {
    58             target: followingText;
    59             properties: "x"
    60             from: followingText.x;
    61             to: followingText.x-animation.lengthInPixels;
    62             duration: animation.durationInMs
    63         }
    64 
    65     }
    66 
    67     //Click to start/stop
    68     MouseArea {
    69         id:mouseArea
    70         anchors.fill: parent
    71         onClicked: {animation.running=!animation.running;
    72             /*
    73             if (!animation.running) {
    74                 animation.start();
    75                 return;
    76             }
    77             if (animation.paused)
    78             {
    79                 console.log("resume")
    80                 animation.resume;
    81             }
    82             else
    83             {
    84                 console.log("pause")
    85                 animation.pause;
    86             }*/
    87         }
    88     }
    89 }