#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"
using std::weak_ptr;
using std::vector;
-using sigrok::Device;
+using pv::devices::Device;
namespace pv {
namespace widgets {
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()
const list< shared_ptr<Device> > &devices, shared_ptr<Device> selected)
{
selected_device_ = selected;
- setText(QString::fromStdString(
- device_manager_.get_display_name(selected)));
+ setText(selected ? QString::fromStdString(
+ selected->display_name(device_manager_)) : "<No Device>");
devices_ = vector< weak_ptr<Device> >(devices.begin(), devices.end());
update_device_list();
}
menu_.addSeparator();
for (weak_ptr<Device> dev_weak_ptr : devices_) {
- shared_ptr<Device> dev(dev_weak_ptr);
+ shared_ptr<Device> dev(dev_weak_ptr.lock());
if (!dev)
continue;
QAction *const a = new QAction(QString::fromStdString(
- device_manager_.get_display_name(dev)), this);
+ dev->display_name(device_manager_)), this);
a->setCheckable(true);
a->setChecked(selected_device_ == dev);
a->setData(qVariantFromValue((void*)dev.get()));
+ a->setToolTip(QString::fromStdString(dev->full_name()));
mapper_.setMapping(a, a);
connect(a, SIGNAL(triggered()), &mapper_, SLOT(map()));
update_device_list();
setText(QString::fromStdString(
- device_manager_.get_display_name(selected_device_)));
+ selected_device_->display_name(device_manager_)));
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