Commit b8f76a6f authored by Mike Kremer's avatar Mike Kremer

Added help browser to OpenFlipper. The search function as css style sheets does not work, yet.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5589 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4367bb0f
......@@ -97,8 +97,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
snapshotName_("snap.png"),
snapshotCounter_(0),
stackMenu_(0),
helpBrowserDeveloper_(0),
helpBrowserUser_(0),
helpWidget_(0),
aboutWidget_(0),
optionsWidget_(0),
plugins_(_plugins),
......
......@@ -76,7 +76,7 @@
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
#include <OpenFlipper/widgets/helpBrowser/helpWidget.hh>
#include <OpenFlipper/widgets/helpWidget/helpWidget.hh>
#include <OpenFlipper/Core/PluginInfo.hh>
......@@ -664,17 +664,11 @@ public:
public slots:
/// Display the help Browser
void showHelpBrowserUser();
/// Display the help Browser
void showHelpBrowserDeveloper();
void showHelpBrowser();
private:
/// Pointer to the help Browser
HelpWidget* helpBrowserDeveloper_;
/// Pointer to the help Browser
HelpWidget* helpBrowserUser_;
HelpWidget* helpWidget_;
/** @} */
......
......@@ -45,49 +45,21 @@
#include <OpenFlipper/common/GlobalOptions.hh>
//== IMPLEMENTATION ==========================================================
void CoreWidget::showHelpBrowserUser( ) {
if ( OpenFlipper::Options::nogui() )
return;
if ( helpBrowserUser_ == 0 ) {
helpBrowserUser_ = new HelpWidget( this ,true);
}
#include <QtHelp>
//show the widget centered
QPoint center;
center.setX( x() + width() / 2 );
center.setY( y() + height() / 2 );
helpBrowserUser_->setGeometry(center.x() - helpBrowserUser_->width() / 2,
center.y() - helpBrowserUser_->height()/ 2, helpBrowserUser_->width(), helpBrowserUser_->height());
helpBrowserUser_->show();
}
//== IMPLEMENTATION ==========================================================
void CoreWidget::showHelpBrowserDeveloper( ) {
if ( OpenFlipper::Options::nogui() )
return;
if ( helpBrowserDeveloper_ == 0 ) {
helpBrowserDeveloper_ = new HelpWidget( this ,false);
}
void CoreWidget::showHelpBrowser( ) {
//show the widget centered
QPoint center;
center.setX( x() + width() / 2 );
center.setY( y() + height() / 2 );
if ( OpenFlipper::Options::nogui() )
return;
helpBrowserDeveloper_->setGeometry(center.x() - helpBrowserDeveloper_->width() / 2,
center.y() - helpBrowserDeveloper_->height()/ 2, helpBrowserDeveloper_->width(), helpBrowserDeveloper_->height());
if(helpWidget_ == 0)
helpWidget_ = new HelpWidget();
helpBrowserDeveloper_->show();
helpWidget_->show();
}
......
......@@ -383,19 +383,11 @@ void CoreWidget::setupMenuBar()
menuBar()->addMenu(helpMenu_);
//Open Help Browser
QAction* AC_HelpBrowser = new QAction(tr("&User Help"), this);
AC_HelpBrowser->setStatusTip(tr("Open Help Browser with User Documentation"));
QAction* AC_HelpBrowser = new QAction(tr("&Help"), this);
AC_HelpBrowser->setStatusTip(tr("Open Help Browser with Documentation"));
AC_HelpBrowser->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-browser.png"));
AC_HelpBrowser->setWhatsThis("Open the <b>Help Browser</b>");
connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowserUser()));
helpMenu_->addAction(AC_HelpBrowser);
//Open Help Browser
AC_HelpBrowser = new QAction(tr("&Developer Help"), this);
AC_HelpBrowser->setStatusTip(tr("Open Help Browser with Developer Documentation"));
AC_HelpBrowser->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"help-browser.png"));
AC_HelpBrowser->setWhatsThis("Open the <b>Help Browser</b>");
connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowserDeveloper()));
connect(AC_HelpBrowser, SIGNAL(triggered()), this, SLOT(showHelpBrowser()));
helpMenu_->addAction(AC_HelpBrowser);
//Switch to whats this mode
......
/*
* helpBrowser.cc
*
* Created on: Apr 8, 2009
* Author: kremer
*/
#include "helpBrowser.hh"
#include <iostream>
HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) :
QTextBrowser(parent),
helpEngine_(_helpEngine),
doc_(0) {
currentPage_ = 0;
doc_ = new QTextDocument();
this->setDocument(doc_);
}
HelpBrowser::~HelpBrowser() {
delete helpEngine_;
}
QVariant HelpBrowser::loadResource(int type, const QUrl &url) {
if (url.scheme() == "qthelp") {
QByteArray bytes = helpEngine_->fileData(url);
return QVariant(bytes);
}
else {
return QTextBrowser::loadResource(type, url);
}
}
void HelpBrowser::setSource(const 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();
QUrl newUrl = QUrl(comp.join("/"));
if(helpEngine_->findFile(newUrl).isValid())
this->setSource(newUrl, newUrl.toString());
else
QMessageBox::warning( this, "OpenFlipper Help",
"Unable to find specified file within documentation.");
} else {
this->setSource(url, url.toString());
}
}
void HelpBrowser::setSource(const QUrl& url, const QString& /* str */, bool _skipSave) {
QVariant data = this->loadResource(QTextDocument::HtmlResource, url);
QString txt;
if (data.type() == QVariant::String) {
txt = data.toString();
} else if (data.type() == QVariant::ByteArray) {
QByteArray ba = data.toByteArray();
QTextCodec *codec = Qt::codecForHtml(ba);
txt = codec->toUnicode(ba);
txt = data.toString();
}
doc_->setHtml(txt);
refreshCSS();
if(!_skipSave) {
visitedPages_.push_back(url.toString());
currentPage_ = visitedPages_.size()-1;
}
emit sourceChanged ( url.toString() );
}
bool HelpBrowser::setCSSData(QString& _filename) {
// 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;
}
void HelpBrowser::refreshCSS() {
if(css_str_.length() > 0)
doc_->addResource( QTextDocument::StyleSheetResource, QUrl( css_file_ ), css_str_ );
}
bool HelpBrowser::isForwardAvailable() {
return currentPage_ < visitedPages_.size() - 1;
}
bool HelpBrowser::isBackwardAvailable() {
return currentPage_ > 0;
}
void HelpBrowser::backward() {
if(isBackwardAvailable()) {
currentPage_--;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
void HelpBrowser::forward() {
if(isForwardAvailable()) {
currentPage_++;
setSource(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
}
}
/*
* helpBrowser.hh
*
* Created on: Apr 8, 2009
* Author: kremer
*/
#ifndef HELPBROWSER_HH_
#define HELPBROWSER_HH_
#include <QtGui>
#include <QTextBrowser>
#include <QtHelp>
class HelpBrowser : public QTextBrowser {
Q_OBJECT
public:
HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent = 0);
~HelpBrowser();
QVariant loadResource(int type, const QUrl& url);
bool setCSSData(QString& _filename);
void refreshCSS();
bool isBackwardAvailable();
bool isForwardAvailable();
signals:
void sourceChanged ( const QString& src );
public slots:
void setSource(const QUrl& url);
void setSource(const QUrl& url, const QString& /* str */, bool _skipSave = false);
void backward();
void forward();
private:
QHelpEngine* helpEngine_;
QTextDocument* doc_;
QString css_str_;
QString css_file_;
QStringList visitedPages_;
int currentPage_;
};
#endif /* HELPBROWSER_HH_ */
/*
* helpWidget.cc
*
* Created on: Apr 7, 2009
* Author: kremer
*/
#include "helpWidget.hh"
#include <OpenFlipper/common/GlobalOptions.hh>
#include <iostream>
#include <QTextStream>
HelpWidget::HelpWidget(QWidget* parent)
: QMainWindow(parent),
searchWidget_(0),
textWindow_(0),
helpEngine_(0) {
setupUi(this);
QString filename = QString(OpenFlipper::Options::applicationDirStr());
filename += "/Help/Help.qhc";
QString stylesheet = QString(OpenFlipper::Options::applicationDirStr());
stylesheet += "/Help/acg_style.css";
//std::cerr << filename.toStdString() << std::endl;
helpEngine_ = new QHelpEngine(filename, this);
helpEngine_->setupData();
textWindow_ = new HelpBrowser(helpEngine_, this);
gridLayout_->addWidget(helpEngine_->contentWidget(), 0, 0);
gridLayout_->addWidget(textWindow_, 0, 1);
gridLayout_->setColumnStretch(0, 1);
gridLayout_->setColumnStretch(1, 3);
// Search popup at bottom of window
searchWidget_ = new QDockWidget(tr("Search results"), this);
searchWidget_->setFeatures( QDockWidget::DockWidgetClosable );
searchWidget_->resize(this->size().width(), floor(this->size().height() / 3));
results_ = new QListWidget();
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&)));
// 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(searchItems()));
// Back button
connect(backButton_, SIGNAL(clicked()), this, SLOT(goBack()));
// Forward button
connect(forwardButton_, SIGNAL(clicked()), this, SLOT(goForward()));
// Source has been reloaded
connect(textWindow_, SIGNAL(sourceChanged(const QString&)), this, SLOT(update(const QString&)));
// Load main page
textWindow_->setSource(QUrl("qthelp://com.openflipper.dev/openflipper-1.0/main.html"));
}
void HelpWidget::update(const QString& /* url */) {
updateButtons();
}
void HelpWidget::goForward() {
textWindow_->forward();
updateButtons();
}
void HelpWidget::goBack() {
textWindow_->backward();
updateButtons();
}
void HelpWidget::updateButtons() {
if(!textWindow_->isBackwardAvailable()) {
backButton_->setEnabled(false);
} else {
backButton_->setEnabled(true);
}
if(!textWindow_->isForwardAvailable()) {
forwardButton_->setEnabled(false);
} else {
forwardButton_->setEnabled(true);
}
}
void HelpWidget::searchItems() {
QMap<QString, QUrl> map = helpEngine_->linksForIdentifier(searchEdit_->text());
std::cerr << "Searching for " << searchEdit_->text().toStdString() << std::endl;
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;
}
searchWidget_->show();
}
void HelpWidget::openFoundSite(QListWidgetItem* _item) {
}
/*
* helpWidget.hh
*
* Created on: Apr 7, 2009
* Author: kremer
*/
#ifndef HELPWIDGET_HH_
#define HELPWIDGET_HH_
#include "ui_helpWidget.hh"
#include <QtGui>
#include <QtHelp>
#include <QTextDocument>
#include <iostream>
#include "helpBrowser.hh"
class HelpWidget : public QMainWindow, public Ui::HelpWidget
{
Q_OBJECT
public:
HelpWidget(QWidget* parent = 0);
private slots:
void goBack();
void goForward();
void searchItems();
void update(const QString& url);
void openFoundSite(QListWidgetItem* _item);
private:
void updateButtons();
// For the search popup
QDockWidget* searchWidget_;
QGridLayout* grid;
QListWidget* results_;
HelpBrowser* textWindow_;
QHelpEngine* helpEngine_;
};
#endif /* HELPWIDGET_HH_ */
<ui version="4.0" >
<class>HelpWidget</class>
<widget class="QMainWindow" name="HelpWidget" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>970</width>
<height>734</height>
</rect>
</property>
<property name="windowTitle" >
<string>OpenFlipper Help</string>
</property>
<widget class="QWidget" name="centralwidget" >
<widget class="QLineEdit" name="searchEdit_" >
<property name="geometry" >
<rect>
<x>500</x>
<y>20</y>
<width>361</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="searchButton_" >
<property name="geometry" >
<rect>
<x>870</x>
<y>20</y>
<width>77</width>
<height>29</height>
</rect>
</property>
<property name="text" >
<string>Search</string>
</property>
</widget>
<widget class="QPushButton" name="backButton_" >
<property name="geometry" >
<rect>
<x>330</x>
<y>20</y>
<width>61</width>
<height>29</height>
</rect>
</property>
<property name="text" >
<string>Back</string>
</property>
</widget>
<widget class="QPushButton" name="forwardButton_" >
<property name="geometry" >
<rect>
<x>410</x>
<y>20</y>
<width>61</width>
<height>29</height>
</rect>
</property>
<property name="text" >
<string>Forward</string>
</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>
<widget class="QStatusBar" name="statusbar" />
</widget>
<resources/>
<connections/>
</ui>
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