Skip to content

Commit

Permalink
logic analyzer: reworked decoder tool tips to show on hover
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w committed Feb 15, 2024
1 parent fade8c6 commit 46a19b2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
50 changes: 31 additions & 19 deletions src/logicanalyzer/logic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2012,29 +2012,41 @@ void LogicAnalyzer::initBufferScrolling()

// When the plot is clicked emit the clicked signal on the curve
m_plot.setMouseTracking(true);
connect(&m_plot, &CapturePlot::mouseButtonPress, [=](const QMouseEvent *event) {
if (event == nullptr) return;

if (event->button() == Qt::LeftButton) {
const auto curve = m_plot.curveAt(event->pos());

if(curve) {
const QPointF curvePos = curve->screenPosToCurvePoint(event->pos());
const QString annInfo = dynamic_cast<AnnotationCurve *>(curve)
->annotationAt(curvePos)
.ann->annotations()[0];
scopy::HoverWidget *toolTip = createHoverToolTip(annInfo, event->pos());

QTimer::singleShot(2000, toolTip, &scopy::HoverWidget::deleteLater);
connect(&m_plot, &CapturePlot::mouseButtonRelease, toolTip, &scopy::HoverWidget::show);
connect(&m_plot, &CapturePlot::mouseButtonPress, toolTip, &scopy::HoverWidget::deleteLater);
connect(m_plot.getZoomer(), &OscPlotZoomer::zoomFinished, toolTip,
&scopy::HoverWidget::deleteLater);

Q_EMIT curve->clicked(curvePos);
QTimer *timer = new QTimer();
timer->setInterval(500);
lastToolTipAnn = NULL;

connect(timer, &QTimer::timeout, this, [=]() {
QPoint pos = m_plot.mapFromGlobal(QCursor::pos());
GenericLogicPlotCurve *curve = m_plot.curveAt(pos);

if(curve) {
const QPointF curvePos = curve->screenPosToCurvePoint(pos);
const QString *annInfo =
&dynamic_cast<AnnotationCurve *>(curve)->annotationAt(curvePos).ann->annotations()[0];

if(lastToolTipAnn != annInfo) {
scopy::HoverWidget *toolTip = createHoverToolTip(*annInfo, pos);
QTimer::singleShot(500, [toolTip, annInfo, this]() {
if(toolTip && lastToolTipAnn == annInfo)
toolTip->show();
});
Q_EMIT deleteToolTips();

lastToolTipAnn = annInfo;
connect(this, &LogicAnalyzer::deleteToolTips, toolTip,
&scopy::HoverWidget::deleteLater);
}
} else {
if(lastToolTipAnn != NULL) {
Q_EMIT deleteToolTips();
}
lastToolTipAnn = NULL;
}
});

timer->start();
}


Expand Down
3 changes: 2 additions & 1 deletion src/logicanalyzer/logic_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class LogicAnalyzer : public LogicTool {
int getGroupOffset();
Q_SIGNALS:
void showTool();
void deleteToolTips();

private Q_SLOTS:

Expand Down Expand Up @@ -259,7 +260,7 @@ private Q_SLOTS:
DropdownSwitchList* filterMessages;
int filterCount = 0;


const QString *lastToolTipAnn;
};
} // namespace logic
} // namespace adiscope
Expand Down

0 comments on commit 46a19b2

Please sign in to comment.