SamplingBar: Show total sampling time in a tooltip.
authorJens Steinhauser <jens.steinhauser@gmail.com>
Thu, 22 May 2014 20:03:21 +0000 (22:03 +0200)
committerJoel Holdsworth <joel@airwebreathe.org.uk>
Fri, 23 May 2014 20:07:36 +0000 (21:07 +0100)
pv/toolbars/samplingbar.cpp
pv/toolbars/samplingbar.h

index 91c4b076ea6346d46102100ec20eec4a0c201756..05c730bf528fe35efdab94acea14be9183838fd6 100644 (file)
@@ -26,6 +26,8 @@
 
 #include <QAction>
 #include <QDebug>
+#include <QHelpEvent>
+#include <QToolTip>
 
 #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<QHelpEvent*>(event);
+               QToolTip::showText(help_event->globalPos(), str);
+
+               return true;
+       }
+
+       return false;
+}
+
 } // namespace toolbars
 } // namespace pv
index e59d2f9f0b195da8417c126de2ea6f4ec7f53539..e2e24b788145bb3ca227b8931e6b13af934a7761 100644 (file)
@@ -89,6 +89,9 @@ private slots:
 
        void on_config_changed();
 
+protected:
+       bool eventFilter(QObject *watched, QEvent *event);
+
 private:
        SigSession &_session;