Commit b0a3b295 authored by Ulf Hermann's avatar Ulf Hermann
Browse files

QmlProfiler: Use bindings instead of JS methods for RangeMover



It's more intuitive to use and more QML-like.

Change-Id: Ifbd05df59d8afaeb62acc9a6f1f3d4786f822169
Reviewed-by: default avatarKai Koehne <kai.koehne@digia.com>
parent 57fe9b7b
......@@ -376,8 +376,8 @@ Rectangle {
}
// hack to pass mouse events to the other mousearea if enabled
startDragArea: selectionRange.ready ? selectionRange.getLeft() : -x
endDragArea: selectionRange.ready ? selectionRange.getRight() : -x - 1
startDragArea: selectionRange.ready ? selectionRange.rangeLeft : -x
endDragArea: selectionRange.ready ? selectionRange.rangeRight : -x - 1
}
MouseArea {
id: selectionRangeControl
......@@ -419,7 +419,7 @@ Rectangle {
startTime: selectionRange.startTimeString
duration: selectionRange.durationString
endTime: selectionRange.endTimeString
showDuration: selectionRange.getWidth() > 1
showDuration: selectionRange.rangeWidth > 1
}
RangeDetails {
......
......@@ -61,8 +61,8 @@ Canvas {
function updateRange() {
if (recursionGuard)
return;
var newStartTime = Math.round(rangeMover.getLeft() * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
var newEndTime = Math.round(rangeMover.getRight() * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
var newStartTime = Math.round(rangeMover.rangeLeft * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
var newEndTime = Math.round(rangeMover.rangeRight * qmlProfilerModelProxy.traceDuration() / width) + qmlProfilerModelProxy.traceStartTime();
if (startTime !== newStartTime || endTime !== newEndTime)
zoomControl.setRange(newStartTime, Math.max(newEndTime, newStartTime + 500));
}
......@@ -81,13 +81,13 @@ Canvas {
endTime = clamp(zoomControl.endTime(), startTime, qmlProfilerModelProxy.traceEndTime());
var newRangeX = (startTime - qmlProfilerModelProxy.traceStartTime()) * width / qmlProfilerModelProxy.traceDuration();
var newWidth = (endTime - startTime) * width / qmlProfilerModelProxy.traceDuration();
var widthChanged = Math.abs(newWidth - rangeMover.getWidth()) > 1;
var leftChanged = Math.abs(newRangeX - rangeMover.getLeft()) > 1;
var widthChanged = Math.abs(newWidth - rangeMover.rangeWidth) > 1;
var leftChanged = Math.abs(newRangeX - rangeMover.rangeLeft) > 1;
if (leftChanged)
rangeMover.setLeft(newRangeX);
rangeMover.rangeLeft = newRangeX;
if (leftChanged || widthChanged)
rangeMover.setRight(newRangeX + newWidth);
rangeMover.rangeRight = newRangeX + newWidth;
recursionGuard = false;
}
}
......@@ -137,19 +137,18 @@ Canvas {
MouseArea {
anchors.fill: canvas
function jumpTo(posX) {
var rangeWidth = rangeMover.getWidth();
var newX = posX - rangeWidth / 2;
var newX = posX - rangeMover.rangeWidth / 2;
if (newX < 0)
newX = 0;
if (newX + rangeWidth > canvas.width)
newX = canvas.width - rangeWidth;
if (newX < rangeMover.getLeft()) {
rangeMover.setLeft(newX);
rangeMover.setRight(newX + rangeWidth);
} else if (newX > rangeMover.getLeft()) {
rangeMover.setRight(newX + rangeWidth);
rangeMover.setLeft(newX);
if (newX + rangeMover.rangeWidth > canvas.width)
newX = canvas.width - rangeMover.rangeWidth;
if (newX < rangeMover.rangeLeft) {
rangeMover.rangeLeft = newX;
rangeMover.rangeRight = newX + rangeMover.rangeWidth;
} else if (newX > rangeMover.rangeLeft) {
rangeMover.rangeRight = newX + rangeMover.rangeWidth;
rangeMover.rangeLeft = newX;
}
}
......@@ -164,7 +163,8 @@ Canvas {
RangeMover {
id: rangeMover
visible: dataReady
onRangeChanged: canvas.updateRange()
onRangeLeftChanged: canvas.updateRange()
onRangeRightChanged: canvas.updateRange()
}
Rectangle {
......
......@@ -33,7 +33,6 @@ Rectangle {
id: rangeMover
anchors.fill: parent
color: "transparent"
signal rangeChanged()
signal rangeDoubleClicked()
property color handleColor: "#869cd1"
......@@ -43,13 +42,9 @@ Rectangle {
property color dragMarkerColor: "#4a64b8"
property color singleLineColor: "#4a64b8"
function setLeft(left) { leftRange.x = left }
function getLeft() { return leftRange.x }
function setRight(right) { rightRange.x = right }
function getRight() { return rightRange.x }
function getWidth() { return rightRange.x - leftRange.x }
property alias rangeLeft: leftRange.x
property alias rangeRight: rightRange.x
readonly property alias rangeWidth: selectedRange.width
Rectangle {
id: selectedRange
......@@ -59,9 +54,6 @@ Rectangle {
height: parent.height
color: width > 1 ? (dragArea.pressed ? dragColor : rangeColor) : singleLineColor
onXChanged: parent.rangeChanged()
onWidthChanged: parent.rangeChanged()
}
Rectangle {
......
......@@ -38,8 +38,8 @@ RangeMover {
property string endTimeString: detailedPrintTime(startTime+duration)
property string durationString: detailedPrintTime(duration)
property double startTime: getLeft() * viewTimePerPixel + zoomControl.windowStart()
property double duration: Math.max(getWidth() * viewTimePerPixel, 500)
property double startTime: rangeLeft * viewTimePerPixel + zoomControl.windowStart()
property double duration: Math.max(rangeWidth * viewTimePerPixel, 500)
property double viewTimePerPixel: 1
property double creationReference : 0
property int creationState : 0
......@@ -50,9 +50,9 @@ RangeMover {
var oldTimePerPixel = selectionRange.viewTimePerPixel;
selectionRange.viewTimePerPixel = Math.abs(zoomControl.endTime() - zoomControl.startTime()) / view.intWidth;
if (creationState === 3 && oldTimePerPixel != selectionRange.viewTimePerPixel) {
var newWidth = getWidth() * oldTimePerPixel / viewTimePerPixel;
setLeft(getLeft() * oldTimePerPixel / viewTimePerPixel);
setRight(getLeft() + newWidth);
var newWidth = rangeWidth * oldTimePerPixel / viewTimePerPixel;
rangeLeft = rangeLeft * oldTimePerPixel / viewTimePerPixel;
rangeRight = rangeLeft + newWidth;
}
}
}
......@@ -63,7 +63,7 @@ RangeMover {
}
function reset() {
setRight(getLeft() + 1);
rangeRight = rangeLeft + 1;
creationState = 0;
creationReference = 0;
}
......@@ -77,16 +77,16 @@ RangeMover {
switch (creationState) {
case 1:
creationReference = pos;
setLeft(pos);
setRight(pos + 1);
rangeLeft = pos;
rangeRight = pos + 1;
break;
case 2:
if (pos > creationReference) {
setLeft(creationReference);
setRight(pos);
rangeLeft = creationReference;
rangeRight = pos;
} else if (pos < creationReference) {
setLeft(pos);
setRight(creationReference);
rangeLeft = pos;
rangeRight = creationReference;
}
break;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment