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