2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-07-06 15:48:52 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-06 15:48:52 +00:00
|
|
|
|
2013-09-03 12:53:48 +02:00
|
|
|
import QtQuick 2.1
|
2011-06-20 18:11:17 +02:00
|
|
|
import Monitor 1.0
|
|
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
Canvas {
|
2011-06-20 18:11:17 +02:00
|
|
|
id: timeDisplay
|
2013-10-30 13:39:29 +01:00
|
|
|
objectName: "TimeDisplay"
|
2013-11-28 15:29:29 +01:00
|
|
|
contextType: "2d"
|
2011-06-20 18:11:17 +02:00
|
|
|
|
2013-09-03 12:56:29 +02:00
|
|
|
property real startTime : 0
|
|
|
|
|
property real endTime : 0
|
|
|
|
|
property real timePerPixel: 0
|
2011-10-11 17:52:39 +02:00
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: zoomControl
|
|
|
|
|
onRangeChanged: {
|
|
|
|
|
startTime = zoomControl.startTime();
|
|
|
|
|
endTime = zoomControl.endTime();
|
2013-11-28 15:29:29 +01:00
|
|
|
requestPaint();
|
2011-10-11 17:52:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
2011-06-20 18:11:17 +02:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
onPaint: {
|
2014-02-25 17:08:26 +01:00
|
|
|
if (context === null)
|
|
|
|
|
return; // canvas isn't ready
|
2013-11-28 15:29:29 +01:00
|
|
|
context.fillStyle = "white";
|
|
|
|
|
context.fillRect(0, 0, width, height);
|
2011-06-20 18:11:17 +02:00
|
|
|
|
|
|
|
|
var totalTime = endTime - startTime;
|
|
|
|
|
var spacing = width / totalTime;
|
|
|
|
|
|
|
|
|
|
var initialBlockLength = 120;
|
|
|
|
|
var timePerBlock = Math.pow(2, Math.floor( Math.log( totalTime / width * initialBlockLength ) / Math.LN2 ) );
|
|
|
|
|
var pixelsPerBlock = timePerBlock * spacing;
|
|
|
|
|
var pixelsPerSection = pixelsPerBlock / 5;
|
|
|
|
|
var blockCount = width / pixelsPerBlock;
|
|
|
|
|
|
|
|
|
|
var realStartTime = Math.floor(startTime/timePerBlock) * timePerBlock;
|
|
|
|
|
var realStartPos = (startTime-realStartTime) * spacing;
|
|
|
|
|
|
|
|
|
|
timePerPixel = timePerBlock/pixelsPerBlock;
|
|
|
|
|
|
2011-11-16 16:08:05 +01:00
|
|
|
var initialColor = Math.floor(realStartTime/timePerBlock) % 2;
|
2011-06-20 18:11:17 +02:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
context.fillStyle = "#000000";
|
|
|
|
|
context.font = "8px sans-serif";
|
2011-06-20 18:11:17 +02:00
|
|
|
for (var ii = 0; ii < blockCount+1; ii++) {
|
|
|
|
|
var x = Math.floor(ii*pixelsPerBlock - realStartPos);
|
2011-11-16 16:08:05 +01:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
context.fillStyle = (ii+initialColor)%2 ? "#E6E6E6":"white";
|
|
|
|
|
context.fillRect(x, 0, pixelsPerBlock, height);
|
2011-11-16 16:08:05 +01:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
context.strokeStyle = "#B0B0B0";
|
|
|
|
|
context.beginPath();
|
|
|
|
|
context.moveTo(x, 0);
|
|
|
|
|
context.lineTo(x, height);
|
|
|
|
|
context.stroke();
|
2011-06-20 18:11:17 +02:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
context.fillStyle = "#000000";
|
|
|
|
|
context.fillText(prettyPrintTime(ii*timePerBlock + realStartTime), x + 5, height/2 + 5);
|
2011-06-20 18:11:17 +02:00
|
|
|
}
|
2011-11-16 16:08:05 +01:00
|
|
|
|
2013-11-28 15:29:29 +01:00
|
|
|
context.strokeStyle = "#525252";
|
|
|
|
|
context.beginPath();
|
|
|
|
|
context.moveTo(0, height-1);
|
|
|
|
|
context.lineTo(width, height-1);
|
|
|
|
|
context.stroke();
|
2011-11-16 16:08:05 +01:00
|
|
|
|
2014-02-24 13:35:05 +01:00
|
|
|
// left border
|
|
|
|
|
context.fillStyle = "#858585";
|
|
|
|
|
context.fillRect(0, 0, 1, height);
|
2011-06-20 18:11:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function prettyPrintTime( t )
|
|
|
|
|
{
|
2013-11-21 18:07:17 +01:00
|
|
|
var round = 1;
|
|
|
|
|
var barrier = 1;
|
|
|
|
|
var range = endTime - startTime;
|
|
|
|
|
var units = ["μs", "ms", "s"];
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < units.length; ++i) {
|
|
|
|
|
barrier *= 1000;
|
|
|
|
|
if (range < barrier)
|
|
|
|
|
round *= 1000;
|
|
|
|
|
else if (range < barrier * 10)
|
|
|
|
|
round *= 100;
|
|
|
|
|
else if (range < barrier * 100)
|
|
|
|
|
round *= 10;
|
|
|
|
|
if (t < barrier * 1000)
|
|
|
|
|
return Math.floor(t / (barrier / round)) / round + units[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t /= barrier;
|
|
|
|
|
var m = Math.floor(t / 60);
|
|
|
|
|
var s = Math.floor((t - m * 60) * round) / round;
|
|
|
|
|
return m + "m" + s + "s";
|
2011-06-20 18:11:17 +02:00
|
|
|
}
|
|
|
|
|
}
|