From e242fc84ee820f625539a8d33e9f7227cfc85500 Mon Sep 17 00:00:00 2001 From: mgr Date: Fri, 17 Nov 2017 22:56:15 +0100 Subject: [PATCH] Search bar improvements New button and key sequence (ESC) to close the search bar. Clear selection (by not avoiding the search) when the text to search is deleted, as expected by @pamtbaau at #1220. --- src/MainWindow.cpp | 1 + src/SqlExecutionArea.cpp | 49 ++++++++++++++++++++++------------------ src/SqlExecutionArea.h | 4 ++++ src/SqlExecutionArea.ui | 33 ++++++++++++++++++++------- 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 38bdeaf7..089f4293 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1737,6 +1737,7 @@ unsigned int MainWindow::openSqlTab(bool resetCounter) ui->tabSqlAreas->setCurrentIndex(index); w->setFindFrameVisibility(ui->actionSqlFind->isChecked()); w->getEditor()->setFocus(); + connect(w, SIGNAL(findFrameVisibilityChanged(bool)), ui->actionSqlFind, SLOT(setChecked(bool))); return index; } diff --git a/src/SqlExecutionArea.cpp b/src/SqlExecutionArea.cpp index ddbddd26..8fb579e9 100644 --- a/src/SqlExecutionArea.cpp +++ b/src/SqlExecutionArea.cpp @@ -8,6 +8,7 @@ #include #include +#include SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) : QWidget(parent), @@ -25,11 +26,15 @@ SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) : ui->findFrame->hide(); + QShortcut* shortcutHideFind = new QShortcut(QKeySequence("ESC"), ui->findLineEdit); + connect(shortcutHideFind, SIGNAL(activated()), this, SLOT(hideFindFrame())); + connect(ui->findLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(findLineEdit_textChanged(const QString &))); connect(ui->previousToolButton, SIGNAL(clicked()), this, SLOT(findPrevious())); connect(ui->nextToolButton, SIGNAL(clicked()), this, SLOT(findNext())); connect(ui->findLineEdit, SIGNAL(returnPressed()), this, SLOT(findNext())); + connect(ui->hideFindButton, SIGNAL(clicked()), this, SLOT(hideFindFrame())); // Load settings reloadSettings(); @@ -152,7 +157,7 @@ void SqlExecutionArea::find(QString expr, bool forward) forward); // Set reddish background when not found - if (found) + if (found || expr == "") ui->findLineEdit->setStyleSheet(""); else ui->findLineEdit->setStyleSheet("color: white; background-color: rgb(255, 102, 102)"); @@ -174,26 +179,26 @@ void SqlExecutionArea::findLineEdit_textChanged(const QString &) // When the text changes, perform an incremental search from cursor // position, or from begin of the selection position. - // Reset reddish background when the user has deleted the input, - // otherwise search the text forward. - if (ui->findLineEdit->text() == "") - ui->findLineEdit->setStyleSheet(""); - else { - // For incremental search while typing we need to start from the - // begining of the current selection, otherwise we'd jump to the - // next occurrence - if (ui->editEditor->hasSelectedText()) { - int lineFrom; - int indexFrom; - int lineTo; - int indexTo; - ui->editEditor->getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo); - ui->editEditor->setCursorPosition(lineFrom, indexFrom); - } - - find(ui->findLineEdit->text(), true); - + // For incremental search while typing we need to start from the + // begining of the current selection, otherwise we'd jump to the + // next occurrence + if (ui->editEditor->hasSelectedText()) { + int lineFrom; + int indexFrom; + int lineTo; + int indexTo; + ui->editEditor->getSelection(&lineFrom, &indexFrom, &lineTo, &indexTo); + ui->editEditor->setCursorPosition(lineFrom, indexFrom); } + + find(ui->findLineEdit->text(), true); +} + +void SqlExecutionArea::hideFindFrame() +{ + ui->editEditor->setFocus(); + ui->findFrame->hide(); + emit findFrameVisibilityChanged(false); } void SqlExecutionArea::setFindFrameVisibility(bool show) @@ -202,8 +207,8 @@ void SqlExecutionArea::setFindFrameVisibility(bool show) ui->findFrame->show(); ui->findLineEdit->setFocus(); ui->findLineEdit->selectAll(); + emit findFrameVisibilityChanged(true); } else { - ui->editEditor->setFocus(); - ui->findFrame->hide(); + hideFindFrame(); } } diff --git a/src/SqlExecutionArea.h b/src/SqlExecutionArea.h index c233221a..5a7b2e71 100644 --- a/src/SqlExecutionArea.h +++ b/src/SqlExecutionArea.h @@ -42,6 +42,10 @@ private slots: void findPrevious(); void findNext(); void findLineEdit_textChanged(const QString& text); + void hideFindFrame(); + +signals: + void findFrameVisibilityChanged(bool visible); private: void find(QString expr, bool forward); diff --git a/src/SqlExecutionArea.ui b/src/SqlExecutionArea.ui index 1152b1a1..00ea7803 100644 --- a/src/SqlExecutionArea.ui +++ b/src/SqlExecutionArea.ui @@ -6,7 +6,7 @@ 0 0 - 552 + 579 482 @@ -77,17 +77,11 @@ - + Qt::Horizontal - - - 40 - 20 - - @@ -156,6 +150,29 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + + + +