Skip to content

Commit

Permalink
Merge pull request #188 from patrickelectric/fix180
Browse files Browse the repository at this point in the history
Fix180
  • Loading branch information
patrickelectric authored Jun 27, 2018
2 parents 241f39b + 87a940e commit ce526c8
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 89 deletions.
2 changes: 1 addition & 1 deletion qml/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Item {

onPointsUpdate: {
// Move from mm to m
ping1DVisualizer.draw(ping.points, (ping.length_mm - ping.start_mm) * 1e-3, ping.confidence, ping.start_mm*1e-3)
ping1DVisualizer.draw(ping.points, (ping.length_mm - ping.start_mm) * 1e-3, ping.confidence, ping.start_mm*1e-3, ping.distance*1e-3)
}

onDistanceUpdate: {
Expand Down
54 changes: 49 additions & 5 deletions qml/Ping1DVisualizer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Item {
}
}

function draw(points, depth, confidence, initialPoint) {
waterfall.draw(points, depth, confidence, initialPoint)
function draw(points, depth, confidence, initialPoint, distance) {
waterfall.draw(points, depth, confidence, initialPoint, distance)
chart.draw(points, depth, initialPoint)
}

Expand All @@ -41,10 +41,46 @@ Item {
Layout.preferredWidth: 350
Layout.minimumWidth: 350
onMouseMove: {
readout.depth = Math.max(waterfall.mouseDepth, 0)
readout.strength = Math.max(waterfall.mouseStrength, 0)
readout.columnDepth = Math.max(waterfall.mouseColumnDepth, 0)
readout.columnConfidence = Math.max(waterfall.mouseColumnConfidence, 0)
}

Rectangle {
x: waterfall.mousePos.x - width/2 + height/2
y: width/2
height: 15
width: waterfall.height
transform: Rotation { origin.x: height/2; angle: 90}
gradient: Gradient {
GradientStop { position: 0.3; color: "transparent" }
GradientStop { position: 0.5; color: Style.color }
GradientStop { position: 0.8; color: "transparent" }
}

ColumnLayout {
x: waterfall.mousePos.y - width/2
y: -height*2
rotation: -90
Text {
id: mouseReadout
text: waterfall.mouseColumnDepth.toFixed(2) + "m"
color: confidenceToColor(waterfall.mouseColumnConfidence)
font.family: "Arial"
font.pointSize: 15
font.bold: true

Text {
id: mouseConfidenceText
x: mouseReadout.width - width
y: mouseReadout.height*4/5
text: transformValue(waterfall.mouseColumnConfidence) + "%"
visible: typeof(waterfall.mouseColumnConfidence) == "number"
color: confidenceToColor(waterfall.mouseColumnConfidence)
font.family: "Arial"
font.pointSize: 10
font.bold: true
}
}
}
}
}

Expand All @@ -66,4 +102,12 @@ Item {
ValueReadout {
id: readout
}

function confidenceToColor(confidence) {
return Qt.rgba(2*(1 - confidence/100), 2*confidence/100, 0)
}

function transformValue(value, precision) {
return typeof(value) == "number" ? value.toFixed(precision) : value + ' '
}
}
1 change: 1 addition & 0 deletions qml/Style.qml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import QtQuick.Controls.Material 2.1
QtObject {
property color textColor: 'linen'
property color iconColor: textColor
property color color: isDark ? "black" : "linen"
property string dark: "dark"
property string light: "light"
property bool isDark: true
Expand Down
93 changes: 17 additions & 76 deletions qml/ValueReadout.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import QtQuick 2.0
import QtQuick 2.7
import Qt.labs.settings 1.0
import QtQuick.Layouts 1.3

Expand All @@ -12,11 +12,8 @@ Item {
property string units: "m"
property real precision: 2
property int margin: 10
property real depth: -1
property real strength: -1
property real confidence: 0
property real columnConfidence: 0
property real columnDepth: 0
property int parentWidth: 0
property int parentHeight: 0

Expand Down Expand Up @@ -49,83 +46,27 @@ Item {

ColumnLayout {
id: mainLayout
RowLayout {
Text {
id: readout
text: value.toFixed(precision) + units
color: confidenceToColor(confidence)
font.family: "Arial"
font.pointSize: 48
font.bold: true
}

Rectangle {
Layout.fillWidth: true
color: "transparent"
}

Text {
Text {
id: readout
width: textMetrics.width
height: textMetrics.height
text: value.toFixed(precision) + units
color: confidenceToColor(confidence)
font.family: "Arial"
font.pointSize: 48
font.bold: true

Text {
id: confidenceText
text: transformValue(confidence) + '%'
x: readout.width - width
y: readout.height*4/5
text: "Confidence: " + transformValue(confidence) + "%"
visible: typeof(strength) == "number"
color: confidenceToColor(confidence)
font.family: "Arial"
font.pointSize: readout.font.pointSize
font.bold: true
}
}

RowLayout {
Text {
id: textColumnDepth
text: transformValue(columnDepth, precision) + units
visible: typeof(strength) == "number"
color: confidenceToColor(columnConfidence)
font.family: "Arial"
font.pointSize: 14
font.bold: true
}

Rectangle {
Layout.fillWidth: true
color: "transparent"
}

Text {
id: textColumnConfidence
text: transformValue(columnConfidence, 0) + '%'
visible: typeof(strength) == "number"
color: confidenceToColor(columnConfidence)
font.family: "Arial"
font.pointSize: 14
font.bold: true
}
}

RowLayout {
Text {
id: depthText
text: transformValue(depth, precision) + units
visible: typeof(strength) == "number"
color: 'white'
font.family: "Arial"
font.pointSize: 14
font.bold: true
}

Rectangle {
Layout.fillWidth: true
color: "transparent"
}

Text {
id: strengthText
text: transformValue(strength*100, 0) + '%'
visible: typeof(strength) == "number"
color: 'white'
font.family: "Arial"
font.pointSize: 14
font.pointSize: readout.font.pointSize/3
font.bold: true
anchors.margins: 0
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/waterfall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ uint16_t Waterfall::displayWidth = 500;

Waterfall::Waterfall(QQuickItem *parent):
QQuickPaintedItem(parent),
_image(2048, 2000, QImage::Format_RGBA8888),
_image(2048, 2500, QImage::Format_RGBA8888),
_painter(nullptr),
_maxDepthToDrawInPixels(0),
_minDepthToDrawInPixels(0),
Expand All @@ -25,8 +25,8 @@ Waterfall::Waterfall(QQuickItem *parent):
currentDrawIndex(displayWidth)
{
// This is the max depth that ping returns
setWaterfallMaxDepth(48.903);
_DCRing.fill({static_cast<const float>(_image.height()), 0, 0}, displayWidth);
setWaterfallMaxDepth(70);
_DCRing.fill({static_cast<const float>(_image.height()), 0, 0, 0}, displayWidth);
setAntialiasing(_smooth);
setAcceptedMouseButtons(Qt::AllButtons);
setAcceptHoverEvents(true);
Expand Down Expand Up @@ -182,11 +182,11 @@ float Waterfall::RGBToValue(const QColor& color)
return _gradient.getValue(color);
}

void Waterfall::draw(const QList<double>& points, float depth, float confidence, float initPoint)
void Waterfall::draw(const QList<double>& points, float depth, float confidence, float initPoint, float distance)
{
static QImage old = _image;
static QList<double> oldPoints = points;
_DCRing.append({initPoint, depth, confidence});
_DCRing.append({initPoint, depth, confidence, distance});

int virtualHeight = floor(_pixelsPerMeter*depth);
int virtualFloor = floor(_pixelsPerMeter*initPoint);
Expand Down Expand Up @@ -271,6 +271,8 @@ void Waterfall::hoverMoveEvent(QHoverEvent *event)
{
event->accept();
auto pos = event->pos();
_mousePos = pos;
emit mousePosChanged();

static uint16_t first;
if (currentDrawIndex < displayWidth) {
Expand All @@ -292,7 +294,7 @@ void Waterfall::hoverMoveEvent(QHoverEvent *event)

const auto& depthAndConfidence = _DCRing[displayWidth - widthPos];
_mouseColumnConfidence = depthAndConfidence.confidence;
_mouseColumnDepth = depthAndConfidence.depth;
_mouseColumnDepth = depthAndConfidence.distance;
emit mouseColumnConfidenceChanged();
emit mouseColumnDepthChanged();
}
Expand Down
14 changes: 13 additions & 1 deletion src/waterfall.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class Waterfall : public QQuickPaintedItem
float mouseColumnDepth() {return _mouseColumnDepth;}
Q_PROPERTY(float mouseColumnDepth READ mouseColumnDepth NOTIFY mouseColumnDepthChanged)

/**
* @brief Return mouse position
*
* @return QPoint
*/
QPoint mousePos() {return _mousePos;}
Q_PROPERTY(QPoint mousePos READ mousePos NOTIFY mousePosChanged)

/**
* @brief Get signal confidence from mouse column
*
Expand Down Expand Up @@ -122,6 +130,7 @@ class Waterfall : public QQuickPaintedItem
float _mouseColumnConfidence;
float _mouseColumnDepth;
float _mouseDepth;
QPoint _mousePos;
float _mouseStrength;
bool _smooth;
QTimer* _updateTimer;
Expand All @@ -139,6 +148,7 @@ class Waterfall : public QQuickPaintedItem
float initialDepth;
float depth;
float confidence;
float distance;
};

RingVector<DCPack> _DCRing;
Expand All @@ -152,6 +162,7 @@ class Waterfall : public QQuickPaintedItem
void mouseColumnConfidenceChanged();
void mouseColumnDepthChanged();
void mouseMove();
void mousePosChanged();
void mouseStrengthChanged();
void mouseLeave();
void themeChanged();
Expand Down Expand Up @@ -224,8 +235,9 @@ class Waterfall : public QQuickPaintedItem
* @param depth
* @param confidence
* @param initPoint
* @param distance
*/
Q_INVOKABLE void draw(const QList<double>& points, float depth = 50, float confidence = 0, float initPoint = 0);
Q_INVOKABLE void draw(const QList<double>& points, float depth = 50, float confidence = 0, float initPoint = 0, float distance = 0);

/**
* @brief Function that deals when the mouse is inside the waterfall
Expand Down

0 comments on commit ce526c8

Please sign in to comment.