Skip to content

Commit

Permalink
logic analyzer / pattern generator: added annotation tool tips on hover
Browse files Browse the repository at this point in the history
- tool tips show on hover with a 500ms delay

Signed-off-by: Andrei Popa <[email protected]>
  • Loading branch information
andrei47w authored and adisuciu committed Feb 20, 2024
1 parent e011859 commit d41900a
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 27 deletions.
71 changes: 45 additions & 26 deletions src/logicanalyzer/logic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ void LogicAnalyzer::connectSignalsAndSlots()
}
}
});

initDecoderToolTips();
}

void LogicAnalyzer::triggerRightMenuToggle(CustomPushButton *btn, bool checked)
Expand Down Expand Up @@ -2009,32 +2011,6 @@ void LogicAnalyzer::initBufferScrolling()
m_horizOffset = 1.0 / m_sampleRate * m_bufferSize / 2.0 +
(ui->btnStreamOneShot ? 0 : m_timeTriggerOffset / m_sampleRate);
});

// 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);
}
}
});
}


Expand Down Expand Up @@ -2062,6 +2038,49 @@ scopy::HoverWidget *LogicAnalyzer::createHoverToolTip(QString info, QPoint posit
return toolTip;
}

void LogicAnalyzer::initDecoderToolTips()
{
QTimer *timer = new QTimer(this);
timer->setInterval(500);
lastToolTipAnn = NULL;

connect(timer, &QTimer::timeout, this, [=]() {
QPoint pos = m_plot.mapFromGlobal(QCursor::pos());
if(!m_plot.underMouse()) {
lastToolTipAnn = NULL;
Q_EMIT deleteToolTips();
return;
}

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();
}

void LogicAnalyzer::fitViewport(double min, double max)
{
if (min > max) {
Expand Down
4 changes: 3 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 @@ -183,6 +184,7 @@ private Q_SLOTS:
void waitForDecoders();

scopy::HoverWidget *createHoverToolTip(QString info, QPoint position);
void initDecoderToolTips();

private:
// TODO: consisten naming (m_ui, m_crUi)
Expand Down Expand Up @@ -259,7 +261,7 @@ private Q_SLOTS:
DropdownSwitchList* filterMessages;
int filterCount = 0;


const QString *lastToolTipAnn;
};
} // namespace logic
} // namespace adiscope
Expand Down
70 changes: 70 additions & 0 deletions src/patterngenerator/pattern_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,74 @@ void PatternGenerator::updateAnnotationCurveChannelsForPattern(const QPair<QVect
}
}


scopy::HoverWidget *PatternGenerator::createHoverToolTip(QString info, QPoint position)
{
QLabel *label = new QLabel(info);
label->setStyleSheet("QLabel {"
" font-weight: bold;"
" color: #FFFFFF;"
"}");

QWidget *content = new QWidget();
content->setStyleSheet("QWidget {"
" background-color: #272730;"
"}");

QHBoxLayout *layout = new QHBoxLayout(content);
layout->addWidget(label);

scopy::HoverWidget *toolTip = new scopy::HoverWidget(content, &m_plot, QApplication::activeWindow());
toolTip->setAnchorPos(scopy::HoverPosition::HP_TOPLEFT);
toolTip->setContentPos(scopy::HoverPosition::HP_TOPLEFT);
toolTip->setAnchorOffset(position);

return toolTip;
}

void PatternGenerator::initDecoderToolTips()
{
QTimer *timer = new QTimer(this);
timer->setInterval(500);
lastToolTipAnn = NULL;

connect(timer, &QTimer::timeout, this, [=]() {
QPoint pos = m_plot.mapFromGlobal(QCursor::pos());
if(!m_plot.underMouse()) {
lastToolTipAnn = NULL;
Q_EMIT deleteToolTips();
return;
}

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, &PatternGenerator::deleteToolTips, toolTip,
&scopy::HoverWidget::deleteLater);
}
} else {
if(lastToolTipAnn != NULL) {
Q_EMIT deleteToolTips();
}
lastToolTipAnn = NULL;
}
});

timer->start();
}

void PatternGenerator::patternSelected(const QString &pattern, int ch, const QString &json)
{
int selected = ch != -1 ? ch : m_selectedChannel;
Expand Down Expand Up @@ -951,6 +1019,8 @@ void PatternGenerator::connectSignalsAndSlots()
m_ui->runSingleWidget->toggle(false);
}
});

initDecoderToolTips();
}

void PatternGenerator::updateChannelGroupWidget(bool visible)
Expand Down
5 changes: 5 additions & 0 deletions src/patterngenerator/pattern_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <libm2k/contextbuilder.hpp>
#include <libm2k/digital/m2kdigital.hpp>
#include <libm2k/enums.hpp>
#include <gui/hoverwidget.h>

#include <QScrollBar>
#include <QQueue>
Expand Down Expand Up @@ -70,6 +71,7 @@ class PatternGenerator : public LogicTool

Q_SIGNALS:
void showTool();
void deleteToolTips();

private Q_SLOTS:
void startStop(bool start);
Expand Down Expand Up @@ -108,6 +110,8 @@ private Q_SLOTS:
void checkEnabledChannels();
void removeAnnotationCurveOfPattern(PatternUI *pattern);
void updateAnnotationCurveChannelsForPattern(const QPair<QVector<int>, PatternUI *> &pattern);
scopy::HoverWidget *createHoverToolTip(QString info, QPoint position);
void initDecoderToolTips();

private:
Ui::PatternGenerator *m_ui;
Expand Down Expand Up @@ -139,6 +143,7 @@ private Q_SLOTS:
QTimer *m_singleTimer;

QMap<PatternUI*, QPair<GenericLogicPlotCurve*, QMetaObject::Connection>> m_annotationCurvePatternUiMap;
const QString *lastToolTipAnn;
};

} // namespace logic
Expand Down

0 comments on commit d41900a

Please sign in to comment.