X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fwidgets%2Fpopup.cpp;h=141985eb556a2e1c87ca2e558f90acd9203d7330;hp=9bdbd76412e5e99cd355c9888b102c9386116692;hb=0715fb8c638b53ac25590841fcbf3a1da3546b68;hpb=fc3e73d0730e032c6c8d49dd80ff8a3620674ebc diff --git a/pv/widgets/popup.cpp b/pv/widgets/popup.cpp index 9bdbd764..141985eb 100644 --- a/pv/widgets/popup.cpp +++ b/pv/widgets/popup.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "popup.h" @@ -67,6 +68,45 @@ void Popup::set_position(const QPoint point, Position pos) } +bool Popup::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) { + this->close(); + return true; + } + } + + return false; +} + +void Popup::show() +{ + QLineEdit* le; + + QWidget::show(); + + // We want to close the popup when the Enter key was + // pressed and the first editable widget had focus. + if ((le = this->findChild())) { + + // For combo boxes we need to hook into the parent of + // the line edit (i.e. the QComboBox). For edit boxes + // we hook into the widget directly. + if (le->parent()->metaObject()->className() == + this->metaObject()->className()) + le->installEventFilter(this); + else + le->parent()->installEventFilter(this); + } +} + bool Popup::space_for_arrow() const { // Check if there is room for the arrow