X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fwidgets%2Fpopup.cpp;h=52701380787e8845dd7830955e526dabdd86a93b;hp=9bdbd76412e5e99cd355c9888b102c9386116692;hb=1db1bdd6079178e218b3b1b0bd3e30efdf3e1690;hpb=d528d3d185ca3bb9a40ec7af0299a83c0d2b76e0 diff --git a/pv/widgets/popup.cpp b/pv/widgets/popup.cpp index 9bdbd76..5270138 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,48 @@ 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) { + 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); + + le->selectAll(); + le->setFocus(); + } +} + bool Popup::space_for_arrow() const { // Check if there is room for the arrow