Binding: Add help icons for entries with descriptions
authorSoeren Apel <soeren@apelpie.net>
Tue, 4 Sep 2018 20:39:57 +0000 (22:39 +0200)
committerUwe Hermann <uwe@hermann-uwe.de>
Wed, 5 Sep 2018 22:25:00 +0000 (00:25 +0200)
icons/help-browser.png [new file with mode: 0644]
manual/import_export.txt
pulseview.qrc
pv/binding/binding.cpp
pv/binding/binding.hpp
pv/binding/device.hpp
pv/binding/inputoutput.cpp

diff --git a/icons/help-browser.png b/icons/help-browser.png
new file mode 100644 (file)
index 0000000..593ecd5
Binary files /dev/null and b/icons/help-browser.png differ
index b3ba772..2e5c8b2 100644 (file)
@@ -24,8 +24,9 @@ For example, the VCD import will ask you for these:
 * Number of logic channels: The number of (logic) channels in the data (default 0)
 * Skip samples until timestamp: Skip samples until the specified timestamp; < 0: Skip until first timestamp listed; 0: Don't skip (default -1)
 
-
-A click on _Ok_ then loads the data from the selected file and you can work with it.
+The detailed description of each item can also be seen when clicking on the help icon on the right
+or hovering your mouse over it. A click on _OK_ then loads the data from the selected file and you
+can work with it.
 
 === Export
 
index 4087fad..9b7510d 100644 (file)
@@ -9,6 +9,7 @@
        <file>icons/document-new.png</file>
        <file>icons/document-open.png</file>
        <file>icons/document-save-as.png</file>
+       <file>icons/help-browser.png</file>
        <file>icons/information.svg</file>
        <file>icons/media-playback-pause.png</file>
        <file>icons/media-playback-start.png</file>
index ddf0c19..9735e14 100644 (file)
 #include <cassert>
 
 #include <QFormLayout>
+#include <QHBoxLayout>
+#include <QIcon>
 #include <QLabel>
+#include <QPushButton>
 
 #include <pv/prop/property.hpp>
 
@@ -46,27 +49,56 @@ void Binding::commit()
        }
 }
 
-void Binding::add_properties_to_form(QFormLayout *layout,
-       bool auto_commit) const
+void Binding::add_properties_to_form(QFormLayout *layout, bool auto_commit)
 {
        assert(layout);
 
+       help_labels_.clear();
+
        for (shared_ptr<pv::prop::Property> p : properties_) {
                assert(p);
 
-               QWidget *const widget = p->get_widget(layout->parentWidget(), auto_commit);
+               QWidget *widget;
+               QLabel *help_lbl = nullptr;
+
+               if (p->desc().isEmpty()) {
+                       widget = p->get_widget(layout->parentWidget(), auto_commit);
+               } else {
+                       QPushButton *help_btn = new QPushButton();
+                       help_btn->setFlat(true);
+                       help_btn->setIcon(QIcon(":/icons/help-browser.png"));
+                       help_btn->setToolTip(p->desc());
+                       connect(help_btn, SIGNAL(clicked(bool)),
+                               this, SLOT(on_help_clicked()));
+
+                       QHBoxLayout *layout = new QHBoxLayout();
+                       layout->setContentsMargins(0, 0, 0, 0);
+                       layout->addWidget(p->get_widget(layout->parentWidget(), auto_commit));
+                       layout->addWidget(help_btn, 0, Qt::AlignRight);
+
+                       widget = new QWidget();
+                       widget->setLayout(layout);
+
+                       help_lbl = new QLabel(p->desc());
+                       help_lbl->setVisible(false);
+                       help_lbl->setWordWrap(true);
+                       help_labels_[help_btn] = help_lbl;
+               }
+
                if (p->labeled_widget()) {
                        layout->addRow(widget);
                } else {
                        auto *lbl = new QLabel(p->name());
-                       lbl->setToolTip(p->desc());
+                       lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
                        layout->addRow(lbl, widget);
                }
+
+               if (help_lbl)
+                       layout->addRow(help_lbl);
        }
 }
 
-QWidget* Binding::get_property_form(QWidget *parent,
-       bool auto_commit) const
+QWidget* Binding::get_property_form(QWidget *parent, bool auto_commit)
 {
        QWidget *const form = new QWidget(parent);
        QFormLayout *const layout = new QFormLayout(form);
@@ -98,5 +130,14 @@ QString Binding::print_gvariant(Glib::VariantBase gvar)
        return s;
 }
 
+void Binding::on_help_clicked()
+{
+       QPushButton *btn = qobject_cast<QPushButton*>(QObject::sender());
+       assert(btn);
+
+       QLabel *lbl = help_labels_.at(btn);
+       lbl->setVisible(!lbl->isVisible());
+}
+
 }  // namespace binding
 }  // namespace pv
index 6e92b08..5580a0b 100644 (file)
@@ -26,15 +26,19 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 #include <glibmm.h>
 G_GNUC_END_IGNORE_DEPRECATIONS
 
+#include <map>
 #include <memory>
 #include <vector>
 
+#include <QObject>
 #include <QString>
 
+using std::map;
 using std::shared_ptr;
 using std::vector;
 
 class QFormLayout;
+class QLabel;
 class QWidget;
 
 namespace pv {
@@ -45,25 +49,29 @@ class Property;
 
 namespace binding {
 
-class Binding
+class Binding: public QObject
 {
+       Q_OBJECT
+
 public:
        const vector< shared_ptr<prop::Property> >& properties();
 
        void commit();
 
-       void add_properties_to_form(QFormLayout *layout,
-               bool auto_commit = false) const;
+       void add_properties_to_form(QFormLayout *layout, bool auto_commit = false);
 
-       QWidget* get_property_form(QWidget *parent,
-               bool auto_commit = false) const;
+       QWidget* get_property_form(QWidget *parent, bool auto_commit = false);
 
        void update_property_widgets();
 
        static QString print_gvariant(Glib::VariantBase gvar);
 
+protected Q_SLOTS:
+       void on_help_clicked();
+
 protected:
        vector< shared_ptr<prop::Property> > properties_;
+       map<QWidget*, QLabel*> help_labels_;
 };
 
 }  // namespace binding
index aceac8c..d4fbf37 100644 (file)
@@ -42,7 +42,7 @@ namespace pv {
 
 namespace binding {
 
-class Device : public QObject, public Binding
+class Device : public Binding
 {
        Q_OBJECT
 
index 4aa0c0e..0d9b2d0 100644 (file)
@@ -65,6 +65,7 @@ InputOutput::InputOutput(
 
                const QString name = QString::fromStdString(opt->name());
                const QString desc = QString::fromStdString(opt->description());
+
                const VariantBase def_val = opt->default_value();
                const vector<VariantBase> values = opt->values();