From bd993a4135c8b717248ce9dd28ea81995f0c86db Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 11 Jul 2014 18:01:35 -0300 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/usermanual.cpp | 26 ++++++++++++++------------ qt-ui/usermanual.h | 7 +++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qt-ui/usermanual.cpp b/qt-ui/usermanual.cpp index 6d9c56432..3d8296045 100644 --- a/qt-ui/usermanual.cpp +++ b/qt-ui/usermanual.cpp @@ -35,7 +35,7 @@ void SearchBar::enableButtons(const QString &s) 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); connect(closeKey, SIGNAL(activated()), this, SLOT(close())); @@ -54,7 +54,8 @@ UserManual::UserManual(QWidget *parent) : QWebView(parent) setWindowTitle(tr("User Manual")); - page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); + userManual = new QWebView(this); + userManual->page()->setLinkDelegationPolicy(QWebPage::DelegateExternalLinks); QString searchPath = getSubsurfaceDataPath("Documentation"); if (searchPath.size()) { // look for localized versions of the manual first @@ -66,28 +67,33 @@ UserManual::UserManual(QWidget *parent) : QWebView(parent) if (!manual.exists()) manual.setFileName(prefix + ".html"); if (!manual.exists()) { - setHtml(tr("Cannot find the Subsurface manual")); + userManual->setHtml(tr("Cannot find the Subsurface manual")); } else { QString urlString = QString("file:///") + manual.fileName(); - setUrl(QUrl(urlString, QUrl::TolerantMode)); + userManual->setUrl(QUrl(urlString, QUrl::TolerantMode)); } } else { - setHtml(tr("Cannot find the Subsurface manual")); + userManual->setHtml(tr("Cannot find the Subsurface manual")); } searchBar = new SearchBar(this); searchBar->hide(); connect(actionShowSearch, SIGNAL(triggered(bool)), searchBar, SLOT(show())); 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(searchNext()), this, SLOT(searchNext())); 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) { - if (findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { + if (userManual->findText(text, QWebPage::FindWrapsAroundDocument | flags) || text.length() == 0) { searchBar->setStyleSheet(""); } else { searchBar->setStyleSheet("QLineEdit{background: red;}"); @@ -110,11 +116,7 @@ void UserManual::searchPrev() search(mLastText, QWebPage::FindBackward); } -void UserManual::linkClickedSlot(QUrl url) +void UserManual::linkClickedSlot(const QUrl& url) { QDesktopServices::openUrl(url); } - -UserManual::~UserManual() -{ -} diff --git a/qt-ui/usermanual.h b/qt-ui/usermanual.h index 7cd10c185..c36226027 100644 --- a/qt-ui/usermanual.h +++ b/qt-ui/usermanual.h @@ -21,20 +21,19 @@ private: Ui::SearchBar ui; }; -class UserManual : public QWebView { +class UserManual : public QWidget { Q_OBJECT public: explicit UserManual(QWidget *parent = 0); - ~UserManual(); private slots: void searchTextChanged(const QString& s); void searchNext(); void searchPrev(); - void linkClickedSlot(QUrl url); - + void linkClickedSlot(const QUrl& url); private: + QWebView *userManual; SearchBar *searchBar; QString mLastText; void search(QString, QWebPage::FindFlags); -- cgit v1.2.3-70-g09d2