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( ) {
return;
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();
......
......@@ -9,19 +9,17 @@
#include <iostream>
#include <QWebFrame>
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) :
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, const QUrl& _basePath, QWidget* parent) :
QWebView(parent),
helpEngine_(_helpEngine) {
QTextBrowser(parent),
helpEngine_(_helpEngine),
basePath_(_basePath) {
currentPage_ = 0;
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
// Link has been clicked
connect(this->page(), SIGNAL(linkClicked(const QUrl&)),
this, SLOT(load(const QUrl&)));
connect(this, SIGNAL(linkClicked(const QString&)),
this, SLOT(open(const QString&)));
}
......@@ -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, "");
}
void HelpBrowser::load(const QUrl& _url) {
return QVariant(helpEngine_->fileData(newUrl));
}
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") {
// Convert link to be within qthelp domain namespace
QString new_file = visitedPages_[currentPage_];
QStringList comp = new_file.split("/");
comp[comp.size()-1] = _url.toString();
void HelpBrowser::open(const QUrl& _url) {
newUrl = QUrl(comp.join("/"));
open(_url, "");
}
if(!helpEngine_->findFile(newUrl).isValid()) {
QMessageBox::warning( this, "OpenFlipper Help",
"Unable to find specified file within documentation.");
return;
}
void HelpBrowser::open(const QUrl& _url, const QString& /*_str*/, bool _skipSave) {
} else {
newUrl = _url;
}
QVariant data = this->loadBytes(newUrl);
QVariant data = this->loadResource(QTextDocument::HtmlResource, _url);
QString txt;
......@@ -83,7 +70,9 @@ void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSa
txt = data.toString();
}
page()->mainFrame()->setHtml(txt, getCurrentDir(newUrl));
//std::cerr << txt.toStdString() << std::endl;
setHtml(txt);
if(!_skipSave) {
visitedPages_.push_back(_url.toString());
......@@ -117,7 +106,7 @@ void HelpBrowser::backward() {
if(isBackwardAvailable()) {
currentPage_--;
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
......@@ -125,7 +114,7 @@ void HelpBrowser::forward() {
if(isForwardAvailable()) {
currentPage_++;
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
......@@ -9,33 +9,35 @@
#define HELPBROWSER_HH_
#include <QtGui>
#include <QWebView>
#include <QTextBrowser>
#include <QtHelp>
class HelpBrowser : public QWebView {
class HelpBrowser : public QTextBrowser {
Q_OBJECT
public:
HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent = 0);
HelpBrowser(QHelpEngine* _helpEngine, const QUrl& _basePath, QWidget* parent = 0);
virtual ~HelpBrowser();
QVariant loadBytes(const QUrl& url);
QVariant loadResource ( int _type, const QUrl& _name );
bool isBackwardAvailable();
bool isForwardAvailable();
void setUrl(const QUrl& _url);
signals:
void urlChanged ( const QUrl& src );
void linkClicked(const QString& _link);
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();
......@@ -47,12 +49,11 @@ private:
QHelpEngine* helpEngine_;
QString css_str_;
QString css_file_;
QStringList visitedPages_;
int currentPage_;
QUrl basePath_;
};
......
......@@ -13,12 +13,13 @@
#include <QTextStream>
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite, const QString& _baseURL)
: QMainWindow(parent),
searchWidget_(0),
results_(0),
tabWidget_(0),
textWindow_(0),
helpEngine_(0) {
helpEngine_(0),
searchEngine_(0) {
setupUi(this);
......@@ -43,14 +44,20 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
homeButton_->setIcon(QIcon(iconPath+"go-home.png"));
searchButton_->setIcon(QIcon(iconPath+"edit-find.png"));
tabWidget_ = new QTabWidget(this);
helpEngine_ = new QHelpEngine(filename, this);
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(textWindow_, 0, 1);
gridLayout_->addWidget(tabWidget_, 0, 1);
gridLayout_->setColumnStretch(0, 1);
gridLayout_->setColumnStretch(1, 3);
......@@ -61,9 +68,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
searchWidget_->resize(this->size().width(), floor( double(this->size().height() / 3)) );
results_ = new QListWidget();
searchWidget_->setWidget(helpEngine_->indexWidget());
searchWidget_->setWidget(searchEngine_->queryWidget());
//searchWidget_->setWidget(results_);
searchWidget_->hide();
......@@ -72,17 +77,24 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
// Entry in tree view has been clicked
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&)),
textWindow_, SLOT(load(const QUrl&, const QString&)));
textWindow_, SLOT(open(const QUrl&, const QString&)));
// Entry in results view (search) has been clicked
//connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
// textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
// Search button
connect(searchButton_, SIGNAL(clicked()), this, SLOT(showSearchWidget()));
// 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
connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack()));
......@@ -96,12 +108,14 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
// Source has been reloaded
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
textWindow_->load(QUrl(homeSite_));
textWindow_->open(QUrl(homeSite_));
}
void HelpWidget::startSearch() {
searchEngine_->search(searchEngine_->queryWidget()->query());
}
void HelpWidget::setHomeSite(const QString& _homeSite) {
......@@ -109,6 +123,12 @@ void HelpWidget::setHomeSite(const QString& _homeSite) {
homeSite_ = _homeSite;
}
void HelpWidget::showFoundSite(const QUrl& _url) {
textWindow_->open(_url);
tabWidget_->setCurrentIndex(homeIndex_);
}
void HelpWidget::update(const QUrl& /* url */) {
updateButtons();
......@@ -130,7 +150,7 @@ void HelpWidget::goBack() {
void HelpWidget::goHome() {
textWindow_->load(homeSite_);
textWindow_->open(homeSite_);
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*/) {
......@@ -166,6 +190,5 @@ void HelpWidget::openFoundSite(QListWidgetItem* /*_item*/) {
HelpWidget::~HelpWidget() {
delete searchWidget_;
delete results_;
delete textWindow_;
}
......@@ -14,6 +14,9 @@
#include <QtHelp>
#include <QTextDocument>
#include <QHelpSearchEngine>
#include <QTabWidget>
#include <iostream>
#include "helpBrowser.hh"
......@@ -24,7 +27,7 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
public:
HelpWidget(QWidget* parent = 0, const QString& _homeSite = "");
HelpWidget(QWidget* parent = 0, const QString& _homeSite = "", const QString& _baseURL = "");
virtual ~HelpWidget();
......@@ -32,13 +35,19 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
private slots:
void startSearch();
void goBack();
void goForward();
void goHome();
void searchItems();
void showSearchWidget();
void showFoundSite(const QUrl& _url);
void showResults(int _hits);
void update(const QUrl& url);
......@@ -50,14 +59,18 @@ private slots:
// For the search popup
QDockWidget* searchWidget_;
QListWidget* results_;
QTabWidget* tabWidget_;
HelpBrowser* textWindow_;
QHelpEngine* helpEngine_;
QHelpSearchEngine* searchEngine_;
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