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

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) {
QStringList linkParts = link.split("/");
if ( linkParts.size() > 3) {
currentNameSpace_ = linkParts[2];
currentVirtualFolder_ = linkParts[3];
currentNameSpace_ = QString("org.openflipper.")+ linkParts[3].toLower() ;
} else {
currentNameSpace_ = "";
currentVirtualFolder_ = "";
......@@ -95,44 +95,48 @@ void HelpBrowser::rememberHistory (const QUrl& _url) {
}
QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
if (_url.scheme() == "qthelp") {
QUrl HelpBrowser::resolveUrl(const QUrl &_url)
{
if (_url.scheme() == "qthelp") {
updateNameSpaceAndFolder(_url);
return QVariant(helpEngine_->fileData(_url));
updateNameSpaceAndFolder(_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
QUrl tmpURL("qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/");
newUrl = tmpURL.resolved(_url);
// 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);
// Update context
updateNameSpaceAndFolder(newUrl);
return newUrl;
} else {
} else {
// Normal URL without relative parts so we can safely combine them
// and stay in the current context
newUrl = "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString();
// Normal URL without relative parts so we can safely combine them
// and stay in the current context
return "qthelp://" + currentNameSpace_ + "/" + currentVirtualFolder_ + "/" + _url.toString();
}
}
}
}
const QUrl newFileUrl = helpEngine_->findFile(newUrl);
QVariant HelpBrowser::loadResource (int /*_type*/, const QUrl& _url) {
if(newFileUrl.isValid())
return QVariant(helpEngine_->fileData(newFileUrl));
else {
std::cerr << "Unable to find file at url : " << newUrl.toString().toStdString() << std::endl;
return QVariant("Page not Found.");
}
QUrl newUrl = resolveUrl(_url);
const QUrl newFileUrl = helpEngine_->findFile(newUrl);
}
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) {
if (Anchor.size() > 1)
this->scrollToAnchor(Anchor[Anchor.size()-1]);
emit urlChanged ( _url.toString() );
emit sourceChanged( _url );
}
QUrl HelpBrowser::getCurrentDir(const QUrl& _url) {
......
......@@ -101,12 +101,12 @@ public:
*/
bool isForwardAvailable();
signals:
/** \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 );
/** \brief resolves relative urls to absolute
*
* @param _url relative URL which will be resolved
* @return absolute url
*/
QUrl resolveUrl(const QUrl &_url);
public slots:
......
......@@ -175,7 +175,7 @@ HelpWidget::HelpWidget(QWidget* parent, const QString& _homeSite)
connect(homeButton_, SIGNAL(clicked()), this, SLOT(goHome()));
// 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
// Seems to be an unneeded call!
......@@ -220,15 +220,6 @@ void HelpWidget::activateLink(const QUrl& _url)
{
//open and show the 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) {
......@@ -253,9 +244,19 @@ void HelpWidget::showFoundSite(const QUrl& _url) {
tabWidget_->setCurrentIndex(homeIndex_);
}
void HelpWidget::update(const QUrl& /* url */) {
void HelpWidget::update(const QUrl& _url ) {
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() {
......
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