mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-18 03:14:06 +00:00
fix: enter event in translate textline (#1158)
* fix: enter event in translate textline * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
dcc4b19b56
commit
19e848ec50
|
@ -2442,6 +2442,8 @@ void MainWindow::setInputLineText( QString text, WildcardPolicy wildcardPolicy,
|
||||||
else {
|
else {
|
||||||
translateBox->setText( text, popupAction == EnablePopup );
|
translateBox->setText( text, popupAction == EnablePopup );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSuggestionList();
|
||||||
GlobalBroadcaster::instance()->translateLineText = text;
|
GlobalBroadcaster::instance()->translateLineText = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ ScanPopup::ScanPopup( QWidget * parent,
|
||||||
definition->installEventFilter( this );
|
definition->installEventFilter( this );
|
||||||
this->installEventFilter( this );
|
this->installEventFilter( this );
|
||||||
|
|
||||||
connect( ui.translateBox->translateLine(), &QLineEdit::textChanged, this, &ScanPopup::translateInputChanged );
|
connect( ui.translateBox->translateLine(), &QLineEdit::textEdited, this, &ScanPopup::translateInputChanged );
|
||||||
|
|
||||||
connect( ui.translateBox, &TranslateBox::returnPressed, this, &ScanPopup::translateInputFinished );
|
connect( ui.translateBox, &TranslateBox::returnPressed, this, &ScanPopup::translateInputFinished );
|
||||||
|
|
||||||
|
@ -694,6 +694,8 @@ void ScanPopup::typingEvent( QString const & t )
|
||||||
ui.translateBox->setText( t, true );
|
ui.translateBox->setText( t, true );
|
||||||
ui.translateBox->translateLine()->setCursorPosition( t.size() );
|
ui.translateBox->translateLine()->setCursorPosition( t.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSuggestionList();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScanPopup::eventFilter( QObject * watched, QEvent * event )
|
bool ScanPopup::eventFilter( QObject * watched, QEvent * event )
|
||||||
|
|
|
@ -50,27 +50,7 @@ TranslateBox::TranslateBox( QWidget * parent ):
|
||||||
completer->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
|
completer->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
|
||||||
completer->setMaxVisibleItems( 16 );
|
completer->setMaxVisibleItems( 16 );
|
||||||
|
|
||||||
connect( completer,
|
connect( translate_line, &QLineEdit::returnPressed, [ this ]() {
|
||||||
QOverload< const QString & >::of( &QCompleter::activated ),
|
|
||||||
translate_line,
|
|
||||||
[ & ]( const QString & text ) {
|
|
||||||
translate_line->setText( text );
|
|
||||||
emit returnPressed();
|
|
||||||
} );
|
|
||||||
|
|
||||||
|
|
||||||
connect( completer,
|
|
||||||
QOverload< const QString & >::of( &QCompleter::highlighted ),
|
|
||||||
translate_line,
|
|
||||||
[ & ]( const QString & text ) {
|
|
||||||
selectedItem = true;
|
|
||||||
} );
|
|
||||||
|
|
||||||
connect( translate_line,
|
|
||||||
&QLineEdit::returnPressed,
|
|
||||||
[ this ]() {
|
|
||||||
if ( selectedItem )
|
|
||||||
return;
|
|
||||||
emit returnPressed();
|
emit returnPressed();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -96,7 +76,7 @@ void TranslateBox::setSizePolicy( QSizePolicy policy )
|
||||||
|
|
||||||
void TranslateBox::setModel( QStringList & _words )
|
void TranslateBox::setModel( QStringList & _words )
|
||||||
{
|
{
|
||||||
disconnect( completer, 0, translate_line, 0 );
|
disconnect( completer, QOverload< const QString & >::of( &QCompleter::activated ), translate_line, nullptr );
|
||||||
const auto model = static_cast< QStringListModel * >( completer->model() );
|
const auto model = static_cast< QStringListModel * >( completer->model() );
|
||||||
|
|
||||||
model->setStringList( _words );
|
model->setStringList( _words );
|
||||||
|
@ -109,13 +89,6 @@ void TranslateBox::setModel( QStringList & _words )
|
||||||
[ & ]( const QString & text ) {
|
[ & ]( const QString & text ) {
|
||||||
translate_line->setText( text );
|
translate_line->setText( text );
|
||||||
emit returnPressed();
|
emit returnPressed();
|
||||||
selectedItem = false;
|
|
||||||
} );
|
|
||||||
connect( completer,
|
|
||||||
QOverload< const QString & >::of( &QCompleter::highlighted ),
|
|
||||||
translate_line,
|
|
||||||
[ & ]( const QString & text ) {
|
|
||||||
selectedItem = true;
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ private slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLineEdit * translate_line;
|
QLineEdit * translate_line;
|
||||||
bool selectedItem = false;
|
|
||||||
bool m_popupEnabled;
|
bool m_popupEnabled;
|
||||||
QCompleter * completer;
|
QCompleter * completer;
|
||||||
QStringList words;
|
QStringList words;
|
||||||
|
|
Loading…
Reference in a new issue