Add "Automatically scroll to target article" option

When a user clicks on a link in a dictionary or requests translation of
a word by double-clicking or translates selection via the context menu,
at first the article from the highest-priority dictionary is at the top.
Then, after approximately one second, the article from the dictionary,
out of which the translation was requested, becomes current and the view
scrolls down to this article placing it on top, hiding articles from the
dictionaries above it.

Such application behavior is inconvenient in some workflows so that the
user manually navigates to the top dictionary translation when this
automatic scrolling happens.

For example: a user has English->Russian dictionaries and
English->English dictionaries. The English->Russian dictionaries are
higher up in the dictionary order because they provide easier/faster to
understand translations. Some rare words and phrases are missing from
the English->Russian dictionaries however. Thus the user occasionally
reads the English explanation of a word/phrase. When the user
double-clicks on a word or follows a link in the English->English
dictionary article, she would rather see translations from the
preferable English->Russian dictionaries.

The new option allows to disable automatic scrolling and ensure that
articles from higher-priority dictionaries are visible. The option
doesn't affect backward/forward navigation via arrow buttons or
Alt+Arrow shortcuts: these still scroll to the stored vertical position
among articles. This remaining automatic scrolling happens much faster,
is not a problem for the described use case and hopefully for other use
cases.
This commit is contained in:
Igor Kushnir 2019-01-11 15:50:40 +02:00 committed by yifang
parent cf1f929430
commit d7ec541383
5 changed files with 28 additions and 0 deletions

View file

@ -543,6 +543,7 @@ void ArticleView::loadFinished( bool result )
}
}
else
if( cfg.preferences.autoScrollToTargetArticle )
{
QString const scrollTo = Utils::Url::queryItemValue( url, "scrollto" );
if( isScrollTo( scrollTo ) )

View file

@ -217,6 +217,7 @@ Preferences::Preferences():
autoStart( false ),
doubleClickTranslates( true ),
selectWordBySingleClick( false ),
autoScrollToTargetArticle( true ),
escKeyHidesMainWindow( false ),
alwaysOnTop ( false ),
searchInDock ( false ),
@ -862,6 +863,9 @@ Class load()
if ( !preferences.namedItem( "selectWordBySingleClick" ).isNull() )
c.preferences.selectWordBySingleClick = ( preferences.namedItem( "selectWordBySingleClick" ).toElement().text() == "1" );
if ( !preferences.namedItem( "autoScrollToTargetArticle" ).isNull() )
c.preferences.autoScrollToTargetArticle = ( preferences.namedItem( "autoScrollToTargetArticle" ).toElement().text() == "1" );
if ( !preferences.namedItem( "escKeyHidesMainWindow" ).isNull() )
c.preferences.escKeyHidesMainWindow = ( preferences.namedItem( "escKeyHidesMainWindow" ).toElement().text() == "1" );
@ -1725,6 +1729,10 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.selectWordBySingleClick ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "autoScrollToTargetArticle" );
opt.appendChild( dd.createTextNode( c.preferences.autoScrollToTargetArticle ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "escKeyHidesMainWindow" );
opt.appendChild( dd.createTextNode( c.preferences.escKeyHidesMainWindow ? "1":"0" ) );
preferences.appendChild( opt );

View file

@ -293,6 +293,7 @@ struct Preferences
bool autoStart;
bool doubleClickTranslates;
bool selectWordBySingleClick;
bool autoScrollToTargetArticle;
bool escKeyHidesMainWindow;
bool alwaysOnTop;

View file

@ -169,6 +169,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.cbAutostart->setChecked( p.autoStart );
ui.doubleClickTranslates->setChecked( p.doubleClickTranslates );
ui.selectBySingleClick->setChecked( p.selectWordBySingleClick);
ui.autoScrollToTargetArticle->setChecked( p.autoScrollToTargetArticle );
ui.escKeyHidesMainWindow->setChecked( p.escKeyHidesMainWindow );
ui.enableMainWindowHotkey->setChecked( p.enableMainWindowHotkey );
@ -379,6 +380,7 @@ Config::Preferences Preferences::getPreferences()
p.autoStart = ui.cbAutostart->isChecked();
p.doubleClickTranslates = ui.doubleClickTranslates->isChecked();
p.selectWordBySingleClick = ui.selectBySingleClick->isChecked();
p.autoScrollToTargetArticle = ui.autoScrollToTargetArticle->isChecked();
p.escKeyHidesMainWindow = ui.escKeyHidesMainWindow->isChecked();
p.enableMainWindowHotkey = ui.enableMainWindowHotkey->isChecked();

View file

@ -369,6 +369,22 @@ be the last ones.</string>
</item>
</layout>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="autoScrollToTargetArticle">
<property name="toolTip">
<string>Normally, clicking on a link, double-clicking on a word or looking up
selection in an article loads the translation and almost immediately
scrolls to the article from the same dictionary. With this option off,
however, the article from the topmost dictionary is shown.</string>
</property>
<property name="text">
<string>Automatically scroll to target article</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">