MarqueeText.qml
author sl
Wed, 04 Jun 2014 18:30:37 +0200
changeset 33 cf5eba52cb1d
parent 32 1c2a7f563019
child 34 f2c87f0cfabe
permissions -rw-r--r--
Marquee loop can now be paused and resumed.
Cleaning up our MiniDisplay coneection to render loop API.
     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             id: animationScrollingTest
    43             target: scrollingText;
    44             properties: "x"
    45             from: scrollingText.x;
    46             to: scrollingText.x-animation.lengthInPixels;
    47             duration:animation.durationInMs
    48         }
    49 
    50         NumberAnimation {
    51             target: separatorText;
    52             properties: "x"
    53             from: separatorText.x;
    54             to: separatorText.x-animation.lengthInPixels;
    55             duration: animation.durationInMs
    56         }
    57 
    58         NumberAnimation {
    59             target: followingText;
    60             properties: "x"
    61             from: followingText.x;
    62             to: followingText.x-animation.lengthInPixels;
    63             duration: animation.durationInMs
    64         }
    65 
    66     }
    67 
    68     //Click to start/stop
    69     MouseArea {
    70         id:mouseArea
    71         anchors.fill: parent
    72         onClicked: {
    73             //animation.running=!animation.running;
    74 
    75             if (!animation.running) {
    76                 animation.start();
    77                 return;
    78             }
    79             if (animation.paused)
    80             {
    81                 //console.log("resume")
    82                 animation.resume();
    83             }
    84             else
    85             {
    86                 //console.log("pause")
    87                 animation.pause();
    88             }
    89         }
    90     }
    91 }