]> sigrok.org Git - pulseview.git/blobdiff - pv/view/trace.cpp
Make decoder popups close when pressing enter
[pulseview.git] / pv / view / trace.cpp
index 896fdec5a5ee50bb40409ad9bed7154b3c955e0d..250376ebb8828d931300a8a1a9ba5fc96ca4b749 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QApplication>
 #include <QFormLayout>
 
 #include <QApplication>
 #include <QFormLayout>
+#include <QKeyEvent>
 #include <QLineEdit>
 
 #include "trace.h"
 #include <QLineEdit>
 
 #include "trace.h"
@@ -218,6 +219,24 @@ QRectF Trace::get_label_rect(int right)
                label_size.width(), label_size.height());
 }
 
                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;
 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);
 
                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);
 }
 
        add_colour_option(parent, form);
 }