]> sigrok.org Git - pulseview.git/commitdiff
Make trace popup combobox behave more user-friendly
authorSoeren Apel <redacted>
Tue, 26 Aug 2014 13:40:00 +0000 (15:40 +0200)
committerUwe Hermann <redacted>
Wed, 27 Aug 2014 16:54:35 +0000 (18:54 +0200)
pv/view/signal.cpp
pv/view/signal.h
pv/view/trace.cpp
pv/view/trace.h

index 0ce423feaae6b97e5bc6809d75fa368b0a71bccb..2ee4b1850ded6f36e18b817df0482d0bd9bba431 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QApplication>
 #include <QFormLayout>
+#include <QKeyEvent>
 #include <QLineEdit>
 #include <QMenu>
 
@@ -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<QKeyEvent*>(evt);
+               if (keyEvent->key() == Qt::Key_Enter ||
+                   keyEvent->key() == Qt::Key_Return) {
+                       close_popup();
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 void Signal::delete_pressed()
 {
        on_disable();
index 99b685c0bdc286f4f4f50e1b08290a8123e57acc..c003de698e3328e9301d1d9148698c3886333d75 100644 (file)
@@ -75,6 +75,8 @@ public:
 
        void delete_pressed();
 
+       bool eventFilter(QObject *obj, QEvent *evt);
+
 private slots:
        void on_disable();
 
index d3e7f0147b87df6adfd843ec174bca82ea96c3df..896fdec5a5ee50bb40409ad9bed7154b3c955e0d 100644 (file)
@@ -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;
index ace93d507a0a6c5832ff34f115468e400d360854..b82aaa6f792871c451be5a706478e499486e82bb 100644 (file)
@@ -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);