]> sigrok.org Git - pulseview.git/blobdiff - pv/toolbars/samplingbar.cpp
SamplingBar: Use nicer time format in the tooltip.
[pulseview.git] / pv / toolbars / samplingbar.cpp
index 91c4b076ea6346d46102100ec20eec4a0c201756..085e0430582e08b5ff488b7b1d2a708ef35bca35 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <QAction>
 #include <QDebug>
+#include <QHelpEvent>
+#include <QToolTip>
 
 #include "samplingbar.h"
 
@@ -33,6 +35,7 @@
 #include <pv/device/devinst.h>
 #include <pv/popups/deviceoptions.h>
 #include <pv/popups/probes.h>
+#include <pv/util.h>
 
 using boost::shared_ptr;
 using std::map;
@@ -93,6 +96,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 +452,21 @@ 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();
+               QHelpEvent *help_event = static_cast<QHelpEvent*>(event);
+
+               QString str = tr("Total sampling time: %1").arg(pv::util::format_second(sec));
+               QToolTip::showText(help_event->globalPos(), str);
+
+               return true;
+       }
+
+       return false;
+}
+
 } // namespace toolbars
 } // namespace pv