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.
sl@25
     1
import QtQuick 2.2
sl@28
     2
import QtQuick.Controls 1.2
sl@25
     3
sl@25
     4
Item {
sl@28
     5
    id:item
sl@25
     6
    height: scrollingText.height
sl@25
     7
    clip: true
sl@28
     8
    antialiasing: false
sl@26
     9
    property int pixelsPerSeconds:25
sl@25
    10
    property alias text: scrollingText.text
sl@26
    11
    property alias separator: separatorText.text
sl@34
    12
    property alias font: scrollingText.font
sl@26
    13
sl@28
    14
    Label {
sl@25
    15
        id:scrollingText
sl@28
    16
        antialiasing: item.antialiasing
sl@35
    17
        onFontChanged: {item.height=height}
sl@25
    18
    }
sl@25
    19
sl@28
    20
    Label {
sl@26
    21
        id:separatorText
sl@26
    22
        text:" || "
sl@34
    23
        font: scrollingText.font
sl@26
    24
        x:scrollingText.x+scrollingText.width
sl@28
    25
        antialiasing: item.antialiasing
sl@26
    26
    }
sl@26
    27
sl@28
    28
    Label {
sl@26
    29
        id:followingText
sl@26
    30
        text:scrollingText.text
sl@34
    31
        font: scrollingText.font
sl@26
    32
        x:scrollingText.x+scrollingText.width+separatorText.width
sl@28
    33
        antialiasing: item.antialiasing
sl@26
    34
    }
sl@26
    35
sl@26
    36
    ParallelAnimation {
sl@26
    37
        id: animation
sl@26
    38
        loops: Animation.Infinite;
sl@26
    39
        //Reset to zero and restart onStopped so that we keep looping
sl@26
    40
        //onStopped: {scrollingText.x=0;running=true;}
sl@26
    41
sl@33
    42
        property int lengthInPixels:(scrollingText.width+separatorText.width)-scrollingText.x;
sl@32
    43
        property int durationInMs:(animation.lengthInPixels)*1000/pixelsPerSeconds;
sl@32
    44
sl@27
    45
        NumberAnimation {
sl@33
    46
            id: animationScrollingTest
sl@26
    47
            target: scrollingText;
sl@27
    48
            properties: "x"
sl@30
    49
            from: scrollingText.x;
sl@32
    50
            to: scrollingText.x-animation.lengthInPixels;
sl@32
    51
            duration:animation.durationInMs
sl@26
    52
        }
sl@26
    53
sl@27
    54
        NumberAnimation {
sl@26
    55
            target: separatorText;
sl@27
    56
            properties: "x"
sl@26
    57
            from: separatorText.x;
sl@32
    58
            to: separatorText.x-animation.lengthInPixels;
sl@32
    59
            duration: animation.durationInMs
sl@26
    60
        }
sl@26
    61
sl@27
    62
        NumberAnimation {
sl@26
    63
            target: followingText;
sl@27
    64
            properties: "x"
sl@26
    65
            from: followingText.x;
sl@32
    66
            to: followingText.x-animation.lengthInPixels;
sl@32
    67
            duration: animation.durationInMs
sl@26
    68
        }
sl@26
    69
sl@26
    70
    }
sl@26
    71
sl@30
    72
    //Click to start/stop
sl@25
    73
    MouseArea {
sl@25
    74
        id:mouseArea
sl@25
    75
        anchors.fill: parent
sl@33
    76
        onClicked: {
sl@33
    77
            //animation.running=!animation.running;
sl@33
    78
sl@32
    79
            if (!animation.running) {
sl@32
    80
                animation.start();
sl@32
    81
                return;
sl@32
    82
            }
sl@32
    83
            if (animation.paused)
sl@32
    84
            {
sl@33
    85
                //console.log("resume")
sl@33
    86
                animation.resume();
sl@32
    87
            }
sl@32
    88
            else
sl@32
    89
            {
sl@33
    90
                //console.log("pause")
sl@33
    91
                animation.pause();
sl@33
    92
            }
sl@25
    93
        }
sl@25
    94
    }
sl@25
    95
}