+ Navigating away from within any article belonging to some dictionary

will result in scrolling to the same dictionary for newly opened content.
+ Some more css markup was added, in part to accomplish the above, in
  part to make the navigation look better (i.e. have space before article).
This commit is contained in:
Konstantin Isakov 2009-05-11 19:14:28 +00:00
parent dc96e29174
commit 527035f450
6 changed files with 82 additions and 25 deletions

View file

@ -27,6 +27,21 @@ pre
{
}
/* The article span. Here we have a padding/margin hack to make fragment links
behave better (have some space before the start of article) */
.gdarticle
{
display: block;
padding-top: 1px;
margin-top: -9px;
margin-bottom: 8px;
}
/* Appears between the articles */
.gdarticleseparator
{
}
/* Dictionary query error description string */
.gderrordesc
{

View file

@ -330,18 +330,29 @@ void ArticleRequest::bodyFinished()
string head;
string gdFrom = "gdfrom-" + Html::escape( dictId );
if ( closePrevSpan )
{
head += "</span>";
head += "</span><span class=\"gdarticleseparator\"></span>";
closePrevSpan = false;
}
else
{
// This is the first article
head += "<script language=\"JavaScript\">"
"var gdCurrentArticle=\"" + gdFrom + "\";</script>";
}
string jsVal = Html::escapeForJavaScript( dictId );
head += "<script language=\"JavaScript\">var gdArticleContents; "
"if ( !gdArticleContents ) gdArticleContents = \"" + jsVal +" \"; "
"else gdArticleContents += \"" + jsVal + " \";</script>";
head += "<span id=\"gdfrom-" + Html::escape( dictId ) + "\">";
head += "<span class=\"gdarticle\" id=\"" + gdFrom +
"\" onClick=\"gdCurrentArticle='" + gdFrom + "';\""
" onContextMenu=\"gdCurrentArticle='" + gdFrom + "';\""
+ ">";
closePrevSpan = true;

View file

@ -80,7 +80,8 @@ ArticleView::~ArticleView()
#endif
}
void ArticleView::showDefinition( QString const & word, unsigned group )
void ArticleView::showDefinition( QString const & word, unsigned group,
QString const & scrollTo )
{
QUrl req;
@ -89,6 +90,9 @@ void ArticleView::showDefinition( QString const & word, unsigned group )
req.addQueryItem( "word", word );
req.addQueryItem( "group", QString::number( group ) );
if ( scrollTo.size() )
req.setFragment( scrollTo );
ui.definition->load( req );
//QApplication::setOverrideCursor( Qt::WaitCursor );
ui.definition->setCursor( Qt::WaitCursor );
@ -145,6 +149,17 @@ unsigned ArticleView::getGroup( QUrl const & url )
return 0;
}
QString ArticleView::getCurrentArticle()
{
QVariant v = ui.definition->page()->currentFrame()->evaluateJavaScript(
QString( "gdCurrentArticle;" ) );
if ( v.type() == QVariant::String )
return v.toString();
else
return QString();
}
void ArticleView::cleanupTemp()
{
if ( desktopOpenedTempFile.size() )
@ -157,10 +172,11 @@ void ArticleView::cleanupTemp()
void ArticleView::linkClicked( QUrl const & url )
{
openLink( url, ui.definition->url() );
openLink( url, ui.definition->url(), getCurrentArticle() );
}
void ArticleView::openLink( QUrl const & url, QUrl const & ref )
void ArticleView::openLink( QUrl const & url, QUrl const & ref,
QString const & scrollTo )
{
printf( "clicked %s\n", url.toString().toLocal8Bit().data() );
@ -168,7 +184,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
showDefinition( ( url.host().startsWith( "xn--" ) ?
QUrl::fromPunycode( url.host().toLatin1() ) :
url.host() ) + url.path(),
getGroup( ref ) );
getGroup( ref ), scrollTo );
else
if ( url.scheme() == "gdlookup" ) // Plain html links inherit gdlookup scheme
{
@ -179,7 +195,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref )
}
else
showDefinition( url.path().mid( 1 ),
getGroup( ref ) );
getGroup( ref ), scrollTo );
}
else
if ( url.scheme() == "bres" || url.scheme() == "gdau" )
@ -425,13 +441,14 @@ void ArticleView::contextMenuRequested( QPoint const & pos )
linkClicked( r.linkUrl() );
else
if ( result == lookupSelection )
showDefinition( selectedText, getGroup( ui.definition->url() ) );
showDefinition( selectedText, getGroup( ui.definition->url() ), getCurrentArticle() );
else
if ( !popupView && result == followLinkNewTab )
emit openLinkInNewTab( r.linkUrl(), ui.definition->url() );
emit openLinkInNewTab( r.linkUrl(), ui.definition->url(), getCurrentArticle() );
else
if ( !popupView && result == lookupSelectionNewTab )
emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ) );
emit showDefinitionInNewTab( selectedText, getGroup( ui.definition->url() ),
getCurrentArticle() );
else
{
// Match against table of contents

View file

@ -53,8 +53,11 @@ public:
~ArticleView();
/// Shows the definition of the given word with the given group
void showDefinition( QString const & word, unsigned group );
/// Shows the definition of the given word with the given group.
/// scrollTo can be optionally set to a "gdfrom-xxxx" identifier to position
/// the page to that article on load.
void showDefinition( QString const & word, unsigned group,
QString const & scrollTo = QString() );
/// Clears the view and sets the application-global waiting cursor,
/// which will be restored when some article loads eventually.
@ -63,7 +66,8 @@ public:
/// Opens the given link. Supposed to be used in response to
/// openLinkInNewTab() signal. The link scheme is therefore supposed to be
/// one of the internal ones.
void openLink( QUrl const & url, QUrl const & referrer );
void openLink( QUrl const & url, QUrl const & referrer,
QString const & scrollTo = QString() );
/// Goes back in history
void back()
@ -108,9 +112,11 @@ signals:
void pageLoaded();
/// Singals that the following link was requested to be opened in new tab
void openLinkInNewTab( QUrl const &, QUrl const & referrer );
void openLinkInNewTab( QUrl const &, QUrl const & referrer,
QString const & fromArticle );
/// Singals that the following definition was requested to be showed in new tab
void showDefinitionInNewTab( QString const & word, unsigned group );
void showDefinitionInNewTab( QString const & word, unsigned group,
QString const & fromArticle );
private slots:
@ -128,6 +134,9 @@ private:
/// returns 0.
unsigned getGroup( QUrl const & );
/// Returns current article in the view, in the form of "gdform-xxx" id.
QString getCurrentArticle();
/// Attempts removing last temporary file created.
void cleanupTemp();

View file

@ -493,11 +493,11 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
connect( view, SIGNAL( pageLoaded() ), this, SLOT( pageLoaded() ) );
connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const & ) ),
this, SLOT( openLinkInNewTab( QUrl const &, QUrl const & ) ) );
connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ),
this, SLOT( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ) );
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned ) ),
this, SLOT( showDefinitionInNewTab( QString const &, unsigned ) ) );
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
this, SLOT( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ) );
int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
@ -885,15 +885,19 @@ void MainWindow::wordListSelectionChanged()
}
void MainWindow::openLinkInNewTab( QUrl const & url,
QUrl const & referrer )
QUrl const & referrer,
QString const & fromArticle )
{
createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->openLink( url, referrer );
createNewTab( !cfg.preferences.newTabsOpenInBackground, "" )->
openLink( url, referrer, fromArticle );
}
void MainWindow::showDefinitionInNewTab( QString const & word,
unsigned group )
unsigned group,
QString const & fromArticle )
{
createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->showDefinition( word, group );
createNewTab( !cfg.preferences.newTabsOpenInBackground, word )->
showDefinition( word, group, fromArticle );
}
void MainWindow::showTranslationFor( QString const & inWord )

View file

@ -176,8 +176,9 @@ private slots:
ArticleView * createNewTab( bool switchToIt,
QString const & name );
void openLinkInNewTab( QUrl const &, QUrl const & );
void showDefinitionInNewTab( QString const & word, unsigned group );
void openLinkInNewTab( QUrl const &, QUrl const &, QString const & );
void showDefinitionInNewTab( QString const & word, unsigned group,
QString const & fromArticle );
void showTranslationFor( QString const & );