fix regression: select translation line text when got focused (#841)

* fix: select translation line text when got focused

* 🎨 apply clang-format changes

* fix: code smells

---------

Co-authored-by: xiaoyifang <xiaoyifang@users.noreply.github.com>
This commit is contained in:
xiaoyifang 2023-06-10 10:36:59 +08:00 committed by GitHub
parent fe1c609b49
commit 9c1a77a3f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -2507,6 +2507,15 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
}
}
if ( ev->type() == QEvent::FocusIn ) {
// select all on mouse click
if ( const auto focusEvent = dynamic_cast< QFocusEvent * >( ev ); focusEvent->reason() == Qt::MouseFocusReason ) {
QTimer::singleShot( 0, this, SLOT( focusTranslateLine() ) );
}
return false;
}
if ( ev->type() == QEvent::Resize ) {
QResizeEvent * resizeEvent = static_cast< QResizeEvent * >( ev );
groupList->setFixedHeight( resizeEvent->size().height() );

View file

@ -12,6 +12,7 @@
#include <QScrollBar>
#include <QStyle>
#include <QStringListModel>
#include <QTimer>
TranslateBox::TranslateBox( QWidget * parent ):
QWidget( parent ),
@ -49,9 +50,12 @@ TranslateBox::TranslateBox( QWidget * parent ):
completer->setCompletionMode( QCompleter::UnfilteredPopupCompletion );
completer->setMaxVisibleItems( 16 );
connect( completer, QOverload< const QString & >::of( &QCompleter::activated ), this, [ = ]( const QString & text ) {
emit translate_line->returnPressed();
} );
connect( completer,
QOverload< const QString & >::of( &QCompleter::activated ),
translate_line,
[ & ]( const QString & ) {
emit translate_line->returnPressed();
} );
}
void TranslateBox::setText( const QString & text, bool showPopup )