mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
fix: when input word in translateline and press Enter
can not type word directly again. fix:#185
This commit is contained in:
parent
75b0a92be7
commit
14c4366839
|
@ -818,10 +818,10 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
|
|||
if( handled )
|
||||
{
|
||||
if( result == Gestures::ZOOM_IN )
|
||||
zoomIn();
|
||||
emit zoomIn();
|
||||
else
|
||||
if( result == Gestures::ZOOM_OUT )
|
||||
zoomOut();
|
||||
emit zoomOut();
|
||||
else
|
||||
if( result == Gestures::SWIPE_LEFT )
|
||||
back();
|
||||
|
@ -881,7 +881,7 @@ bool ArticleView::eventFilter( QObject * obj, QEvent * ev )
|
|||
}
|
||||
}
|
||||
else
|
||||
if ( ev->type() == QEvent::KeyPress || ev->type ()==QEvent::ShortcutOverride)
|
||||
if ( ev->type() == QEvent::KeyPress )
|
||||
{
|
||||
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
||||
|
||||
|
|
|
@ -2476,6 +2476,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
|| ev->type() == QEvent::KeyPress )
|
||||
{
|
||||
QKeyEvent * ke = static_cast<QKeyEvent*>( ev );
|
||||
qDebug()<<obj<<ke->type()<<ke->text();
|
||||
|
||||
// Handle F3/Shift+F3 shortcuts
|
||||
if ( ke->key() == Qt::Key_F3 )
|
||||
|
@ -2582,8 +2583,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
else
|
||||
if ( obj == wordList )
|
||||
{
|
||||
if (ev->type() == QEvent::KeyPress || ev->type() == QEvent::ShortcutOverride)
|
||||
{
|
||||
if ( ev->type() == QEvent::KeyPress ) {
|
||||
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
||||
|
||||
if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) &&
|
||||
|
@ -2607,54 +2607,29 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
|
|||
|
||||
return cfg.preferences.searchInDock;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle typing events used to initiate new lookups
|
||||
// TODO: refactor to eliminate duplication (see below)
|
||||
if ( ev->type() == QEvent::KeyPress && obj != translateLine ) {
|
||||
|
||||
if ( keyEvent->modifiers() &
|
||||
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
|
||||
return false; // A non-typing modifier is pressed
|
||||
if ( const auto key_event = dynamic_cast< QKeyEvent * >(ev); key_event->modifiers() == Qt::NoModifier ) {
|
||||
const QString text = key_event->text();
|
||||
|
||||
if ( Utils::ignoreKeyEvent(keyEvent))
|
||||
if ( Utils::ignoreKeyEvent( key_event ) ||
|
||||
key_event->key() == Qt::Key_Return ||
|
||||
key_event->key() == Qt::Key_Enter )
|
||||
return false; // Those key have other uses than to start typing
|
||||
// or don't make sense
|
||||
|
||||
QString text = keyEvent->text();
|
||||
|
||||
if ( text.size() )
|
||||
{
|
||||
// or don't make sense
|
||||
if ( !text.isEmpty() ) {
|
||||
typingEvent( text );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
if (obj == ui.dictsList) {
|
||||
if ( ev->type() == QEvent::KeyPress || ev->type() == QEvent::ShortcutOverride)
|
||||
{
|
||||
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev );
|
||||
|
||||
// Handle typing events used to initiate new lookups
|
||||
// TODO: refactor to eliminate duplication (see above)
|
||||
|
||||
if ( keyEvent->modifiers() &
|
||||
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
|
||||
return false; // A non-typing modifier is pressed
|
||||
|
||||
if ( Utils::ignoreKeyEvent(keyEvent))
|
||||
return false; // Those key have other uses than to start typing
|
||||
// or don't make sense
|
||||
|
||||
QString text = keyEvent->text();
|
||||
|
||||
if ( text.size() )
|
||||
{
|
||||
typingEvent( text );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return QMainWindow::eventFilter( obj, ev );
|
||||
return QMainWindow::eventFilter( obj, ev );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -2770,13 +2745,12 @@ void MainWindow::typingEvent( QString const & t )
|
|||
if ( ( cfg.preferences.searchInDock && ui.searchPane->isFloating() ) || ui.dictsPane->isFloating() )
|
||||
ui.searchPane->activateWindow();
|
||||
|
||||
if( translateLine->isEnabled() )
|
||||
{
|
||||
translateLine->clear();
|
||||
translateLine->setFocus();
|
||||
// Escaping the typed-in characters is the user's responsibility.
|
||||
// setTranslateBoxTextAndClearSuffix( t, WildcardsAreAlreadyEscaped, EnablePopup );
|
||||
// translateLine->setCursorPosition( t.size() );
|
||||
if ( translateLine->isEnabled() ) {
|
||||
translateLine->clear();
|
||||
translateLine->setFocus();
|
||||
// Escaping the typed-in characters is the user's responsibility.
|
||||
setTranslateBoxTextAndClearSuffix( t, WildcardsAreAlreadyEscaped, EnablePopup );
|
||||
translateLine->setCursorPosition( t.size() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,8 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
ui.translateBox->wordList()->attachFinder( &wordFinder );
|
||||
ui.translateBox->wordList()->setFocusPolicy(Qt::ClickFocus);
|
||||
ui.translateBox->translateLine()->installEventFilter( this );
|
||||
definition->installEventFilter(this);
|
||||
this->installEventFilter(this);
|
||||
|
||||
connect( ui.translateBox->translateLine(), &QLineEdit::textChanged, this, &ScanPopup::translateInputChanged );
|
||||
|
||||
|
@ -736,16 +738,14 @@ vector< sptr< Dictionary::Class > > const & ScanPopup::getActiveDicts()
|
|||
|
||||
void ScanPopup::typingEvent( QString const & t )
|
||||
{
|
||||
if ( t == "\n" || t == "\r" )
|
||||
{
|
||||
if ( t == "\n" || t == "\r" ) {
|
||||
focusTranslateLine();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.translateBox->translateLine()->clear();
|
||||
ui.translateBox->translateLine()->setFocus();
|
||||
// ui.translateBox->setText( t, true );
|
||||
// ui.translateBox->translateLine()->setCursorPosition( t.size() );
|
||||
else {
|
||||
ui.translateBox->translateLine()->clear();
|
||||
ui.translateBox->translateLine()->setFocus();
|
||||
ui.translateBox->setText( t, true );
|
||||
ui.translateBox->translateLine()->setCursorPosition( t.size() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -773,6 +773,24 @@ bool ScanPopup::eventFilter( QObject * watched, QEvent * event )
|
|||
}
|
||||
}
|
||||
|
||||
if ( event->type() == QEvent::KeyPress && watched != ui.translateBox->translateLine() ) {
|
||||
|
||||
if ( const auto key_event = dynamic_cast< QKeyEvent * >(event); key_event->modifiers() == Qt::NoModifier ) {
|
||||
const QString text = key_event->text();
|
||||
|
||||
if ( Utils::ignoreKeyEvent( key_event ) ||
|
||||
key_event->key() == Qt::Key_Return ||
|
||||
key_event->key() == Qt::Key_Enter )
|
||||
return false; // Those key have other uses than to start typing
|
||||
// or don't make sense
|
||||
if ( !text.isEmpty() ) {
|
||||
typingEvent( text );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return QMainWindow::eventFilter( watched, event );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue