Commit 80f85132 authored by Jan Möbius's avatar Jan Möbius

Help browser cleanup:

Use URL for everything and not QString
Full documentation for the help brwoser

Bugfix: Relative links were completly broken



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14191 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e6a7f488
......@@ -135,12 +135,12 @@ public:
//--------------------------------------------------- constructor / destructor
/** Create a glViewer.
\param _parent parent widget
\param _name name (qt internal, qt debugging)
\param _properties viewerOptions controlled by PluginFunctions
\param _statusBar pointer to an existing status bar for this widget,
if \c statusBar==0 then a \a private status bar will be created
\param _format OpenGL context settings, will be passed to glarea()
*
* @param scene The graphics scene that will be the parent of this widget
* @param _glWidget A pointer to the underlying gl widget
* @param _properties viewerOptions controlled by PluginFunctions
* @param _parent The parent graphicswidget
*
*/
glViewer( QGraphicsScene* _scene,
QGLWidget* _glWidget,
......@@ -150,10 +150,6 @@ public:
/// Destructor.
virtual ~glViewer();
//------------------------------------------------------------- public methods
virtual QSize sizeHint () const;
......
......@@ -61,8 +61,7 @@ HelpBrowser::HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent) :
currentPage_ = 0;
connect(this, SIGNAL(linkClicked(const QString&)),
this, SLOT(open(const QString&)));
connect(this, SIGNAL(linkClicked(const QString&)), this, SLOT(open(const QString&)));
}
......@@ -70,34 +69,68 @@ HelpBrowser::~HelpBrowser() {
}
void HelpBrowser::updateNameSpaceAndFolder (const QUrl& _url) {
// Extract the global virtual folder from this link
QString link = _url.toString();
QStringList linkParts = link.split("/");
if ( linkParts.size() > 3) {
currentNameSpace_ = linkParts[2];
currentVirtualFolder_ = linkParts[3];
} else {
currentNameSpace_ = "";
currentVirtualFolder_ = "";
std::cerr << "Unable to detect virtual folder or namespace of this link" << _url.toString().toStdString() << std::endl;
}
}
void HelpBrowser::rememberHistory (const QUrl& _url) {
// Delete the visited pages after the current position if they exist
if ( currentPage_ < visitedPages_.size()-1 )
visitedPages_.erase((visitedPages_.begin()+currentPage_),visitedPages_.end());
visitedPages_.push_back(_url);
currentPage_ = visitedPages_.size()-1;
}
QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
if (_url.scheme() == "qthelp") {
// Extract the global virtual folder from this link
QString link = _url.toString();
updateNameSpaceAndFolder(_url);
return QVariant(helpEngine_->fileData(_url));
} else {
QUrl newUrl;
if ( _url.toString().startsWith("..") ) {
QStringList linkParts = link.split("/");
// Relative url. We jump to a new context, so we first remove the relative part
QUrl tmpURL("qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/");
newUrl = tmpURL.resolved(_url);
// Update context
updateNameSpaceAndFolder(newUrl);
if ( linkParts.size() > 3) {
currentNameSpace_ = linkParts[2];
currentVirtualFolder_ = linkParts[3];
} else {
currentNameSpace_ = "";
currentVirtualFolder_ = "";
std::cerr << "Unable to detect virtual folder or namespace of this link" << _url.toString().toStdString() << std::endl;
}
return QVariant(helpEngine_->fileData(_url));
} else {
// Normal URL without relative parts so we can safely combine them
// and stay in the current context
newUrl = "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString();
const QString sNewUrl = "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString();
const QUrl newUrl = helpEngine_->findFile(QUrl(sNewUrl));
}
const QUrl newFileUrl = helpEngine_->findFile(newUrl);
if(newUrl.isValid())
return QVariant(helpEngine_->fileData(newUrl));
if(newFileUrl.isValid())
return QVariant(helpEngine_->fileData(newFileUrl));
else {
std::cerr << "Unable to find file at url : " << sNewUrl.toStdString() << std::endl;
std::cerr << "Unable to find file at url : " << newUrl.toString().toStdString() << std::endl;
return QVariant();
}
......@@ -107,15 +140,10 @@ QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
void HelpBrowser::open(const QString& _url) {
open(QUrl(_url), "");
}
void HelpBrowser::open(const QUrl& _url) {
open(_url, "");
open(QUrl(_url));
}
void HelpBrowser::open(const QUrl& _url, const QString& /*_str*/, bool _skipSave) {
void HelpBrowser::open(const QUrl& _url, bool _skipSave) {
QVariant data = this->loadResource(QTextDocument::HtmlResource, _url);
......@@ -132,14 +160,10 @@ void HelpBrowser::open(const QUrl& _url, const QString& /*_str*/, bool _skipSave
txt = data.toString();
}
//std::cerr << txt.toStdString() << std::endl;
setHtml(txt);
if(!_skipSave) {
visitedPages_.push_back(_url.toString());
currentPage_ = visitedPages_.size()-1;
}
if(!_skipSave)
rememberHistory(_url);
//jumps to a reference (Doxygen reference name and not section name)
//references are at the end of url after last '#'
......@@ -153,7 +177,11 @@ void HelpBrowser::open(const QUrl& _url, const QString& /*_str*/, bool _skipSave
QUrl HelpBrowser::getCurrentDir(const QUrl& _url) {
QStringList str_list = _url.toString().split("/");
str_list[str_list.size() - 1] = "";
if ( str_list.size() > 0 )
str_list[str_list.size() - 1] = "";
else
std::cerr << "Warning, getCurrentDir got invalid input: " << _url.toString().toStdString() << std::endl;
QString nstr = str_list.join("/");
......@@ -174,15 +202,17 @@ void HelpBrowser::backward() {
if(isBackwardAvailable()) {
currentPage_--;
open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
open(visitedPages_[currentPage_], true);
}
}
void HelpBrowser::forward() {
if(isForwardAvailable()) {
currentPage_++;
open(QUrl(visitedPages_[currentPage_]), visitedPages_[currentPage_], true);
open(visitedPages_[currentPage_], true);
}
}
......@@ -55,47 +55,128 @@
#include <QTextBrowser>
#include <QtHelp>
/** \class HelpBrowser
*
* This class implements OpenFlippers help browser. The QtHelp files are loaded at startup
* into the help engine which is passed to this widget.
*
*/
class HelpBrowser : public QTextBrowser {
Q_OBJECT
public:
/** \brief Constructor
*
* Sets up a new help widget which works on the given help engine
*
* @param _helpEngine QHelpEngine
* @param parent Parent widget
*/
HelpBrowser(QHelpEngine* _helpEngine, QWidget* parent = 0);
/// Destructor
virtual ~HelpBrowser();
/** \brief re implementation of the load resource function of the text browser
*
* This function loads a resource from the help system. It also handles jumping to
* another namespace via relative links in the url
*
* @param _type Ignored
* @param _name A filename in the help system that should be loaded (image, html document)
* @return The loaded resource
*/
QVariant loadResource ( int _type, const QUrl& _name );
/** \brief Checks if we visited other pages before
*
* @return Did we visit pages before to which we can jump back? (History)
*/
bool isBackwardAvailable();
/** \brief Checks if the back button was pressed and we can go forward to the next page
*
* @return is a page stored in the forward list?
*/
bool isForwardAvailable();
signals:
void urlChanged ( const QUrl& src );
void linkClicked(const QString& _link);
/** \brief This signal is emitted everytime an url is opened
*
* @param _src The new url that is visible in the browser
*/
void urlChanged ( const QUrl& _src );
public slots:
void open(const QUrl& _url);
void open(const QString& _url);
void open(const QUrl& _url, const QString& _str, bool _skipSave = false);
/** \brief Opens a new url from the help system in the browser
*
* @param _url URL that should be opened
* @param _skipSave Flag if the URL should be saved in the history
*/
void open(const QUrl& _url, bool _skipSave = false);
/** \brief Show last page stored in the history
*
*/
void backward();
/** \brief Show next page stored in the history
*
*/
void forward();
private:
/** \brief Extract path from URL
*
* Removes the filename part from the url and returns only the directory component
*
* @param _url Input url
* @return Path
*/
QUrl getCurrentDir(const QUrl& _url);
/** \brief updateNameSpaceAndFolder
*
* This function takes the url and extracts the virtual namespace and
* folder information which are stored in the variables. These variables are used to
* find the corresponding images.
*
* @param _url The url that should be analyzed
*/
void updateNameSpaceAndFolder (const QUrl& _url);
/** \brief Adds a new page to the history
*
* @param _url URL of the new page
*/
void rememberHistory (const QUrl& _url);
/// The help engine the widget is working on
QHelpEngine* helpEngine_;
QStringList visitedPages_;
/// History of the visited pages
QList<QUrl> visitedPages_;
/// Current position in the history
int currentPage_;
/** \brief The currently active virtual folder
*
* QT manages the different help files for the plugins in different virtual folders.
* This variable will always hold the currently active one.
*/
QString currentVirtualFolder_;
/** \brief The currently active namespace
*
* QT manages the different help files for the plugins with different name spaces.
* This variable will always hold the currently active one.
*/
QString currentNameSpace_;
};
......
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