From 83649b5d52c1e9e56cf1fc4e5f5ab42b7508ad77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 5 Feb 2018 01:40:38 +0100 Subject: [PATCH] NOISSUE implement basic search in Other Logs page --- application/pages/OtherLogsPage.cpp | 45 +++++++++++++++++ application/pages/OtherLogsPage.h | 5 ++ application/pages/OtherLogsPage.ui | 76 +++++++++++++++++++---------- 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/application/pages/OtherLogsPage.cpp b/application/pages/OtherLogsPage.cpp index 0fe7360b..40ba4108 100644 --- a/application/pages/OtherLogsPage.cpp +++ b/application/pages/OtherLogsPage.cpp @@ -22,6 +22,7 @@ #include "RecursiveFileSystemWatcher.h" #include #include +#include OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget *parent) : QWidget(parent), ui(new Ui::OtherLogsPage), m_path(path), m_fileFilter(fileFilter), @@ -35,6 +36,17 @@ OtherLogsPage::OtherLogsPage(QString path, IPathMatcher::Ptr fileFilter, QWidget connect(m_watcher, &RecursiveFileSystemWatcher::filesChanged, this, &OtherLogsPage::populateSelectLogBox); populateSelectLogBox(); + + auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this); + connect(findShortcut, &QShortcut::activated, this, &OtherLogsPage::findActivated); + + auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this); + connect(findNextShortcut, &QShortcut::activated, this, &OtherLogsPage::findNextActivated); + + auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this); + connect(findPreviousShortcut, &QShortcut::activated, this, &OtherLogsPage::findPreviousActivated); + + connect(ui->searchBar, &QLineEdit::returnPressed, this, &OtherLogsPage::on_findButton_clicked); } OtherLogsPage::~OtherLogsPage() @@ -253,3 +265,36 @@ void OtherLogsPage::setControlsEnabled(const bool enabled) ui->text->setEnabled(enabled); ui->btnClean->setEnabled(enabled); } + +// FIXME: HACK, use LogView instead? +static void findNext(QPlainTextEdit * _this, const QString& what, bool reverse) +{ + _this->find(what, reverse ? QTextDocument::FindFlag::FindBackward : QTextDocument::FindFlag(0)); +} + +void OtherLogsPage::on_findButton_clicked() +{ + auto modifiers = QApplication::keyboardModifiers(); + bool reverse = modifiers & Qt::ShiftModifier; + findNext(ui->text, ui->searchBar->text(), reverse); +} + +void OtherLogsPage::findNextActivated() +{ + findNext(ui->text, ui->searchBar->text(), false); +} + +void OtherLogsPage::findPreviousActivated() +{ + findNext(ui->text, ui->searchBar->text(), true); +} + +void OtherLogsPage::findActivated() +{ + // focus the search bar if it doesn't have focus + if (!ui->searchBar->hasFocus()) + { + ui->searchBar->setFocus(); + ui->searchBar->selectAll(); + } +} diff --git a/application/pages/OtherLogsPage.h b/application/pages/OtherLogsPage.h index 9ccf964f..462fa62b 100644 --- a/application/pages/OtherLogsPage.h +++ b/application/pages/OtherLogsPage.h @@ -64,6 +64,11 @@ private slots: void on_btnDelete_clicked(); void on_btnClean_clicked(); + void on_findButton_clicked(); + void findActivated(); + void findNextActivated(); + void findPreviousActivated(); + private: void setControlsEnabled(const bool enabled); diff --git a/application/pages/OtherLogsPage.ui b/application/pages/OtherLogsPage.ui index 43d6a35b..56ff3b62 100644 --- a/application/pages/OtherLogsPage.ui +++ b/application/pages/OtherLogsPage.ui @@ -32,8 +32,34 @@ Tab 1 - - + + + + + + + + Find + + + + + + + false + + + Qt::ScrollBarAlwaysOn + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + @@ -65,6 +91,16 @@ + + + + Clear the log + + + Clean + + + @@ -82,31 +118,12 @@ - - - - Clear the log - - - Clean - - - - - - - false - - - Qt::ScrollBarAlwaysOn - - - true - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + Search: @@ -117,7 +134,16 @@ + tabWidget + selectLogBox + btnReload + btnCopy + btnPaste + btnDelete + btnClean text + searchBar + findButton