mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
+ Allow navigating down to the word list from the translation line and back
by pressing Down or Up keys, respectively. * Pressing Enter on the translation line directly translates what is typed there now, irrespectively of whether there are any word matches or not.
This commit is contained in:
parent
9539e1557d
commit
4a99ce281f
|
@ -72,6 +72,10 @@ public:
|
|||
void forward()
|
||||
{ ui.definition->forward(); }
|
||||
|
||||
/// Takes the focus to the view
|
||||
void focus()
|
||||
{ ui.definition->setFocus( Qt::ShortcutFocusReason ); }
|
||||
|
||||
signals:
|
||||
|
||||
void iconChanged( ArticleView *, QIcon const & icon );
|
||||
|
|
|
@ -127,6 +127,9 @@ MainWindow::MainWindow():
|
|||
connect( &wordFinder, SIGNAL( finished() ),
|
||||
this, SLOT( prefixMatchFinished() ) );
|
||||
|
||||
ui.translateLine->installEventFilter( this );
|
||||
ui.wordList->installEventFilter( this );
|
||||
|
||||
makeDictionaries();
|
||||
|
||||
addNewTab();
|
||||
|
@ -596,8 +599,10 @@ void MainWindow::translateInputChanged( QString const & newValue )
|
|||
|
||||
void MainWindow::translateInputFinished()
|
||||
{
|
||||
if ( ui.wordList->count() )
|
||||
wordListItemActivated( ui.wordList->item( 0 ) );
|
||||
QString word = ui.translateLine->text();
|
||||
|
||||
if ( word.size() )
|
||||
showTranslationFor( word );
|
||||
}
|
||||
|
||||
void MainWindow::prefixMatchUpdated()
|
||||
|
@ -665,6 +670,52 @@ void MainWindow::updateMatchResults( bool finished )
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
||||
{
|
||||
if ( obj == ui.translateLine )
|
||||
{
|
||||
if ( ev->type() == QEvent::KeyPress )
|
||||
{
|
||||
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
||||
|
||||
if ( keyEvent->matches( QKeySequence::MoveToNextLine ) && ui.wordList->count() )
|
||||
{
|
||||
ui.wordList->setFocus( Qt::ShortcutFocusReason );
|
||||
ui.wordList->setCurrentRow( 0, QItemSelectionModel::ClearAndSelect );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if ( obj == ui.wordList )
|
||||
{
|
||||
if ( ev->type() == QEvent::KeyPress )
|
||||
{
|
||||
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
||||
|
||||
if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) &&
|
||||
!ui.wordList->currentRow() )
|
||||
{
|
||||
ui.wordList->setCurrentRow( 0, QItemSelectionModel::Clear );
|
||||
ui.translateLine->setFocus( Qt::ShortcutFocusReason );
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( keyEvent->matches( QKeySequence::InsertParagraphSeparator ) &&
|
||||
ui.wordList->selectedItems().size() )
|
||||
{
|
||||
dynamic_cast< ArticleView & >( *( ui.tabWidget->currentWidget() ) ).focus();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
return QMainWindow::eventFilter( obj, ev );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::wordListItemActivated( QListWidgetItem * item )
|
||||
{
|
||||
showTranslationFor( item->text() );
|
||||
|
|
|
@ -105,6 +105,8 @@ private:
|
|||
|
||||
void updateMatchResults( bool finished );
|
||||
|
||||
virtual bool eventFilter( QObject *, QEvent * );
|
||||
|
||||
/// Returns the reference to dictionaries stored in the currently active
|
||||
/// group, or to all dictionaries if there are no groups.
|
||||
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
||||
|
|
Loading…
Reference in a new issue