2014-01-09 17:21:29 +00:00
|
|
|
#include <QDesktopServices>
|
2014-04-24 21:58:58 +00:00
|
|
|
#include <QShortcut>
|
2014-06-06 19:10:34 +00:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDebug>
|
2014-01-09 17:21:29 +00:00
|
|
|
|
|
|
|
#include "usermanual.h"
|
|
|
|
#include "ui_usermanual.h"
|
|
|
|
|
2014-06-06 19:10:34 +00:00
|
|
|
#include "helpers.h"
|
2014-01-09 17:21:29 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
UserManual::UserManual(QWidget *parent) : QMainWindow(parent),
|
2014-01-09 17:21:29 +00:00
|
|
|
ui(new Ui::UserManual)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
|
2014-04-24 21:58:58 +00:00
|
|
|
connect(closeKey, SIGNAL(activated()), this, SLOT(close()));
|
2014-05-22 18:40:22 +00:00
|
|
|
QShortcut *quitKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
2014-04-24 23:19:09 +00:00
|
|
|
connect(quitKey, SIGNAL(activated()), parent, SLOT(close()));
|
2014-04-24 21:58:58 +00:00
|
|
|
|
2014-01-09 17:21:29 +00:00
|
|
|
QAction *actionShowSearch = new QAction(this);
|
|
|
|
actionShowSearch->setShortcut(Qt::CTRL + Qt::Key_F);
|
2014-06-25 12:07:02 +00:00
|
|
|
actionShowSearch->setShortcutContext(Qt::WindowShortcut);
|
2014-01-09 17:21:29 +00:00
|
|
|
addAction(actionShowSearch);
|
|
|
|
|
|
|
|
QAction *actionHideSearch = new QAction(this);
|
|
|
|
actionHideSearch->setShortcut(Qt::Key_Escape);
|
2014-06-25 12:07:02 +00:00
|
|
|
actionHideSearch->setShortcutContext(Qt::WindowShortcut);
|
2014-01-09 17:21:29 +00:00
|
|
|
addAction(actionHideSearch);
|
|
|
|
|
2014-01-09 18:29:33 +00:00
|
|
|
setWindowTitle(tr("User Manual"));
|
|
|
|
|
2014-01-09 17:21:29 +00:00
|
|
|
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
|
|
|
|
QString searchPath = getSubsurfaceDataPath("Documentation");
|
2014-05-11 00:37:18 +00:00
|
|
|
if (searchPath.size()) {
|
2014-06-06 19:10:34 +00:00
|
|
|
// look for localized versions of the manual first
|
|
|
|
QString lang = uiLanguage(NULL);
|
|
|
|
QString prefix = searchPath.append("/user-manual");
|
|
|
|
QFile manual(prefix + "_" + lang + ".html");
|
|
|
|
if (!manual.exists())
|
|
|
|
manual.setFileName(prefix + "_" + lang.left(2) + ".html");
|
|
|
|
if (!manual.exists())
|
|
|
|
manual.setFileName(prefix + ".html");
|
2014-06-09 20:42:16 +00:00
|
|
|
if (!manual.exists()) {
|
|
|
|
ui->webView->setHtml(tr("Cannot find the Subsurface manual"));
|
|
|
|
} else {
|
|
|
|
QString urlString = QString("file:///") + manual.fileName();
|
|
|
|
QUrl url(urlString, QUrl::TolerantMode);
|
|
|
|
ui->webView->setUrl(url);
|
|
|
|
}
|
2014-01-09 17:21:29 +00:00
|
|
|
} 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)
|
|
|
|
{
|
2014-02-28 04:09:57 +00:00
|
|
|
if (ui->webView->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
|
2014-01-09 17:21:29 +00:00
|
|
|
ui->searchEdit->setStyleSheet("");
|
|
|
|
} else {
|
|
|
|
ui->searchEdit->setStyleSheet("QLineEdit{background: red;}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
void UserManual::searchTextChanged(QString text)
|
|
|
|
{
|
2014-01-09 17:21:29 +00:00
|
|
|
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;
|
|
|
|
}
|