From 4e2195c8d934f7f874b612eaace8c6849e8b475d Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Tue, 4 Sep 2018 22:39:57 +0200 Subject: [PATCH] Binding: Add help icons for entries with descriptions --- icons/help-browser.png | Bin 0 -> 1566 bytes manual/import_export.txt | 5 ++-- pulseview.qrc | 1 + pv/binding/binding.cpp | 53 ++++++++++++++++++++++++++++++++----- pv/binding/binding.hpp | 18 +++++++++---- pv/binding/device.hpp | 2 +- pv/binding/inputoutput.cpp | 1 + 7 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 icons/help-browser.png diff --git a/icons/help-browser.png b/icons/help-browser.png new file mode 100644 index 0000000000000000000000000000000000000000..593ecd5b3f717ac23feb7215b6d20b71e3f9acfb GIT binary patch literal 1566 zcmZ`(dpOez82$}IMCG0pQ;pm=RxX*#X6CYKF>((xEDdQhm)Pndw;DHxq_0Dv6<#hwQM1{?qud;!2T7XTE) z3tP^a2?nD64mfMz*Y7B8t-K>(#OQVetk?_~vQJii3^Rxj?Eh(JZAG%}YQ5`;C*hR3 zSYHZFuJpSTt-uOZZ8J4d?j*UzQ#OmRL-qMc1och+6Yl7HAD@_ew3*q9{{Ewl?{jvD zZ}O2;qzz9YEyo`FM){z10$5QWD#wrVyEa!iB<5NkTum5?@5zbI+m2r^+1@i;RZaR{ zA=@B&r?N|FMZkN3HD*sH!{wj>dxtkd&AT91?W`42 zTX*kA&<^=DIyg8#mCrw!dcEAT92Wg$8;tLDoUW#c?Oc3L>%5&=eqL22GL@u@-7`W%c^$PMC|5QxL{aWicC12`Eo_O{&mSGJN&oBXt%bRn+28 zVXe+v6Ep)uh#aW2ZZRpcV%F-^O~DXZ`N=Pn&PdUwyqJwjy?c9l0d6xAW#{OoO=cm;=QYnB~Ap8iX%t@*Q~&QKc?##Kvc96#}4#f9YJZsyg#ADRzYbyEFm zEiUD)h|!#zx=iyaz)e&j0llWl86sAsH_Pot2b}IP8fFO727h2w?&sZ1X96zgOoW))Gtfwfe?!#?N6 zWl+wsiMK+6KvP0`dNqrg`QO^ljAAZkf@?61O(oYrkgm(&M{}NUj}-DRULJUVp-Pxz zCX#H??D-^qn>_GrDk^ZUV%AuivovGe57kwP`zdUFFK%PAb3R=v!!TaXd_~-RXM>nd zJF~d*OIsy|5Lbn{f8~my;>uO#Ewk7)(@E7@+#nJ^JCP`n@R}$OF4KHihys-`Pk5qt zW8+b*xmJfH^N$P`ie?Peth+k-nB#eP@@}!DPQhXhM1p&#Fxc1r*2EqN&qE+kDS3PK za{ayKWpm7}&h)L##>R;#R@53!D;ZbL+zY9y{&dq@GKdnJ{b~2sR0k54fe>Y{-nDo@ zYgs;mibF(lTX@Y?Yr|vX(_}^V@*kBdlD48Y!sLyFtjova(z1IxvPu#Dm!yxWVcR3W zO)PVQnVw`8b1ZS0J3BWO2{K~qmC7gY6$ydd*kVeD25wvWKSPwS6-{u`nX@Ck!b__b z9VN#dnmA7f6#@mn5k|+l(F6SG6jO2pMF4;S9AT^rKc#D6M1mWcB1}vT5ZZ79Q#gF| zCI7>J479KSYGCyL8>$LqLIj4xzb`n41=5**5fp&QWa?2vL#~kh!YO)T5kUpZX37E) NV25?Iu0i`={}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 ddf0c19a..9735e146 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 6e92b083..5580a0b0 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 aceac8cc..d4fbf371 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 4aa0c0ea..0d9b2d0d 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(); -- 2.30.2