aboutsummaryrefslogtreecommitdiff
path: root/src/widgets
diff options
context:
space:
mode:
authorMike Skec <skec@protonmail.ch>2021-02-09 17:49:07 +1100
committerFelix Queißner <felix@ib-queissner.de>2021-02-09 10:18:41 +0100
commit0843ee2dada57255c29425f7b598ab3b258e4641 (patch)
tree053f28868aec5901c8bf1a7aa0a5401d442a3987 /src/widgets
parent70c71e7a0ee3f2c446551fc15af06136861e10e7 (diff)
downloadkristall-0843ee2dada57255c29425f7b598ab3b258e4641.tar.gz
Search box: better reimplementation
This was necessary to fix a bug, where the URL bar becomes unusable while search box is visible.
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/searchbox.cpp31
-rw-r--r--src/widgets/searchbox.hpp20
2 files changed, 51 insertions, 0 deletions
diff --git a/src/widgets/searchbox.cpp b/src/widgets/searchbox.cpp
new file mode 100644
index 0000000..67e48f9
--- /dev/null
+++ b/src/widgets/searchbox.cpp
@@ -0,0 +1,31 @@
+#include "searchbox.hpp"
+
+#include <QKeyEvent>
+#include <QDebug>
+
+SearchBox::SearchBox(QWidget * parent) : QLineEdit(parent)
+{}
+
+void SearchBox::keyPressEvent(QKeyEvent *event)
+{
+ if(event->key() == Qt::Key_Return || event->key() == Qt::Key_F3) {
+ if (event->modifiers() == Qt::ShiftModifier) {
+ emit searchPrev();
+ }
+ else {
+ emit searchNext();
+ }
+ } else {
+ QLineEdit::keyPressEvent(event);
+ }
+}
+
+void SearchBox::keyReleaseEvent(QKeyEvent *event)
+{
+ if(event->key() == Qt::Key_Return) {
+ // Eat the event
+ } else {
+ QLineEdit::keyReleaseEvent(event);
+ }
+}
+
diff --git a/src/widgets/searchbox.hpp b/src/widgets/searchbox.hpp
new file mode 100644
index 0000000..fe589ff
--- /dev/null
+++ b/src/widgets/searchbox.hpp
@@ -0,0 +1,20 @@
+#ifndef SEARCHBOX_HPP
+#define SEARCHBOX_HPP
+
+#include <QLineEdit>
+
+class SearchBox : public QLineEdit
+{
+ Q_OBJECT
+public:
+ explicit SearchBox(QWidget *parent = nullptr);
+
+signals:
+ void searchNext();
+ void searchPrev();
+public:
+ void keyPressEvent(QKeyEvent *event) override;
+ void keyReleaseEvent(QKeyEvent *event) override;
+};
+
+#endif // SEARCHBOX_HPP