]> sigrok.org Git - pulseview.git/commitdiff
Make decoder popups close when pressing enter
authorSoeren Apel <redacted>
Tue, 2 Sep 2014 18:26:10 +0000 (20:26 +0200)
committerSoeren Apel <redacted>
Tue, 2 Sep 2014 18:28:34 +0000 (20:28 +0200)
pv/view/trace.cpp
pv/view/trace.h

index 896fdec5a5ee50bb40409ad9bed7154b3c955e0d..250376ebb8828d931300a8a1a9ba5fc96ca4b749 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QApplication>
 #include <QFormLayout>
+#include <QKeyEvent>
 #include <QLineEdit>
 
 #include "trace.h"
@@ -218,6 +219,24 @@ QRectF Trace::get_label_rect(int right)
                label_size.width(), label_size.height());
 }
 
+bool Trace::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;
+}
+
 QColor Trace::get_text_colour() const
 {
        return (_colour.lightness() > 64) ? Qt::black : Qt::white;
@@ -269,6 +288,9 @@ void Trace::populate_popup_form(QWidget *parent, QFormLayout *form)
                this, SLOT(on_text_changed(const QString&)));
        form->addRow(tr("Name"), name_edit);
 
+       // We want to close the popup when the Enter key was pressed.
+       name_edit->installEventFilter(this);
+
        add_colour_option(parent, form);
 }
 
index 71ad4953d84dc8f37f6f3c2418ef7a554ee0eda4..de68dea1b1ab376d5ea03ed51207b250760dfe79 100644 (file)
@@ -148,6 +148,8 @@ public:
         */
        QRectF get_label_rect(int right);
 
+       bool eventFilter(QObject *obj, QEvent *evt);
+
 protected:
 
        /**