Commit a5c86c28 authored by Mike Kremer's avatar Mike Kremer

Added icons to help browser as well as a home button.

Replaced old QTextBrowser by QWebView which offers more functions to properly display the help sites.
Search now opens a small window at the bottom which displays "all" searchable objects. These still have to be filtered.
Clicking links now gets handled by HelpBrowser such that requested pages can be load out of the help engine
which uses in fact it's own domain namespace and is therefore not accessible by QWebView.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5615 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4b142e1d
......@@ -57,7 +57,7 @@ void CoreWidget::showHelpBrowser( ) {
return;
if(helpWidget_ == 0)
helpWidget_ = new HelpWidget();
helpWidget_ = new HelpWidget(this, "qthelp://org.openflipper.doc/OpenFlipper-1.0-Dev/main.html");
helpWidget_->show();
......
......@@ -9,62 +9,66 @@
#include <iostream>
#include <QWebFrame>
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) :
QTextBrowser(parent),
helpEngine_(_helpEngine),
doc_(0) {
QWebView(parent),
helpEngine_(_helpEngine) {
currentPage_ = 0;
doc_ = new QTextDocument();
page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
// Link has been clicked
connect(this->page(), SIGNAL(linkClicked(const QUrl&)),
this, SLOT(load(const QUrl&)));
this->setDocument(doc_);
}
HelpBrowser::~HelpBrowser() {
delete helpEngine_;
}
QVariant HelpBrowser::loadResource(int type, const QUrl &url) {
if (url.scheme() == "qthelp") {
QVariant HelpBrowser::loadBytes(const QUrl &url) {
QByteArray bytes = helpEngine_->fileData(url);
return QVariant(bytes);
}
else {
return QTextBrowser::loadResource(type, url);
}
}
void HelpBrowser::setSource(const QUrl& url) {
void HelpBrowser::setUrl(const QUrl& _url) {
load(_url, "");
}
void HelpBrowser::load(const QUrl& _url) {
if(url.scheme() != "qthelp") {
load(_url, "");
}
void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSave) {
QUrl newUrl;
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();
comp[comp.size()-1] = _url.toString();
QUrl newUrl = QUrl(comp.join("/"));
newUrl = QUrl(comp.join("/"));
if(helpEngine_->findFile(newUrl).isValid())
this->setSource(newUrl, newUrl.toString());
else
if(!helpEngine_->findFile(newUrl).isValid()) {
QMessageBox::warning( this, "OpenFlipper Help",
"Unable to find specified file within documentation.");
return;
}
} else {
this->setSource(url, url.toString());
newUrl = _url;
}
}
void HelpBrowser::setSource(const QUrl& url, const QString& /* str */, bool _skipSave) {
QVariant data = this->loadResource(QTextDocument::HtmlResource, url);
QVariant data = this->loadBytes(newUrl);
QString txt;
......@@ -79,45 +83,24 @@ void HelpBrowser::setSource(const QUrl& url, const QString& /* str */, bool _ski
txt = data.toString();
}
doc_->setHtml(txt);
refreshCSS();
page()->mainFrame()->setHtml(txt, getCurrentDir(newUrl));
if(!_skipSave) {
visitedPages_.push_back(url.toString());
visitedPages_.push_back(_url.toString());
currentPage_ = visitedPages_.size()-1;
}
emit sourceChanged ( url.toString() );
emit urlChanged ( _url.toString() );
}
bool HelpBrowser::setCSSData(QString& _filename) {
QUrl HelpBrowser::getCurrentDir(const QUrl& _url) {
// Load style sheet
QFile file(_filename);
if(!file.open(QIODevice::ReadOnly))
return false;
QTextStream css_stream(&file);
// Read css data into member variable
css_str_ = css_stream.readAll();
// Cut off the path to css file
#ifdef WIN32
css_file_ = _filename.split("\\").last();
#else
css_file_ = _filename.split("/").last();
#endif
doc_->addResource( QTextDocument::StyleSheetResource, QUrl( css_file_ ), css_str_ );
doc_->setDefaultStyleSheet(css_file_);
return true;
}
QStringList str_list = _url.toString().split("/");
str_list[str_list.size() - 1] = "";
void HelpBrowser::refreshCSS() {
QString nstr = str_list.join("/");
if(css_str_.length() > 0)
doc_->addResource( QTextDocument::StyleSheetResource, QUrl( css_file_ ), css_str_ );
return QUrl(nstr);
}
bool HelpBrowser::isForwardAvailable() {
......@@ -134,7 +117,7 @@ void HelpBrowser::backward() {
if(isBackwardAvailable()) {
currentPage_--;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
......@@ -142,7 +125,7 @@ void HelpBrowser::forward() {
if(isForwardAvailable()) {
currentPage_++;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
......@@ -9,10 +9,10 @@
#define HELPBROWSER_HH_
#include <QtGui>
#include <QTextBrowser>
#include <QWebView>
#include <QtHelp>
class HelpBrowser : public QTextBrowser {
class HelpBrowser : public QWebView {
Q_OBJECT
public:
......@@ -20,24 +20,22 @@ public:
~HelpBrowser();
QVariant loadResource(int type, const QUrl& url);
bool setCSSData(QString& _filename);
void refreshCSS();
QVariant loadBytes(const QUrl& url);
bool isBackwardAvailable();
bool isForwardAvailable();
void setUrl(const QUrl& _url);
signals:
void sourceChanged ( const QString& src );
void urlChanged ( const QUrl& src );
public slots:
void setSource(const QUrl& url);
void load(const QUrl& _url);
void setSource(const QUrl& url, const QString& /* str */, bool _skipSave = false);
void load(const QUrl& url, const QString& _s_url, bool _skipSave = false);
void backward();
......@@ -45,9 +43,9 @@ public slots:
private:
QHelpEngine* helpEngine_;
QUrl getCurrentDir(const QUrl& _url);
QTextDocument* doc_;
QHelpEngine* helpEngine_;
QString css_str_;
QString css_file_;
......
......@@ -13,7 +13,7 @@
#include <QTextStream>
HelpWidget::HelpWidget(QWidget* parent)
HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
: QMainWindow(parent),
searchWidget_(0),
textWindow_(0),
......@@ -21,13 +21,26 @@ HelpWidget::HelpWidget(QWidget* parent)
setupUi(this);
homeSite_ = _homeSite;
QString filename = QString(OpenFlipper::Options::applicationDirStr());
filename += "/Help/Help.qhc";
QString stylesheet = QString(OpenFlipper::Options::applicationDirStr());
stylesheet += "/Help/acg_style.css";
//closeTabButton->setIcon(QIcon(iconPath+"tab-close.png"));
QString iconPath = QString(OpenFlipper::Options::iconDirStr());
#ifdef WIN32
iconPath += "\\";
#else
iconPath += "/";
#endif
// Set Buttons
backButton_->setIcon(QIcon(iconPath+"arrow-left.png"));
forwardButton_->setIcon(QIcon(iconPath+"arrow-right.png"));
homeButton_->setIcon(QIcon(iconPath+"go-home.png"));
searchButton_->setIcon(QIcon(iconPath+"edit-find.png"));
helpEngine_ = new QHelpEngine(filename, this);
......@@ -49,22 +62,23 @@ HelpWidget::HelpWidget(QWidget* parent)
results_ = new QListWidget();
searchWidget_->setWidget(results_);
searchWidget_->setWidget(helpEngine_->indexWidget());
//searchWidget_->setWidget(results_);
searchWidget_->hide();
addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);
// Load css data
textWindow_->setCSSData(stylesheet);
// Entry in tree view has been clicked
connect(helpEngine_->contentWidget(), SIGNAL(linkActivated(const QUrl&)),
textWindow_, SLOT(setSource(const QUrl&)));
textWindow_, SLOT(load(const QUrl&)));
connect(helpEngine_->indexWidget(), SIGNAL(linkActivated(const QUrl&, const QString&)),
textWindow_, SLOT(load(const QUrl&, const QString&)));
// Entry in results view (search) has been clicked
connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
//connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
// textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
// Search button
connect(searchButton_, SIGNAL(clicked()), this, SLOT(searchItems()));
......@@ -75,14 +89,26 @@ HelpWidget::HelpWidget(QWidget* parent)
// Forward button
connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward()));
// Forward button
connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));
// Source has been reloaded
connect(textWindow_, SIGNAL(sourceChanged(const QString&)), this, SLOT(update(const QString&)));
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_->setSource(QUrl("qthelp://com.openflipper.dev/openflipper-1.0/main.html"));
textWindow_->load(QUrl(homeSite_));
}
void HelpWidget::setHomeSite(const QString& _homeSite) {
homeSite_ = _homeSite;
}
void HelpWidget::update(const QString& /* url */) {
void HelpWidget::update(const QUrl& /* url */) {
updateButtons();
}
......@@ -101,6 +127,13 @@ void HelpWidget::goBack() {
updateButtons();
}
void HelpWidget::goHome() {
textWindow_->load(homeSite_);
updateButtons();
}
void HelpWidget::updateButtons() {
if(!textWindow_->isBackwardAvailable()) {
......@@ -118,19 +151,9 @@ void HelpWidget::updateButtons() {
void HelpWidget::searchItems() {
QMap<QString, QUrl> map = helpEngine_->linksForIdentifier(searchEdit_->text());
std::cerr << "Searching for " << searchEdit_->text().toStdString() << std::endl;
QMap<QString, QUrl> results = helpEngine_->linksForIdentifier(searchButton_->text());
QList<QUrl> list = map.values();
std::cerr << "Found " << list.size() << " items!" << std::endl;
for(int i = 0; i < list.size(); i++) {
QListWidgetItem itm(list[i].toString());
results_->insertItem(i, &itm);
std::cerr << "Adding item " << list[i].toString().toStdString() << std::endl;
}
std::cerr << "Found: " << results.size() << std::endl;
searchWidget_->show();
}
......
......@@ -24,19 +24,23 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
public:
HelpWidget(QWidget* parent = 0);
HelpWidget(QWidget* parent = 0, const QString& _homeSite = "");
virtual ~HelpWidget();
void setHomeSite(const QString& _homeSite);
private slots:
void goBack();
void goForward();
void goHome();
void searchItems();
void update(const QString& url);
void update(const QUrl& url);
void openFoundSite(QListWidgetItem* _item);
......@@ -52,6 +56,8 @@ private slots:
QHelpEngine* helpEngine_;
QString homeSite_;
};
......
......@@ -16,62 +16,129 @@
<widget class="QLineEdit" name="searchEdit_" >
<property name="geometry" >
<rect>
<x>500</x>
<y>20</y>
<x>510</x>
<y>30</y>
<width>361</width>
<height>26</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget" >
<property name="geometry" >
<rect>
<x>9</x>
<y>69</y>
<width>951</width>
<height>631</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_" />
</widget>
<widget class="QPushButton" name="searchButton_" >
<widget class="QToolButton" name="backButton_" >
<property name="geometry" >
<rect>
<x>870</x>
<y>20</y>
<width>77</width>
<height>29</height>
<x>280</x>
<y>30</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
<property name="toolTip" >
<string>Go one page back.</string>
</property>
<property name="whatsThis" >
<string>Go one page back.</string>
</property>
<property name="text" >
<string>Search</string>
<string>Back</string>
</property>
</widget>
<widget class="QPushButton" name="backButton_" >
<widget class="QToolButton" name="forwardButton_" >
<property name="geometry" >
<rect>
<x>330</x>
<y>20</y>
<width>61</width>
<height>29</height>
<x>340</x>
<y>30</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
<property name="toolTip" >
<string>Go one page forward.</string>
</property>
<property name="whatsThis" >
<string>Go one page forward.</string>
</property>
<property name="text" >
<string>Back</string>
<string>Forward</string>
</property>
</widget>
<widget class="QPushButton" name="forwardButton_" >
<widget class="QToolButton" name="homeButton_" >
<property name="geometry" >
<rect>
<x>410</x>
<y>20</y>
<width>61</width>
<height>29</height>
<x>430</x>
<y>30</y>
<width>51</width>
<height>26</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
<property name="toolTip" >
<string>Open home site.</string>
</property>
<property name="whatsThis" >
<string>Open home site.</string>
</property>
<property name="text" >
<string>Forward</string>
<string>Home</string>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget" >
<widget class="QToolButton" name="searchButton_" >
<property name="geometry" >
<rect>
<x>9</x>
<y>69</y>
<width>951</width>
<height>631</height>
<x>890</x>
<y>30</y>
<width>61</width>
<height>26</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_" />
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>
<property name="toolTip" >
<string>Search documentation for specified terms.</string>
</property>
<property name="whatsThis" >
<string>Search documentation for specified terms.</string>
</property>
<property name="text" >
<string>Search</string>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar" />
......
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