MarqueeText.qml
author sl
Tue, 03 Jun 2014 18:35:43 +0200
changeset 31 e68f1542d9d3
parent 28 8297924aa384
child 32 1c2a7f563019
permissions -rw-r--r--
Frame culling now done in QML rather than CPP.
     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         NumberAnimation {
    39             target: scrollingText;
    40             properties: "x"
    41             from: scrollingText.x;
    42             to: scrollingText.x-scrollingText.width-separatorText.width;
    43             duration: (scrollingText.width+separatorText.width)*1000/pixelsPerSeconds
    44         }
    45 
    46         NumberAnimation {
    47             target: separatorText;
    48             properties: "x"
    49             from: separatorText.x;
    50             to: separatorText.x-scrollingText.width-separatorText.width;
    51             duration: (scrollingText.width+separatorText.width)*1000/pixelsPerSeconds
    52         }
    53 
    54         NumberAnimation {
    55             target: followingText;
    56             properties: "x"
    57             from: followingText.x;
    58             to: followingText.x-scrollingText.width-separatorText.width;
    59             duration: (scrollingText.width+separatorText.width)*1000/pixelsPerSeconds
    60         }
    61 
    62     }
    63 
    64     //Click to start/stop
    65     MouseArea {
    66         id:mouseArea
    67         anchors.fill: parent
    68         onClicked: {
    69             animation.running=!animation.running;
    70         }
    71     }
    72 }