aboutsummaryrefslogtreecommitdiff
path: root/src/mainwindow/widgets/searchform.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-04-17 16:37:25 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-04-17 16:37:25 +0200
commit5152fc15d128821b842ade2c8fa7e2fcb16c0e94 (patch)
tree446658345a873ede716006bfe10d0470b8181aa8 /src/mainwindow/widgets/searchform.cpp
parentClear navigation bar and address bar when last subwindow is closed (diff)
downloadsmolbote-5152fc15d128821b842ade2c8fa7e2fcb16c0e94.tar.xz
Search box works again
Diffstat (limited to 'src/mainwindow/widgets/searchform.cpp')
-rw-r--r--src/mainwindow/widgets/searchform.cpp55
1 files changed, 31 insertions, 24 deletions
diff --git a/src/mainwindow/widgets/searchform.cpp b/src/mainwindow/widgets/searchform.cpp
index 07b8426..80e3848 100644
--- a/src/mainwindow/widgets/searchform.cpp
+++ b/src/mainwindow/widgets/searchform.cpp
@@ -7,45 +7,30 @@
*/
#include "searchform.h"
-#include "configuration/configuration.h"
-#include "mainwindow/mainwindow.h"
#include "ui_searchform.h"
-#include "webengine/webview.h"
-#include <QAction>
+#include <QWebEngineView>
+#include <QFocusEvent>
-SearchForm::SearchForm(MainWindow *parentWindow, QWidget *parent)
+SearchForm::SearchForm(QWidget *parent)
: QWidget(parent)
, ui(new Ui::SearchForm)
{
- Q_CHECK_PTR(parentWindow);
-
ui->setupUi(this);
ui->lineEdit->setPlaceholderText(tr("Search"));
ui->lineEdit->setClearButtonEnabled(true);
ui->result_label->setVisible(false);
- // show/hide action
- auto *toggleSearchBox = new QAction(this);
- toggleSearchBox->setShortcut(QKeySequence(QString::fromStdString(parentWindow->m_config->value<std::string>("browser.shortcuts.toggleSearchBox").value())));
- connect(toggleSearchBox, &QAction::triggered, this, [this, parentWindow]() {
- if(isVisible()) {
- setVisible(false);
- // remove highlighting by passing an empty string
- parentWindow->m_currentView->findText("");
- } else {
- setVisible(true);
- setFocus();
- }
- });
- parentWindow->addAction(toggleSearchBox);
+ connect(ui->lineEdit, &QLineEdit::returnPressed, this, [this]() {
+ Q_ASSERT_X(view != nullptr, "SearchForm::returnPressed::lambda", "No view set");
- connect(ui->lineEdit, &QLineEdit::returnPressed, this, [this, parentWindow]() {
+ if(view) {
QWebEnginePage::FindFlags searchFlags;
searchFlags.setFlag(QWebEnginePage::FindCaseSensitively, ui->caseSensitivity_checkBox->isChecked());
searchFlags.setFlag(QWebEnginePage::FindBackward, ui->reverseSearch_checkBox->isChecked());
- parentWindow->m_currentView->findText(ui->lineEdit->text(), searchFlags, [this](bool found) {
+ view->findText(ui->lineEdit->text(), searchFlags, [this](bool found) {
ui->result_label->setVisible(!found);
});
+ }
});
}
@@ -54,8 +39,30 @@ SearchForm::~SearchForm()
delete ui;
}
+void SearchForm::setView(QWebEngineView* view)
+{
+ qDebug("setting view: %s", view == nullptr ? "nullptr" : "valid");
+ this->view = view;
+}
+
+void SearchForm::showEvent(QShowEvent* e)
+{
+ e->accept();
+ ui->lineEdit->setFocus();
+ ui->lineEdit->selectAll();
+}
+
+void SearchForm::hideEvent(QHideEvent* e)
+{
+ e->accept();
+ // clear highlighted text when hiding
+ if(view) {
+ view->findText("");
+ }
+}
+
void SearchForm::focusInEvent(QFocusEvent *e)
{
ui->lineEdit->setFocus();
- QWidget::focusInEvent(e);
+ e->accept();
}