Commit 73f16fb6 authored by Shubham  .'s avatar Shubham .
Browse files

Add Find in Page text functionality

parent 9bac6817
......@@ -38,6 +38,7 @@
#include <QLineEdit>
#include <QModelIndex>
#include <QPushButton>
#include <QShortcut>
#include <QStandardPaths>
#include <QStackedWidget>
#include <QToolButton>
......@@ -114,35 +115,39 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
QLabel* label = new QLabel(this);
label->setText(i18n("Find:"));
QLineEdit* findText = new QLineEdit(this);
findText->setPlaceholderText(i18nc("@info:placeholder", "Search..."));
findText->setClearButtonEnabled(true);
m_findText = new QLineEdit(this);
m_findText->setPlaceholderText(i18nc("@info:placeholder", "Search..."));
m_findText->setClearButtonEnabled(true);
QToolButton* next = new QToolButton(this);
next->setIcon(QIcon::fromTheme(QLatin1String("arrow-down")));
next->setIcon(QIcon::fromTheme(QLatin1String("go-down-search")));
next->setToolTip(i18nc("@info:tooltip", "Jump to next match"));
QToolButton* previous = new QToolButton(this);
previous->setIcon(QIcon::fromTheme(QLatin1String("arrow-up")));
previous->setIcon(QIcon::fromTheme(QLatin1String("go-up-search")));
previous->setToolTip(i18nc("@info:tooltip", "Jump to previous match"));
QToolButton* matchCase = new QToolButton(this);
next->setIcon(QIcon::fromTheme(QLatin1String("format-text-superscript")));
next->setToolTip(i18nc("@info:tooltip", "Match case sensitive"));
m_matchCase = new QToolButton(this);
m_matchCase->setIcon(QIcon::fromTheme(QLatin1String("format-text-superscript")));
m_matchCase->setToolTip(i18nc("@info:tooltip", "Match case sensitive"));
// Create a layout
QHBoxLayout* lout = new QHBoxLayout(this);
lout->addWidget(hideButton);
lout->addWidget(label);
lout->addWidget(findText);
lout->addWidget(m_findText);
lout->addWidget(next);
lout->addWidget(previous);
lout->addWidget(matchCase);
lout->addWidget(m_matchCase);
QWidget* findPageWidgetContainer = new QWidget(this);
findPageWidgetContainer->setLayout(lout);
findPageWidgetContainer->hide();
auto closeFindBarShortcut = new QShortcut(QKeySequence(Qt::Key_F3), this);
closeFindBarShortcut->setContext(Qt::WidgetWithChildrenShortcut);
connect(closeFindBarShortcut, &QShortcut::activated, findPageWidgetContainer, &QWidget::hide);
////////////////////////////////////////////////////////
static bool qthelpRegistered = false;
......@@ -214,13 +219,13 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
connect(m_search, &QLineEdit::returnPressed, this, &DocumentationPanelWidget::returnPressed);
connect(m_search->completer(), QOverload<const QModelIndex&>::of(&QCompleter::activated), this, &DocumentationPanelWidget::returnPressed);
connect(hideButton, &QToolButton::clicked, this, [=]{
findPageWidgetContainer->hide();
});
/*connect(matchCase, &QAbstractButton::toggled, this, &DocumentationPanelWidget::emitDataChanged);
connect(findText, &QLineEdit::returnPressed, this, &DocumentationPanelWidget::searchNext);
connect(previous, &QToolButton::clicked, this, &DocumentationPanelWidget::searchPrevious);
connect(next, &QToolButton::clicked, this, &DocumentationPanelWidget::searchNext);*/
// connect statements for Find in Page text widget
connect(hideButton, &QToolButton::clicked, findPageWidgetContainer, &QWidget::hide);
connect(m_findText, &QLineEdit::returnPressed, this, &DocumentationPanelWidget::searchForward);
connect(m_findText, &QLineEdit::textEdited, this, &DocumentationPanelWidget::searchForward); // for highlighting found string in real time
connect(next, &QToolButton::clicked, this, &DocumentationPanelWidget::searchForward);
connect(previous, &QToolButton::clicked, this, &DocumentationPanelWidget::searchBackward);
connect(m_matchCase, &QAbstractButton::toggled, this, &DocumentationPanelWidget::searchForward);
setSession(session);
}
......@@ -232,6 +237,8 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
delete m_displayArea;
delete m_index;
delete m_search;
delete m_findText;
delete m_matchCase;
}
void DocumentationPanelWidget::setSession(Cantor::Session* session)
......@@ -284,6 +291,18 @@ void DocumentationPanelWidget::refreshIndexWidget()
m_index->activateCurrentItem();
}
void DocumentationPanelWidget::searchForward()
{
m_matchCase->isChecked() ? m_textBrowser->findText(m_findText->text(), QWebEnginePage::FindCaseSensitively) :
m_textBrowser->findText(m_findText->text());
}
void DocumentationPanelWidget::searchBackward()
{
m_matchCase->isChecked() ? m_textBrowser->findText(m_findText->text(), QWebEnginePage::FindCaseSensitively | QWebEnginePage::FindBackward) :
m_textBrowser->findText(m_findText->text(), QWebEnginePage::FindBackward);
}
void DocumentationPanelWidget::loadDocumentation()
{
const QString& backend = backendName();
......
......@@ -36,6 +36,7 @@ class QHelpEngine;
class QHelpIndexWidget;
class QLineEdit;
class QStackedWidget;
class QToolButton;
class QUrl;
class QWebEngineView;
......@@ -66,13 +67,21 @@ class DocumentationPanelWidget : public QWidget
void returnPressed();
void refreshIndexWidget();
// SLOTS for Find in Page widget
void searchForward();
void searchBackward();
private:
QHelpEngine* m_engine = nullptr;
QWebEngineView* m_textBrowser = nullptr;
QStackedWidget* m_displayArea = nullptr;
QHelpIndexWidget* m_index = nullptr;
QLineEdit* m_search = nullptr;
QString m_backend;
// member variables for find in page text widget
QLineEdit* m_search = nullptr; // for searching through keywords
QLineEdit* m_findText = nullptr; // for find in page text widget
QToolButton* m_matchCase = nullptr;
};
// class for handling of custom url scheme ie. qthelp:// inside QWebEngineView
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment