From: Soeren Apel Date: Tue, 26 Aug 2014 13:40:00 +0000 (+0200) Subject: Make trace popup combobox behave more user-friendly X-Git-Tag: pulseview-0.3.0~559 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3c1001230d7dd6ee68d21ed46082f5f97d3b4bfc;p=pulseview.git Make trace popup combobox behave more user-friendly --- diff --git a/pv/view/signal.cpp b/pv/view/signal.cpp index 0ce423fe..2ee4b185 100644 --- a/pv/view/signal.cpp +++ b/pv/view/signal.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -94,18 +95,32 @@ const sr_channel* Signal::probe() const void Signal::populate_popup_form(QWidget *parent, QFormLayout *form) { + int index; + _name_widget = new QComboBox(parent); _name_widget->setEditable(true); for(unsigned int i = 0; i < countof(ProbeNames); i++) _name_widget->insertItem(i, ProbeNames[i]); - _name_widget->setEditText(_name); + + index = _name_widget->findText(_name, Qt::MatchExactly); + + if (index == -1) { + _name_widget->insertItem(0, _name); + _name_widget->setCurrentIndex(0); + } else { + _name_widget->setCurrentIndex(index); + } + _name_widget->lineEdit()->selectAll(); _name_widget->setFocus(); connect(_name_widget, SIGNAL(editTextChanged(const QString&)), this, SLOT(on_text_changed(const QString&))); + // We want to close the popup when the Enter key was pressed. + _name_widget->installEventFilter(this); + form->addRow(tr("Name"), _name_widget); add_colour_option(parent, form); @@ -125,6 +140,24 @@ QMenu* Signal::create_context_menu(QWidget *parent) return menu; } +bool Signal::eventFilter(QObject *obj, QEvent *evt) +{ + QKeyEvent *keyEvent; + + (void)obj; + + if (evt->type() == QEvent::KeyPress) { + keyEvent = static_cast(evt); + if (keyEvent->key() == Qt::Key_Enter || + keyEvent->key() == Qt::Key_Return) { + close_popup(); + return true; + } + } + + return false; +} + void Signal::delete_pressed() { on_disable(); diff --git a/pv/view/signal.h b/pv/view/signal.h index 99b685c0..c003de69 100644 --- a/pv/view/signal.h +++ b/pv/view/signal.h @@ -75,6 +75,8 @@ public: void delete_pressed(); + bool eventFilter(QObject *obj, QEvent *evt); + private slots: void on_disable(); diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index d3e7f014..896fdec5 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -272,6 +272,11 @@ void Trace::populate_popup_form(QWidget *parent, QFormLayout *form) add_colour_option(parent, form); } +void Trace::close_popup() +{ + _popup->close(); +} + void Trace::on_popup_closed() { _popup = NULL; diff --git a/pv/view/trace.h b/pv/view/trace.h index ace93d50..b82aaa6f 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -173,6 +173,8 @@ protected: virtual void populate_popup_form(QWidget *parent, QFormLayout *form); + void close_popup(); + private slots: void on_text_changed(const QString &text);