From: Soeren Apel Date: Tue, 4 Sep 2018 20:39:57 +0000 (+0200) Subject: Binding: Add help icons for entries with descriptions X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=commitdiff_plain;h=4e2195c8d934f7f874b612eaace8c6849e8b475d;hp=1894027b98640702a5229c4168c586df5f83a3af Binding: Add help icons for entries with descriptions --- diff --git a/icons/help-browser.png b/icons/help-browser.png new file mode 100644 index 0000000..593ecd5 Binary files /dev/null and b/icons/help-browser.png differ diff --git a/manual/import_export.txt b/manual/import_export.txt index b3ba772..2e5c8b2 100644 --- a/manual/import_export.txt +++ b/manual/import_export.txt @@ -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 diff --git a/pulseview.qrc b/pulseview.qrc index 4087fad..9b7510d 100644 --- a/pulseview.qrc +++ b/pulseview.qrc @@ -9,6 +9,7 @@ icons/document-new.png icons/document-open.png icons/document-save-as.png + icons/help-browser.png icons/information.svg icons/media-playback-pause.png icons/media-playback-start.png diff --git a/pv/binding/binding.cpp b/pv/binding/binding.cpp index ddf0c19..9735e14 100644 --- a/pv/binding/binding.cpp +++ b/pv/binding/binding.cpp @@ -20,7 +20,10 @@ #include #include +#include +#include #include +#include #include @@ -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 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(QObject::sender()); + assert(btn); + + QLabel *lbl = help_labels_.at(btn); + lbl->setVisible(!lbl->isVisible()); +} + } // namespace binding } // namespace pv diff --git a/pv/binding/binding.hpp b/pv/binding/binding.hpp index 6e92b08..5580a0b 100644 --- a/pv/binding/binding.hpp +++ b/pv/binding/binding.hpp @@ -26,15 +26,19 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS #include G_GNUC_END_IGNORE_DEPRECATIONS +#include #include #include +#include #include +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 >& 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 > properties_; + map help_labels_; }; } // namespace binding diff --git a/pv/binding/device.hpp b/pv/binding/device.hpp index aceac8c..d4fbf37 100644 --- a/pv/binding/device.hpp +++ b/pv/binding/device.hpp @@ -42,7 +42,7 @@ namespace pv { namespace binding { -class Device : public QObject, public Binding +class Device : public Binding { Q_OBJECT diff --git a/pv/binding/inputoutput.cpp b/pv/binding/inputoutput.cpp index 4aa0c0e..0d9b2d0 100644 --- a/pv/binding/inputoutput.cpp +++ b/pv/binding/inputoutput.cpp @@ -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 values = opt->values();