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( ) { ...@@ -57,7 +57,7 @@ void CoreWidget::showHelpBrowser( ) {
return; return;
if(helpWidget_ == 0) if(helpWidget_ == 0)
helpWidget_ = new HelpWidget(); helpWidget_ = new HelpWidget(this, "qthelp://org.openflipper.doc/OpenFlipper-1.0-Dev/main.html");
helpWidget_->show(); helpWidget_->show();
......
...@@ -9,62 +9,66 @@ ...@@ -9,62 +9,66 @@
#include <iostream> #include <iostream>
#include <QWebFrame>
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) : HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) :
QTextBrowser(parent), QWebView(parent),
helpEngine_(_helpEngine), helpEngine_(_helpEngine) {
doc_(0) {
currentPage_ = 0; 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() { HelpBrowser::~HelpBrowser() {
delete helpEngine_; delete helpEngine_;
} }
QVariant HelpBrowser::loadResource(int type, const QUrl &url) { QVariant HelpBrowser::loadBytes(const QUrl &url) {
if (url.scheme() == "qthelp") {
QByteArray bytes = helpEngine_->fileData(url); QByteArray bytes = helpEngine_->fileData(url);
return QVariant(bytes); return QVariant(bytes);
} }
else {
return QTextBrowser::loadResource(type, url); void HelpBrowser::setUrl(const QUrl& _url) {
}
load(_url, "");
} }
void HelpBrowser::setSource(const QUrl& url) { void HelpBrowser::load(const QUrl& _url) {
load(_url, "");
}
void HelpBrowser::load(const QUrl& _url, const QString& /*_s_url*/, bool _skipSave) {
QUrl newUrl;
if(url.scheme() != "qthelp") { if(_url.scheme() != "qthelp") {
// Convert link to be within qthelp domain namespace // Convert link to be within qthelp domain namespace
QString new_file = visitedPages_[currentPage_]; QString new_file = visitedPages_[currentPage_];
QStringList comp = new_file.split("/"); 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()) if(!helpEngine_->findFile(newUrl).isValid()) {
this->setSource(newUrl, newUrl.toString());
else
QMessageBox::warning( this, "OpenFlipper Help", QMessageBox::warning( this, "OpenFlipper Help",
"Unable to find specified file within documentation."); "Unable to find specified file within documentation.");
return;
}
} else { } else {
newUrl = _url;
this->setSource(url, url.toString());
} }
}
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; QString txt;
...@@ -79,45 +83,24 @@ void HelpBrowser::setSource(const QUrl& url, const QString& /* str */, bool _ski ...@@ -79,45 +83,24 @@ void HelpBrowser::setSource(const QUrl& url, const QString& /* str */, bool _ski
txt = data.toString(); txt = data.toString();
} }
doc_->setHtml(txt); page()->mainFrame()->setHtml(txt, getCurrentDir(newUrl));
refreshCSS();
if(!_skipSave) { if(!_skipSave) {
visitedPages_.push_back(url.toString()); visitedPages_.push_back(_url.toString());
currentPage_ = visitedPages_.size()-1; 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 QStringList str_list = _url.toString().split("/");
QFile file(_filename); str_list[str_list.size() - 1] = "";
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;
}
void HelpBrowser::refreshCSS() { QString nstr = str_list.join("/");
if(css_str_.length() > 0) return QUrl(nstr);
doc_->addResource( QTextDocument::StyleSheetResource, QUrl( css_file_ ), css_str_ );
} }
bool HelpBrowser::isForwardAvailable() { bool HelpBrowser::isForwardAvailable() {
...@@ -134,7 +117,7 @@ void HelpBrowser::backward() { ...@@ -134,7 +117,7 @@ void HelpBrowser::backward() {
if(isBackwardAvailable()) { if(isBackwardAvailable()) {
currentPage_--; currentPage_--;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true); load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
} }
} }
...@@ -142,7 +125,7 @@ void HelpBrowser::forward() { ...@@ -142,7 +125,7 @@ void HelpBrowser::forward() {
if(isForwardAvailable()) { if(isForwardAvailable()) {
currentPage_++; currentPage_++;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true); load(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
} }
} }
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#define HELPBROWSER_HH_ #define HELPBROWSER_HH_
#include <QtGui> #include <QtGui>
#include <QTextBrowser> #include <QWebView>
#include <QtHelp> #include <QtHelp>
class HelpBrowser : public QTextBrowser { class HelpBrowser : public QWebView {
Q_OBJECT Q_OBJECT
public: public:
...@@ -20,24 +20,22 @@ public: ...@@ -20,24 +20,22 @@ public:
~HelpBrowser(); ~HelpBrowser();
QVariant loadResource(int type, const QUrl& url); QVariant loadBytes(const QUrl& url);
bool setCSSData(QString& _filename);
void refreshCSS();
bool isBackwardAvailable(); bool isBackwardAvailable();
bool isForwardAvailable(); bool isForwardAvailable();
void setUrl(const QUrl& _url);
signals: signals:
void sourceChanged ( const QString& src ); void urlChanged ( const QUrl& src );
public slots: 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(); void backward();
...@@ -45,9 +43,9 @@ public slots: ...@@ -45,9 +43,9 @@ public slots:
private: private:
QHelpEngine* helpEngine_; QUrl getCurrentDir(const QUrl& _url);
QTextDocument* doc_; QHelpEngine* helpEngine_;
QString css_str_; QString css_str_;
QString css_file_; QString css_file_;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include <QTextStream> #include <QTextStream>
HelpWidget::HelpWidget(QWidget* parent) HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
: QMainWindow(parent), : QMainWindow(parent),
searchWidget_(0), searchWidget_(0),
textWindow_(0), textWindow_(0),
...@@ -21,13 +21,26 @@ HelpWidget::HelpWidget(QWidget* parent) ...@@ -21,13 +21,26 @@ HelpWidget::HelpWidget(QWidget* parent)
setupUi(this); setupUi(this);
homeSite_ = _homeSite;
QString filename = QString(OpenFlipper::Options::applicationDirStr()); QString filename = QString(OpenFlipper::Options::applicationDirStr());
filename += "/Help/Help.qhc"; filename += "/Help/Help.qhc";
QString stylesheet = QString(OpenFlipper::Options::applicationDirStr()); QString stylesheet = QString(OpenFlipper::Options::applicationDirStr());
stylesheet += "/Help/acg_style.css"; 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); helpEngine_ = new QHelpEngine(filename, this);
...@@ -49,22 +62,23 @@ HelpWidget::HelpWidget(QWidget* parent) ...@@ -49,22 +62,23 @@ HelpWidget::HelpWidget(QWidget* parent)
results_ = new QListWidget(); results_ = new QListWidget();
searchWidget_->setWidget(results_); searchWidget_->setWidget(helpEngine_->indexWidget());
//searchWidget_->setWidget(results_);
searchWidget_->hide(); searchWidget_->hide();
addDockWidget(Qt::BottomDockWidgetArea, searchWidget_); addDockWidget(Qt::BottomDockWidgetArea, searchWidget_);
// Load css data
textWindow_->setCSSData(stylesheet);
// 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(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 // Entry in results view (search) has been clicked
connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)), //connect(results_, SIGNAL(itemDoubleClicked(QListWidgetItem*)),
textWindow_, SLOT(openFoundSite(QListWidgetItem*))); // textWindow_, SLOT(openFoundSite(QListWidgetItem*)));
// Search button // Search button
connect(searchButton_, SIGNAL(clicked()), this, SLOT(searchItems())); connect(searchButton_, SIGNAL(clicked()), this, SLOT(searchItems()));
...@@ -75,14 +89,26 @@ HelpWidget::HelpWidget(QWidget* parent) ...@@ -75,14 +89,26 @@ HelpWidget::HelpWidget(QWidget* parent)
// Forward button // Forward button
connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward())); connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward()));
// Forward button
connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));
// Source has been reloaded // 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 // 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(); updateButtons();
} }
...@@ -101,6 +127,13 @@ void HelpWidget::goBack() { ...@@ -101,6 +127,13 @@ void HelpWidget::goBack() {
updateButtons(); updateButtons();
} }
void HelpWidget::goHome() {
textWindow_->load(homeSite_);
updateButtons();
}
void HelpWidget::updateButtons() { void HelpWidget::updateButtons() {
if(!textWindow_->isBackwardAvailable()) { if(!textWindow_->isBackwardAvailable()) {
...@@ -118,19 +151,9 @@ void HelpWidget::updateButtons() { ...@@ -118,19 +151,9 @@ void HelpWidget::updateButtons() {
void HelpWidget::searchItems() { void HelpWidget::searchItems() {
QMap<QString, QUrl> map = helpEngine_->linksForIdentifier(searchEdit_->text()); QMap<QString, QUrl> results = helpEngine_->linksForIdentifier(searchButton_->text());
std::cerr << "Searching for " << searchEdit_->text().toStdString() << std::endl;
QList<QUrl> list = map.values(); std::cerr << "Found: " << results.size() << std::endl;
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;
}
searchWidget_->show(); searchWidget_->show();
} }
......
...@@ -24,19 +24,23 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget ...@@ -24,19 +24,23 @@ class HelpWidget : public QMainWindow, public Ui::HelpWidget
public: public:
HelpWidget(QWidget* parent = 0); HelpWidget(QWidget* parent = 0, const QString& _homeSite = "");
virtual ~HelpWidget(); virtual ~HelpWidget();
void setHomeSite(const QString& _homeSite);
private slots: private slots:
void goBack(); void goBack();
void goForward(); void goForward();
void goHome();
void searchItems(); void searchItems();
void update(const QString& url); void update(const QUrl& url);
void openFoundSite(QListWidgetItem* _item); void openFoundSite(QListWidgetItem* _item);
...@@ -52,6 +56,8 @@ private slots: ...@@ -52,6 +56,8 @@ private slots:
QHelpEngine* helpEngine_; QHelpEngine* helpEngine_;
QString homeSite_;
}; };
......
...@@ -16,62 +16,129 @@ ...@@ -16,62 +16,129 @@
<widget class="QLineEdit" name="searchEdit_" > <widget class="QLineEdit" name="searchEdit_" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>500</x> <x>510</x>
<y>20</y> <y>30</y>
<width>361</width> <width>361</width>
<height>26</height>
</rect>
</property>
<property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height> <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> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_" />
</widget> </widget>
<widget class="QPushButton" name="searchButton_" > <widget class="QToolButton" name="backButton_" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>870</x> <x>280</x>
<y>20</y> <y>30</y>
<width>77</width> <width>51</width>
<height>29</height> <height>26</height>
</rect> </rect>
</property> </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" > <property name="text" >
<string>Search</string> <string>Back</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="backButton_" > <widget class="QToolButton" name="forwardButton_" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>330</x> <x>340</x>
<y>20</y> <y>30</y>
<width>61</width> <width>51</width>
<height>29</height> <height>26</height>
</rect> </rect>
</property> </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" > <property name="text" >
<string>Back</string> <string>Forward</string>
</property> </property>
</widget> </widget>
<widget class="QPushButton" name="forwardButton_" > <widget class="QToolButton" name="homeButton_" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>410</x> <x>430</x>
<y>20</y> <y>30</y>
<width>61</width> <width>51</width>
<height>29</height> <height>26</height>
</rect> </rect>
</property> </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" > <property name="text" >
<string>Forward</string> <string>Home</string>
</property> </property>
</widget> </widget>
<widget class="QWidget" name="gridLayoutWidget" > <widget class="QToolButton" name="searchButton_" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>9</x> <x>890</x>
<y>69</y> <y>30</y>
<width>951</width> <width>61</width>
<height>631</height> <height>26</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="gridLayout_" /> <property name="maximumSize" >
<size>
<width>16777215</width>
<height>31</height>
</size>
</property>