#include <cassert>
+#include <QTimer>
+#include <QToolTip>
+
#include <libsigrok/libsigrok.hpp>
#include <pv/devicemanager.hpp>
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()
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()));
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
private Q_SLOTS:
void on_action(QObject *action);
+ void on_menu_hovered(QAction *action);
+
+ void on_menu_hover_timeout();
+
Q_SIGNALS:
void device_selected();
std::shared_ptr<sigrok::Device> selected_device_;
std::vector< std::weak_ptr<sigrok::Device> > devices_;
+
+ QString device_tooltip_;
};
} // widgets