From: Jens Steinhauser Date: Thu, 22 May 2014 20:03:21 +0000 (+0200) Subject: SamplingBar: Show total sampling time in a tooltip. X-Git-Tag: pulseview-0.3.0~619 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=40065ab65c4f347ac5c3731fcea628ab26b49c1e;p=pulseview.git SamplingBar: Show total sampling time in a tooltip. --- diff --git a/pv/toolbars/samplingbar.cpp b/pv/toolbars/samplingbar.cpp index 91c4b076..05c730bf 100644 --- a/pv/toolbars/samplingbar.cpp +++ b/pv/toolbars/samplingbar.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include "samplingbar.h" @@ -93,6 +95,9 @@ SamplingBar::SamplingBar(SigSession &session, QWidget *parent) : addWidget(&_sample_rate); addWidget(&_run_stop_button); + + _sample_count.installEventFilter(this); + _sample_rate.installEventFilter(this); } void SamplingBar::set_device_list( @@ -446,5 +451,28 @@ void SamplingBar::on_config_changed() update_sample_rate_selector(); } +bool SamplingBar::eventFilter(QObject *watched, QEvent *event) +{ + if ((watched == &_sample_count || watched == &_sample_rate) && + (event->type() == QEvent::ToolTip)) { + double sec = (double)_sample_count.value() / _sample_rate.value(); + + QString str; + QTextStream(&str) + << tr("Total sampling time: ") + << fixed + << qSetRealNumberPrecision(1) + << sec + << "s"; + + QHelpEvent *help_event = static_cast(event); + QToolTip::showText(help_event->globalPos(), str); + + return true; + } + + return false; +} + } // namespace toolbars } // namespace pv diff --git a/pv/toolbars/samplingbar.h b/pv/toolbars/samplingbar.h index e59d2f9f..e2e24b78 100644 --- a/pv/toolbars/samplingbar.h +++ b/pv/toolbars/samplingbar.h @@ -89,6 +89,9 @@ private slots: void on_config_changed(); +protected: + bool eventFilter(QObject *watched, QEvent *event); + private: SigSession &_session;