Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move text and repaint on value changged.
  • Loading branch information
locusf committed Nov 12, 2013
1 parent 0f217a9 commit 6cfe421
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/styles/SliderStyle.qml
Expand Up @@ -32,27 +32,42 @@ SliderStyle {
z: 1
visible: control.enabled
}

handle: Canvas {
Connections {
target: control
onValueChanged: {
console.log(((control.value*1000) - lastValue))
if (((control.value*1000) - lastValue) > 200) {
requestPaint()
lastValue = control.value*1000
}
}
}
id: canvas
width: 125
height: 32
height: 110
property color strokeStyle: Theme.groove.foreground
property color fillStyle: Theme.groove.foreground
property bool fill: true
property bool stroke: true
property real alpha: 1.0
property real lastValue: 0
antialiasing: true

onPaint: {
var ctx = canvas.getContext('2d');
var gradient = ctx.createLinearGradient(0,0,100,100);
gradient.addColorStop(0.3, Theme.groove.foreground);
ctx.save();
if (pressed) {
if (control.pressed) {
ctx.fillStyle = gradient;
console.log("PRESSED!");
} else {
ctx.fillStyle = canvas.fillStyle;
console.log("NOT PRESSED!");
}
ctx.translate(0, 39);
ctx.beginPath();
ctx.lineWidth = 1;
ctx.moveTo(0,8);
Expand All @@ -66,9 +81,10 @@ SliderStyle {
ctx.fill();
ctx.drawImage(ball, 80, -5);
ctx.restore();
ctx.translate(0,39);
ctx.fillStyle="white";
ctx.font="Bold 12px";
ctx.fillText(parseInt(control.value*100), 80, 5);
ctx.font="Bold 24px";
ctx.fillText(parseInt(control.value*100), 90, 25);
ctx.restore();
}
}
Expand Down

0 comments on commit 6cfe421

Please sign in to comment.