Commit 41de8ea7 authored by Mike Kremer's avatar Mike Kremer

Updated help browser in order to display images and handle internal...

Updated help browser in order to display images and handle internal references. Dropped ACG stylesheet since QTextBrowser does not support CSS2.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5631 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 2b0b90e1
No preview for this file type
No preview for this file type
...@@ -57,7 +57,8 @@ void CoreWidget::showHelpBrowser( ) { ...@@ -57,7 +57,8 @@ void CoreWidget::showHelpBrowser( ) {
return; return;
if(helpWidget_ == 0) if(helpWidget_ == 0)
helpWidget_ = new HelpWidget(this, "qthelp://org.openflipper.doc/OpenFlipper-1.0-Dev/main.html"); helpWidget_ = new HelpWidget(this, "qthelp://org.openflipper.doc/openflipper-1.0-dev/main.html",
"qthelp://org.openflipper.doc/openflipper-1.0-dev/");
helpWidget_->show(); helpWidget_->show();
......
...@@ -9,19 +9,17 @@ ...@@ -9,19 +9,17 @@
#include <iostream> #include <iostream>
#include <QWebFrame>
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) : HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, const QUrl& _basePath, QWidget* parent) :
QWebView(parent), QTextBrowser(parent),
helpEngine_(_helpEngine) { helpEngine_(_helpEngine),
basePath_(_basePath) {
currentPage_ = 0; currentPage_ = 0;
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks); connect(this, SIGNAL(linkClicked(const QString&)),
// Link has been clicked this, SLOT(open(const QString&)));
connect(this->page(), SIGNAL(linkClicked(const QUrl&)),
this, SLOT(load(const QUrl&)));
} }
...@@ -29,46 +27,35 @@ HelpBrowser::~HelpBrowser() { ...@@ -29,46 +27,35 @@ HelpBrowser::~HelpBrowser() {
} }
QVariant HelpBrowser::loadBytes(const QUrl &url) { QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
QByteArray bytes = helpEngine_->fileData(url); if (_url.scheme() == "qthelp") {
return QVariant(bytes); return QVariant(helpEngine_->fileData(_url));
} }
else {
void HelpBrowser::setUrl(const QUrl& _url) { // Set basePath_ as prefix of resource file
QUrl newUrl = QUrl(basePath_.toString() + _url.toString());
load(_url, ""); return QVariant(helpEngine_->fileData(newUrl));
} }
void HelpBrowser::load(const QUrl& _url) {
load(_url, "");
} }
void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSave) { void HelpBrowser::open(const QString& _url) {
QUrl newUrl; open(QUrl(_url), "");
}
if(_url.scheme() != "qthelp") { void HelpBrowser::open(const QUrl& _url) {
// Convert link to be within qthelp domain namespace
QString new_file = visitedPages_[currentPage_];
QStringList comp = new_file.split("/");
comp[comp.size()-1] = _url.toString();
newUrl = QUrl(comp.join("/")); open(_url, "");
}
if(!helpEngine_->findFile(newUrl).isValid()) { void HelpBrowser::open(const QUrl& _url, const QString& /*_str*/, bool _skipSave) {
QMessageBox::warning( this, "OpenFlipper Help",
"Unable to find specified file within documentation.");
return;
}
} else { QVariant data = this->loadResource(QTextDocument::HtmlResource, _url);
newUrl = _url;
}
QVariant data = this->loadBytes(newUrl);
QString txt; QString txt;
...@@ -83,7 +70,9 @@ void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSa ...@@ -83,7 +70,9 @@ void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSa
txt = data.toString(); txt = data.toString();
} }
page()->mainFrame()->setHtml(txt, getCurrentDir(newUrl)); //std::cerr << txt.toStdString() << std::endl;
setHtml(txt);
if(!_skipSave) { if(!_skipSave) {
visitedPages_.push_back(_url.toString()); visitedPages_.push_back(_url.toString());
...@@ -117,7 +106,7 @@ void HelpBrowser::backward() { ...@@ -117,7 +106,7 @@ void HelpBrowser::backward() {
if(isBackwardAvailable()) { if(isBackwardAvailable()) {
currentPage_--; currentPage_--;
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true); open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
} }
} }
...@@ -125,7 +114,7 @@ void HelpBrowser::forward() { ...@@ -125,7 +114,7 @@ void HelpBrowser::forward() {
if(isForwardAvailable()) { if(isForwardAvailable()) {
currentPage_++; currentPage_++;
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true); open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
} }
} }
...@@ -9,33 +9,35 @@ ...@@ -9,33 +9,35 @@
#define HELPBROWSER_HH_ #define HELPBROWSER_HH_
#include <QtGui> #include <QtGui>
#include <QWebView> #include <QTextBrowser>
#include <QtHelp> #include <QtHelp>
class HelpBrowser : public QWebView { class HelpBrowser : public QTextBrowser {
Q_OBJECT Q_OBJECT
public: public:
HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent = 0); HelpBrowser(QHelpEngine* _helpEngine, const QUrl& _basePath, QWidget* parent = 0);
virtual ~HelpBrowser(); virtual ~HelpBrowser();
QVariant loadBytes(const QUrl& url); QVariant loadResource ( int _type, const QUrl& _name );
bool isBackwardAvailable(); bool isBackwardAvailable();
bool isForwardAvailable(); bool isForwardAvailable();
void setUrl(const QUrl& _url);
signals: signals:
void urlChanged ( const QUrl& src ); void urlChanged ( const QUrl& src );
void linkClicked(const QString& _link);
public slots: public slots:
void load(const QUrl& _url); void open(const QUrl& _url);
void open(const QString& _url);
void load(const QUrl& url, const QString& _s_url, bool _skipSave = false); void open(const QUrl& _url, const QString& _str, bool _skipSave = false);
void backward(); void backward();
...@@ -47,12 +49,11 @@ private: ...@@ -47,12 +49,11 @@ private:
QHelpEngine* helpEngine_; QHelpEngine* helpEngine_;
QString css_str_;
QString css_file_;
QStringList visitedPages_; QStringList visitedPages_;
int currentPage_; int currentPage_;
QUrl basePath_;
}; };
......
...@@ -13,12 +13,13 @@ ...@@ -13,12 +13,13 @@
#include <QTextStream> #include <QTextStream>
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite, const QString& _baseURL)
: QMainWindow(parent), : QMainWindow(parent),
searchWidget_(0), searchWidget_(0),
results_(0), tabWidget_(0),
textWindow_(0), textWindow_(0),
helpEngine_(0) { helpEngine_(0),
searchEngine_(0) {
setupUi(this); setupUi(this);
...@@ -43,14 +44,20 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) ...@@ -43,14 +44,20 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
homeButton_->setIcon(QIcon(iconPath+"go-home.png")); homeButton_->setIcon(QIcon(iconPath+"go-home.png"));
searchButton_->setIcon(QIcon(iconPath+"edit-find.png")); searchButton_->setIcon(QIcon(iconPath+"edit-find.png"));
tabWidget_ = new QTabWidget(this);
helpEngine_ = new QHelpEngine(filename, this); helpEngine_ = new QHelpEngine(filename, this);
helpEngine_->setupData(); helpEngine_->setupData();
textWindow_ = new HelpBrowser(helpEngine_, this); searchEngine_ = new QHelpSearchEngine(helpEngine_, this);
textWindow_ = new HelpBrowser(helpEngine_, _baseURL, this);
homeIndex_ = tabWidget_->addTab(textWindow_, "Home");
gridLayout_->addWidget(helpEngine_->contentWidget(), 0, 0); gridLayout_->addWidget(helpEngine_->contentWidget(), 0, 0);
gridLayout_->addWidget(textWindow_, 0, 1); gridLayout_->addWidget(tabWidget_, 0, 1);
gridLayout_->setColumnStretch(0, 1); gridLayout_->setColumnStretch(0, 1);
gridLayout_->setColumnStretch(1, 3); gridLayout_->setColumnStretch(1, 3);
...@@ -61,9 +68,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) ...@@ -61,9 +68,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) ); searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) );
results_ = new QListWidget(); searchWidget_->setWidget(searchEngine_->queryWidget());
searchWidget_->setWidget(helpEngine_->indexWidget());
//searchWidget_->setWidget(results_); //searchWidget_->setWidget(results_);
searchWidget_->hide(); searchWidget_->hide();
...@@ -72,17 +77,24 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) ...@@ -72,17 +77,24 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
// Entry in tree view has been clicked // Entry in tree view has been clicked
connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)), connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)),
textWindow_, SLOT(load(const QUrl&))); textWindow_, SLOT(open(const QUrl&)));
connect(helpEngine_->indexWidget(), SIGNAL(linkActivated(const QUrl&, const QString&)), connect(helpEngine_->indexWidget(), SIGNAL(linkActivated(const QUrl&, const QString&)),
textWindow_, SLOT(load(const QUrl&, const QString&))); textWindow_, SLOT(open(const QUrl&, const QString&)));
// Entry in results view (search) has been clicked // Search button
//connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
// textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
// Search button // Search button
connect(searchButton_, SIGNAL(clicked()), this, SLOT(searchItems())); connect(searchEngine_->queryWidget(), SIGNAL(search()), this, SLOT(startSearch()));
// Show results if search is finished
connect(searchEngine_, SIGNAL(searchingFinished(int)), this, SLOT(showResults(int)));
// Show results if search is finished
connect(searchEngine_->resultWidget(), SIGNAL(requestShowLink(const QUrl&)),
this, SLOT(showFoundSite(const QUrl&)));
// Back button // Back button
connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack())); connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack()));
...@@ -96,12 +108,14 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) ...@@ -96,12 +108,14 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
// Source has been reloaded // Source has been reloaded
connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&))); connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&)));
// Register documentation (if not registered yet)
helpEngine_->registerDocumentation(filename);
helpEngine_->setCurrentFilter("");
// Load main page // Load main page
textWindow_->load(QUrl(homeSite_)); textWindow_->open(QUrl(homeSite_));
}
void HelpWidget::startSearch() {
searchEngine_->search(searchEngine_->queryWidget()->query());
} }
void HelpWidget::setHomeSite(const QString& _homeSite) { void HelpWidget::setHomeSite(const QString& _homeSite) {
...@@ -109,6 +123,12 @@ void HelpWidget::setHomeSite(const QString& _homeSite) { ...@@ -109,6 +123,12 @@ void HelpWidget::setHomeSite(const QString& _homeSite) {
homeSite_ = _homeSite; homeSite_ = _homeSite;
} }
void HelpWidget::showFoundSite(const QUrl& _url) {
textWindow_->open(_url);
tabWidget_->setCurrentIndex(homeIndex_);
}
void HelpWidget::update(const QUrl& /* url */) { void HelpWidget::update(const QUrl& /* url */) {
updateButtons(); updateButtons();
...@@ -130,7 +150,7 @@ void HelpWidget::goBack() { ...@@ -130,7 +150,7 @@ void HelpWidget::goBack() {
void HelpWidget::goHome() { void HelpWidget::goHome() {
textWindow_->load(homeSite_); textWindow_->open(homeSite_);
updateButtons(); updateButtons();
} }
...@@ -150,13 +170,17 @@ void HelpWidget::updateButtons() { ...@@ -150,13 +170,17 @@ void HelpWidget::updateButtons() {
} }
} }
void HelpWidget::searchItems() { void HelpWidget::showSearchWidget() {
QMap<QString, QUrl> results = helpEngine_->linksForIdentifier(searchButton_->text()); searchWidget_->show();
}
std::cerr << "Found: " << results.size() << std::endl; void HelpWidget::showResults(int /*_hits*/) {
searchWidget_->show(); searchWidget_->hide();
int resultsTabIndex_ = tabWidget_->addTab(searchEngine_->resultWidget(), "Results");
tabWidget_->setCurrentIndex(resultsTabIndex_);
} }
void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) { void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
...@@ -166,6 +190,5 @@ void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) { ...@@ -166,6 +190,5 @@ void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
HelpWidget::~HelpWidget() { HelpWidget::~HelpWidget() {
delete searchWidget_; delete searchWidget_;
delete results_;
delete textWindow_; delete textWindow_;
} }
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
#include <QtHelp> #include <QtHelp>
#include <QTextDocument> #include <QTextDocument>
#include <QHelpSearchEngine>
#include <QTabWidget>
#include <iostream> #include <iostream>
#include "helpBrowser.hh" #include "helpBrowser.hh"
...@@ -24,7 +27,7 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget ...@@ -24,7 +27,7 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
public: public:
HelpWidget(QWidget* parent = 0, const QString& _homeSite = ""); HelpWidget(QWidget* parent = 0, const QString& _homeSite = "", const QString& _baseURL = "");
virtual ~HelpWidget(); virtual ~HelpWidget();
...@@ -32,13 +35,19 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget ...@@ -32,13 +35,19 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
private slots: private slots:
void startSearch();
void goBack(); void goBack();
void goForward(); void goForward();
void goHome(); void goHome();
void searchItems(); void showSearchWidget();
void showFoundSite(const QUrl& _url);
void showResults(int _hits);
void update(const QUrl& url); void update(const QUrl& url);
...@@ -50,14 +59,18 @@ private slots: ...@@ -50,14 +59,18 @@ private slots:
// For the search popup // For the search popup
QDockWidget* searchWidget_; QDockWidget* searchWidget_;
QListWidget* results_;
QTabWidget* tabWidget_;
HelpBrowser* textWindow_; HelpBrowser* textWindow_;
QHelpEngine* helpEngine_; QHelpEngine* helpEngine_;
QHelpSearchEngine* searchEngine_;
QString homeSite_; QString homeSite_;
int homeIndex_;
}; };
......
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