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