Commit 638661f9 authored by Matthias Möller's avatar Matthias Möller
Browse files

help browser tree view selection will be updated if a link to another document is clicked.

Also, it updates the selection if a button (back/forward/home) is pressed


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14365 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 14ef815d
...@@ -75,8 +75,8 @@ void HelpBrowser::updateNameSpaceAndFolder (const QUrl& _url) { ...@@ -75,8 +75,8 @@ void HelpBrowser::updateNameSpaceAndFolder (const QUrl& _url) {
QStringList linkParts = link.split("/"); QStringList linkParts = link.split("/");
if ( linkParts.size() > 3) { if ( linkParts.size() > 3) {
currentNameSpace_ = linkParts[2];
currentVirtualFolder_ = linkParts[3]; currentVirtualFolder_ = linkParts[3];
currentNameSpace_ = QString("org.openflipper.")+ linkParts[3].toLower() ;
} else { } else {
currentNameSpace_ = ""; currentNameSpace_ = "";
currentVirtualFolder_ = ""; currentVirtualFolder_ = "";
...@@ -95,44 +95,48 @@ void HelpBrowser::rememberHistory (const QUrl& _url) { ...@@ -95,44 +95,48 @@ void HelpBrowser::rememberHistory (const QUrl& _url) {
} }
QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) { QUrl HelpBrowser::resolveUrl(const QUrl &_url)
{
if (_url.scheme() == "qthelp") { if (_url.scheme() == "qthelp") {
updateNameSpaceAndFolder(_url); updateNameSpaceAndFolder(_url);
return QVariant(helpEngine_->fileData(_url)); return _url;
} else { } else {
QUrl newUrl; QUrl newUrl;
if ( _url.toString().startsWith("..") ) { if ( _url.toString().startsWith("..") ) {
// Relative url. We jump to a new context, so we first remove the relative part // Relative url. We jump to a new context, so we first remove the relative part
QUrl tmpURL("qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/"); QUrl tmpURL("qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/");
newUrl = tmpURL.resolved(_url); newUrl = tmpURL.resolved(_url);
// Update context // Update context
updateNameSpaceAndFolder(newUrl); updateNameSpaceAndFolder(newUrl);
return newUrl;
} else { } else {
// Normal URL without relative parts so we can safely combine them // Normal URL without relative parts so we can safely combine them
// and stay in the current context // and stay in the current context
newUrl = "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString(); return "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString();
} }
}
}
const QUrl newFileUrl = helpEngine_->findFile(newUrl); QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
if(newFileUrl.isValid()) QUrl newUrl = resolveUrl(_url);
return QVariant(helpEngine_->fileData(newFileUrl)); const QUrl newFileUrl = helpEngine_->findFile(newUrl);
else {
std::cerr << "Unable to find file at url : " << newUrl.toString().toStdString() << std::endl;
return QVariant("Page not Found.");
}
} if(newFileUrl.isValid())
return QVariant(helpEngine_->fileData(newFileUrl));
else {
std::cerr << "Unable to find file at url : " << _url.toString().toStdString() << std::endl;
return QVariant("Page not Found.");
}
} }
...@@ -169,7 +173,7 @@ void HelpBrowser::open(const QUrl& _url, bool _skipSave) { ...@@ -169,7 +173,7 @@ void HelpBrowser::open(const QUrl& _url, bool _skipSave) {
if (Anchor.size() > 1) if (Anchor.size() > 1)
this->scrollToAnchor(Anchor[Anchor.size()-1]); this->scrollToAnchor(Anchor[Anchor.size()-1]);
emit urlChanged ( _url.toString() ); emit sourceChanged( _url );
} }
QUrl HelpBrowser::getCurrentDir(const QUrl& _url) { QUrl HelpBrowser::getCurrentDir(const QUrl& _url) {
......
...@@ -101,12 +101,12 @@ public: ...@@ -101,12 +101,12 @@ public:
*/ */
bool isForwardAvailable(); bool isForwardAvailable();
signals: /** \brief resolves relative urls to absolute
/** \brief This signal is emitted everytime an url is opened *
* * @param _url relative URL which will be resolved
* @param _src The new url that is visible in the browser * @return absolute url
*/ */
void urlChanged ( const QUrl& _src ); QUrl resolveUrl(const QUrl &_url);
public slots: public slots:
......
...@@ -175,7 +175,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite) ...@@ -175,7 +175,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome())); connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));
// Source has been reloaded // Source has been reloaded
connect(textWindow_, SIGNAL(urlChanged(const QUrl&)), this, SLOT(update(const QUrl&))); connect(textWindow_, SIGNAL(sourceChanged(const QUrl&)), this, SLOT(update(const QUrl&)));
// Register documentation // Register documentation
// Seems to be an unneeded call! // Seems to be an unneeded call!
...@@ -220,15 +220,6 @@ void HelpWidget::activateLink(const QUrl& _url) ...@@ -220,15 +220,6 @@ void HelpWidget::activateLink(const QUrl& _url)
{ {
//open and show the url //open and show the url
linkActivated(_url); linkActivated(_url);
//set tree to the right entry
//this is _slow_, so do not use it in function "linkActivated". in "linkActivated" the entry is already selected by the user
helpEngine_->contentWidget()->hide();
QModelIndex modelIndex = helpEngine_->contentWidget()->indexOf(_url);
if (modelIndex.isValid())
helpEngine_->contentWidget()->setCurrentIndex( modelIndex );
helpEngine_->contentWidget()->show();
} }
void HelpWidget::linkActivated(const QUrl& _url) { void HelpWidget::linkActivated(const QUrl& _url) {
...@@ -253,9 +244,19 @@ void HelpWidget::showFoundSite(const QUrl& _url) { ...@@ -253,9 +244,19 @@ void HelpWidget::showFoundSite(const QUrl& _url) {
tabWidget_->setCurrentIndex(homeIndex_); tabWidget_->setCurrentIndex(homeIndex_);
} }
void HelpWidget::update(const QUrl& /* url */) { void HelpWidget::update(const QUrl& _url ) {
updateButtons(); updateButtons();
//search for the entry and select the item in the contentWidget
//in our case, it is the treeView on the left side
QUrl newUrl = textWindow_->resolveUrl(_url);
//search for the selected url
QModelIndex modelIndex = helpEngine_->contentWidget()->indexOf(newUrl);
//select this url in content widget
if (modelIndex.isValid())
helpEngine_->contentWidget()->setCurrentIndex( modelIndex );
} }
void HelpWidget::goForward() { void HelpWidget::goForward() {
......
Supports Markdown
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