+ 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 */ /* Dictionary query error description string */
.gderrordesc .gderrordesc
{ {

View file

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

View file

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

View file

@ -53,8 +53,11 @@ public:
~ArticleView(); ~ArticleView();
/// Shows the definition of the given word with the given group /// Shows the definition of the given word with the given group.
void showDefinition( QString const & word, unsigned 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, /// Clears the view and sets the application-global waiting cursor,
/// which will be restored when some article loads eventually. /// 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 /// Opens the given link. Supposed to be used in response to
/// openLinkInNewTab() signal. The link scheme is therefore supposed to be /// openLinkInNewTab() signal. The link scheme is therefore supposed to be
/// one of the internal ones. /// 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 /// Goes back in history
void back() void back()
@ -108,9 +112,11 @@ signals:
void pageLoaded(); void pageLoaded();
/// Singals that the following link was requested to be opened in new tab /// 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 /// 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: private slots:
@ -128,6 +134,9 @@ private:
/// returns 0. /// returns 0.
unsigned getGroup( QUrl const & ); 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. /// Attempts removing last temporary file created.
void cleanupTemp(); void cleanupTemp();

View file

@ -493,11 +493,11 @@ ArticleView * MainWindow::createNewTab( bool switchToIt,
connect( view, SIGNAL( pageLoaded() ), this, SLOT( pageLoaded() ) ); connect( view, SIGNAL( pageLoaded() ), this, SLOT( pageLoaded() ) );
connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const & ) ), connect( view, SIGNAL( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ),
this, SLOT( openLinkInNewTab( QUrl const &, QUrl const & ) ) ); this, SLOT( openLinkInNewTab( QUrl const &, QUrl const &, QString const & ) ) );
connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned ) ), connect( view, SIGNAL( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ),
this, SLOT( showDefinitionInNewTab( QString const &, unsigned ) ) ); this, SLOT( showDefinitionInNewTab( QString const &, unsigned, QString const & ) ) );
int index = cfg.preferences.newTabsOpenAfterCurrentOne ? int index = cfg.preferences.newTabsOpenAfterCurrentOne ?
ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count(); ui.tabWidget->currentIndex() + 1 : ui.tabWidget->count();
@ -885,15 +885,19 @@ void MainWindow::wordListSelectionChanged()
} }
void MainWindow::openLinkInNewTab( QUrl const & url, 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, 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 ) void MainWindow::showTranslationFor( QString const & inWord )

View file

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