Use device::Devices to represent sigrok Devices
[pulseview.git] / pv / widgets / devicetoolbutton.cpp
index 27ba31a62120d5e97a2085fed6e4337d204116b6..7ba8aa28ce6704a0553911890af33fd3ef86ff74 100644 (file)
 
 #include <cassert>
 
-#include <libsigrok/libsigrok.hpp>
+#include <QTimer>
+#include <QToolTip>
+
+#include <libsigrokcxx/libsigrokcxx.hpp>
 
 #include <pv/devicemanager.hpp>
+#include <pv/devices/device.hpp>
 
 #include "devicetoolbutton.hpp"
 
@@ -32,7 +36,7 @@ using std::string;
 using std::weak_ptr;
 using std::vector;
 
-using sigrok::Device;
+using pv::devices::Device;
 
 namespace pv {
 namespace widgets {
@@ -54,6 +58,9 @@ DeviceToolButton::DeviceToolButton(QWidget *parent,
 
        connect(&mapper_, SIGNAL(mapped(QObject*)),
                this, SLOT(on_action(QObject*)));
+
+       connect(&menu_, SIGNAL(hovered(QAction*)),
+               this, SLOT(on_menu_hovered(QAction*)));
 }
 
 shared_ptr<Device> DeviceToolButton::selected_device()
@@ -88,6 +95,7 @@ void DeviceToolButton::update_device_list()
                a->setCheckable(true);
                a->setChecked(selected_device_ == dev);
                a->setData(qVariantFromValue((void*)dev.get()));
+               a->setToolTip(QString::fromStdString(device_manager_.get_full_name(dev)));
                mapper_.setMapping(a, a);
 
                connect(a, SIGNAL(triggered()), &mapper_, SLOT(map()));
@@ -116,5 +124,30 @@ void DeviceToolButton::on_action(QObject *action)
        device_selected();
 }
 
+void DeviceToolButton::on_menu_hovered(QAction *action)
+{
+       assert(action);
+
+       // Only show the tooltip for device entries (they hold
+       // device pointers in their data field)
+       if (!action->data().isValid())
+               return;
+
+       device_tooltip_ = action->toolTip();
+
+       if (QToolTip::isVisible())
+               on_menu_hover_timeout();
+       else
+               QTimer::singleShot(1000, this, SLOT(on_menu_hover_timeout()));
+}
+
+void DeviceToolButton::on_menu_hover_timeout()
+{
+       if (device_tooltip_.isEmpty())
+               return;
+
+       QToolTip::showText(QCursor::pos(), device_tooltip_);
+}
+
 } // widgets
 } // pv