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