From: Soeren Apel Date: Tue, 2 Sep 2014 18:26:10 +0000 (+0200) Subject: Make decoder popups close when pressing enter X-Git-Tag: pulseview-0.3.0~547 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=0891e69b714a1eaf8b0d5c2e85f092e9f0b44088;p=pulseview.git Make decoder popups close when pressing enter --- diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp index 896fdec5..250376eb 100644 --- a/pv/view/trace.cpp +++ b/pv/view/trace.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #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(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); } diff --git a/pv/view/trace.h b/pv/view/trace.h index 71ad4953..de68dea1 100644 --- a/pv/view/trace.h +++ b/pv/view/trace.h @@ -148,6 +148,8 @@ public: */ QRectF get_label_rect(int right); + bool eventFilter(QObject *obj, QEvent *evt); + protected: /**