]> sigrok.org Git - pulseview.git/commitdiff
Fix #489 by implementing device tool button tooltip
authorSoeren Apel <redacted>
Mon, 5 Jan 2015 17:34:53 +0000 (18:34 +0100)
committerJoel Holdsworth <redacted>
Sat, 10 Jan 2015 16:54:15 +0000 (16:54 +0000)
pv/widgets/devicetoolbutton.cpp
pv/widgets/devicetoolbutton.hpp

index 27ba31a62120d5e97a2085fed6e4337d204116b6..ffa1cc6546561f74ceebba4b198e5a85d702cd71 100644 (file)
@@ -20,6 +20,9 @@
 
 #include <cassert>
 
+#include <QTimer>
+#include <QToolTip>
+
 #include <libsigrok/libsigrok.hpp>
 
 #include <pv/devicemanager.hpp>
@@ -54,6 +57,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 +94,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 +123,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
index 1fb0a54486057cbcd776b3f782580d54f416ea43..684d87b0b2bb72f05cf2c063178c92621411c73a 100644 (file)
@@ -79,6 +79,10 @@ private:
 private Q_SLOTS:
        void on_action(QObject *action);
 
+       void on_menu_hovered(QAction *action);
+
+       void on_menu_hover_timeout();
+
 Q_SIGNALS:
        void device_selected();
 
@@ -91,6 +95,8 @@ private:
 
        std::shared_ptr<sigrok::Device> selected_device_;
        std::vector< std::weak_ptr<sigrok::Device> > devices_;
+
+       QString device_tooltip_;
 };
 
 } // widgets