diff options
author | Sergey Starosek <sergey.starosek@gmail.com> | 2014-01-09 19:21:29 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-01-10 16:07:43 +0700 |
commit | 8b00f8ffe6597a233814708d19b286e5dc0c65d8 (patch) | |
tree | 0ccd0f2e3e886b596aa10cb92c6e373867a08431 /qt-ui/usermanual.cpp | |
parent | e5ae3fca7fce07b5415f66fab937420f07aa70c6 (diff) | |
download | subsurface-8b00f8ffe6597a233814708d19b286e5dc0c65d8.tar.gz |
Extract user manual web view into a separate class
Provide search functionality which addresses ticket #391
Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/usermanual.cpp')
-rw-r--r-- | qt-ui/usermanual.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/qt-ui/usermanual.cpp b/qt-ui/usermanual.cpp new file mode 100644 index 000000000..56f0fe1c3 --- /dev/null +++ b/qt-ui/usermanual.cpp @@ -0,0 +1,93 @@ +#include <QDesktopServices> + +#include "usermanual.h" +#include "ui_usermanual.h" + +#include "../helpers.h" + +UserManual::UserManual(QWidget *parent) : + QWidget(parent), + ui(new Ui::UserManual) +{ + ui->setupUi(this); + + QAction *actionShowSearch = new QAction(this); + actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F); + actionShowSearch->setShortcutContext(Qt::WindowShortcut); + addAction(actionShowSearch); + + QAction *actionHideSearch = new QAction(this); + actionHideSearch->setShortcut(Qt::Key_Escape); + actionHideSearch->setShortcutContext(Qt::WindowShortcut); + addAction(actionHideSearch); + + ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); + QString searchPath = getSubsurfaceDataPath("Documentation"); + if (searchPath != "") { + QUrl url(searchPath.append("/user-manual.html")); + ui->webView->setWindowTitle(tr("User Manual")); + ui->webView->setWindowIcon(QIcon(":/subsurface-icon")); + ui->webView->setUrl(url); + } else { + ui->webView->setHtml(tr("Cannot find the Subsurface manual")); + } + ui->searchPanel->setParent(this); + ui->searchPanel->hide(); + + connect(actionShowSearch, SIGNAL(triggered(bool)), this, SLOT(showSearchPanel())); + connect(actionHideSearch, SIGNAL(triggered(bool)), this, SLOT(hideSearchPanel())); + connect(ui->webView, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); + connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(searchTextChanged(QString))); + connect(ui->findNext, SIGNAL(clicked()), this, SLOT(searchNext())); + connect(ui->findPrev, SIGNAL(clicked()), this, SLOT(searchPrev())); +} + +void UserManual::showSearchPanel() +{ + ui->searchPanel->show(); + ui->searchEdit->setFocus(); + ui->searchEdit->selectAll(); +} + +void UserManual::hideSearchPanel() +{ + ui->searchPanel->hide(); +} + +void UserManual::search(QString text, QWebPage::FindFlags flags = 0) +{ + if (ui->webView->findText(text, flags) || text.length() == 0) { + ui->searchEdit->setStyleSheet(""); + } else { + ui->searchEdit->setStyleSheet("QLineEdit{background: red;}"); + } +} + +void UserManual::searchTextChanged(QString text) { + bool hasText = text.length() > 0; + + ui->findPrev->setEnabled(hasText); + ui->findNext->setEnabled(hasText); + + search(text); +} + +void UserManual::searchNext() +{ + search(ui->searchEdit->text()); +} + +void UserManual::searchPrev() +{ + search(ui->searchEdit->text(), QWebPage::FindBackward); +} + +void UserManual::linkClickedSlot(QUrl url) +{ + QDesktopServices::openUrl(url); +} + +UserManual::~UserManual() +{ + delete ui; +} |