Use a layout to lay down the search and the help

The old layout tried to add the search on top of the help view, which
didn't really work because of the way that the QWebView rendered: we got
garbage after a scroll with the find opened. So now I'v created a QWidget
and layed down the QWebView and the search bar vertically.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-07-11 18:01:35 -03:00 committed by Dirk Hohndel
parent af9d62bac3
commit bd993a4135
2 changed files with 17 additions and 16 deletions

View file

@ -35,7 +35,7 @@ void SearchBar::enableButtons(const QString &s)
ui.findNext->setEnabled(s.length()); ui.findNext->setEnabled(s.length());
} }
UserManual::UserManual(QWidget *parent) : QWebView(parent) UserManual::UserManual(QWidget *parent) : QWidget(parent)
{ {
QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
connect(closeKey, SIGNAL(activated()), this, SLOT(close())); connect(closeKey, SIGNAL(activated()), this, SLOT(close()));
@ -54,7 +54,8 @@ UserManual::UserManual(QWidget *parent) : QWebView(parent)
setWindowTitle(tr("User Manual")); setWindowTitle(tr("User Manual"));
page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); userManual = new QWebView(this);
userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks);
QString searchPath = getSubsurfaceDataPath("Documentation"); QString searchPath = getSubsurfaceDataPath("Documentation");
if (searchPath.size()) { if (searchPath.size()) {
// look for localized versions of the manual first // look for localized versions of the manual first
@ -66,28 +67,33 @@ UserManual::UserManual(QWidget *parent) : QWebView(parent)
if (!manual.exists()) if (!manual.exists())
manual.setFileName(prefix + ".html"); manual.setFileName(prefix + ".html");
if (!manual.exists()) { if (!manual.exists()) {
setHtml(tr("Cannot find the Subsurface manual")); userManual->setHtml(tr("Cannot find the Subsurface manual"));
} else { } else {
QString urlString = QString("file:///") + manual.fileName(); QString urlString = QString("file:///") + manual.fileName();
setUrl(QUrl(urlString, QUrl::TolerantMode)); userManual->setUrl(QUrl(urlString, QUrl::TolerantMode));
} }
} else { } else {
setHtml(tr("Cannot find the Subsurface manual")); userManual->setHtml(tr("Cannot find the Subsurface manual"));
} }
searchBar = new SearchBar(this); searchBar = new SearchBar(this);
searchBar->hide(); searchBar->hide();
connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show()));
connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide())); connect(actionHideSearch, SIGNAL(triggered(bool)), searchBar, SLOT(hide()));
connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl))); connect(userManual, SIGNAL(linkClicked(QUrl)), this, SLOT(linkClickedSlot(QUrl)));
connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString))); connect(searchBar, SIGNAL(searchTextChanged(QString)), this, SLOT(searchTextChanged(QString)));
connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext())); connect(searchBar, SIGNAL(searchNext()), this, SLOT(searchNext()));
connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev())); connect(searchBar, SIGNAL(searchPrev()), this, SLOT(searchPrev()));
QVBoxLayout *vboxLayout = new QVBoxLayout();
vboxLayout->addWidget(userManual);
vboxLayout->addWidget(searchBar);
setLayout(vboxLayout);
} }
void UserManual::search(QString text, QWebPage::FindFlags flags = 0) void UserManual::search(QString text, QWebPage::FindFlags flags = 0)
{ {
if (findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) {
searchBar->setStyleSheet(""); searchBar->setStyleSheet("");
} else { } else {
searchBar->setStyleSheet("QLineEdit{background: red;}"); searchBar->setStyleSheet("QLineEdit{background: red;}");
@ -110,11 +116,7 @@ void UserManual::searchPrev()
search(mLastText, QWebPage::FindBackward); search(mLastText, QWebPage::FindBackward);
} }
void UserManual::linkClickedSlot(QUrl url) void UserManual::linkClickedSlot(const QUrl& url)
{ {
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
} }
UserManual::~UserManual()
{
}

View file

@ -21,20 +21,19 @@ private:
Ui::SearchBar ui; Ui::SearchBar ui;
}; };
class UserManual : public QWebView { class UserManual : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit UserManual(QWidget *parent = 0); explicit UserManual(QWidget *parent = 0);
~UserManual();
private private
slots: slots:
void searchTextChanged(const QString& s); void searchTextChanged(const QString& s);
void searchNext(); void searchNext();
void searchPrev(); void searchPrev();
void linkClickedSlot(QUrl url); void linkClickedSlot(const QUrl& url);
private: private:
QWebView *userManual;
SearchBar *searchBar; SearchBar *searchBar;
QString mLastText; QString mLastText;
void search(QString, QWebPage::FindFlags); void search(QString, QWebPage::FindFlags);