MarqueeText.qml
author sl
Wed, 04 Jun 2014 21:56:36 +0200
changeset 35 2868107ea71d
parent 34 f2c87f0cfabe
child 36 f2a9369e7fb9
permissions -rw-r--r--
Testing our double marquee.
     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     property alias font: scrollingText.font
    13 
    14     Label {
    15         id:scrollingText
    16         antialiasing: item.antialiasing
    17         onFontChanged: {item.height=height}
    18     }
    19 
    20     Label {
    21         id:separatorText
    22         text:" || "
    23         font: scrollingText.font
    24         x:scrollingText.x+scrollingText.width
    25         antialiasing: item.antialiasing
    26     }
    27 
    28     Label {
    29         id:followingText
    30         text:scrollingText.text
    31         font: scrollingText.font
    32         x:scrollingText.x+scrollingText.width+separatorText.width
    33         antialiasing: item.antialiasing
    34     }
    35 
    36     ParallelAnimation {
    37         id: animation
    38         loops: Animation.Infinite;
    39         //Reset to zero and restart onStopped so that we keep looping
    40         //onStopped: {scrollingText.x=0;running=true;}
    41 
    42         property int lengthInPixels:(scrollingText.width+separatorText.width)-scrollingText.x;
    43         property int durationInMs:(animation.lengthInPixels)*1000/pixelsPerSeconds;
    44 
    45         NumberAnimation {
    46             id: animationScrollingTest
    47             target: scrollingText;
    48             properties: "x"
    49             from: scrollingText.x;
    50             to: scrollingText.x-animation.lengthInPixels;
    51             duration:animation.durationInMs
    52         }
    53 
    54         NumberAnimation {
    55             target: separatorText;
    56             properties: "x"
    57             from: separatorText.x;
    58             to: separatorText.x-animation.lengthInPixels;
    59             duration: animation.durationInMs
    60         }
    61 
    62         NumberAnimation {
    63             target: followingText;
    64             properties: "x"
    65             from: followingText.x;
    66             to: followingText.x-animation.lengthInPixels;
    67             duration: animation.durationInMs
    68         }
    69 
    70     }
    71 
    72     //Click to start/stop
    73     MouseArea {
    74         id:mouseArea
    75         anchors.fill: parent
    76         onClicked: {
    77             //animation.running=!animation.running;
    78 
    79             if (!animation.running) {
    80                 animation.start();
    81                 return;
    82             }
    83             if (animation.paused)
    84             {
    85                 //console.log("resume")
    86                 animation.resume();
    87             }
    88             else
    89             {
    90                 //console.log("pause")
    91                 animation.pause();
    92             }
    93         }
    94     }
    95 }