From: Soeren Apel <[email protected]>
Just like the patch that made analog and digital trace popups close
upon hitting the enter key, this patch adds this feature to decoder
channels as well - or whatever else may derive from the Trace class
in the future.
---
pv/view/trace.cpp | 22 ++++++++++++++++++++++
pv/view/trace.h | 2 ++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/pv/view/trace.cpp b/pv/view/trace.cpp
index 896fdec..250376e 100644
--- a/pv/view/trace.cpp
+++ b/pv/view/trace.cpp
@@ -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);
}
diff --git a/pv/view/trace.h b/pv/view/trace.h
index 71ad495..de68dea 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:
/**
--
1.7.8.6
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
sigrok-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sigrok-devel