Merge pull request #1010 from xiaoyifang/fix/shortcut-navigation

fix: shortcut navigation through dictionary and page
This commit is contained in:
xiaoyifang 2023-07-27 10:34:57 +08:00 committed by GitHub
commit fe5a329056
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 14 deletions

View file

@ -447,6 +447,13 @@ void ArticleView::loadFinished( bool result )
if ( isScrollTo( scrollTo ) ) {
setCurrentArticle( scrollTo, true );
}
else {
setActiveArticleId( "" );
}
}
else {
//clear current active dictionary id;
setActiveArticleId( "" );
}
webview->unsetCursor();
@ -1886,8 +1893,7 @@ void ArticleView::moveOneArticleUp()
void ArticleView::moveOneArticleDown()
{
QString current = getCurrentArticle();
QString currentDictId = dictionaryIdFromScrollTo( current );
QString currentDictId = getActiveArticleId();
QStringList lst = getArticlesList();
// if current article is empty .use the first as default.
if ( currentDictId.isEmpty() && !lst.isEmpty() ) {

View file

@ -1,6 +1,7 @@
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include <Qt>
#include <QScopeGuard>
#ifndef NO_EPWING_SUPPORT
#include "dict/epwing_book.hh"
@ -2477,16 +2478,19 @@ bool MainWindow::handleBackForwardMouseButtons( QMouseEvent * event )
bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
{
if ( ev->type() == QEvent::ShortcutOverride || ev->type() == QEvent::KeyPress ) {
QKeyEvent * ke = static_cast< QKeyEvent * >( ev );
QKeyEvent * ke = dynamic_cast< QKeyEvent * >( ev );
// Handle F3/Shift+F3 shortcuts
if ( ke->key() == Qt::Key_F3 ) {
int const key = ke->key();
if ( key == Qt::Key_F3 ) {
ArticleView * view = getCurrentArticleView();
if ( view && view->handleF3( obj, ev ) )
return true;
}
//workaround to fix #660
if ( obj == this && ev->type() == QEvent::KeyPress && ( ke->key() == Qt::Key_Up || ke->key() == Qt::Key_Down ) ) {
if ( obj == this && ev->type() == QEvent::KeyPress
&& ( key == Qt::Key_Up || key == Qt::Key_Down || key == Qt::Key_Space || key == Qt::Key_PageUp
|| key == Qt::Key_PageDown ) ) {
ArticleView * view = getCurrentArticleView();
if ( view ) {
view->focus();
@ -2504,12 +2508,12 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
}
if ( obj == this && ev->type() == QEvent::WindowStateChange ) {
QWindowStateChangeEvent * stev = static_cast< QWindowStateChangeEvent * >( ev );
auto stev = dynamic_cast< QWindowStateChangeEvent * >( ev );
wasMaximized = ( stev->oldState() == Qt::WindowMaximized && isMinimized() );
}
if ( ev->type() == QEvent::MouseButtonPress ) {
QMouseEvent * event = static_cast< QMouseEvent * >( ev );
auto event = static_cast< QMouseEvent * >( ev );
return handleBackForwardMouseButtons( event );
}
@ -2517,7 +2521,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
if ( ev->type() == QEvent::KeyPress ) {
auto keyevent = dynamic_cast< QKeyEvent * >( ev );
bool handleCtrlTab = ( obj == translateLine || obj == ui.wordList || obj == ui.historyList
bool const handleCtrlTab = ( obj == translateLine || obj == ui.wordList || obj == ui.historyList
|| obj == ui.favoritesTree || obj == ui.dictsList || obj == groupList );
if ( keyevent->modifiers() == Qt::ControlModifier && keyevent->key() == Qt::Key_Tab ) {
@ -2531,11 +2535,9 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
}
return false;
}
if ( handleCtrlTab
&& keyevent->matches(
QKeySequence::
PreviousChild ) ) // Handle only Ctrl+Shist+Tab here because Ctrl+Tab was already handled before
{
// Handle only Ctrl+Shift+Tab here because Ctrl+Tab was already handled before
if ( handleCtrlTab && keyevent->matches( QKeySequence::PreviousChild ) ) {
QApplication::sendEvent( ui.tabWidget, ev );
return true;
}