improvement:refactor code ,ignore key event extract to method

This commit is contained in:
yifang 2022-01-13 20:39:58 +08:00
parent d8f5e4a374
commit 9a4b119976
2 changed files with 13 additions and 11 deletions

View file

@ -2634,11 +2634,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) ) ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
return false; // A non-typing modifier is pressed return false; // A non-typing modifier is pressed
if ( keyEvent->key() == Qt::Key_Space || if ( ignoreKeyEvent(keyEvent))
keyEvent->key() == Qt::Key_Backspace ||
keyEvent->key() == Qt::Key_Tab ||
keyEvent->key() == Qt::Key_Backtab ||
keyEvent->key() == Qt::Key_Escape)
return false; // Those key have other uses than to start typing return false; // Those key have other uses than to start typing
// or don't make sense // or don't make sense
@ -2664,11 +2660,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) ) ( Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier ) )
return false; // A non-typing modifier is pressed return false; // A non-typing modifier is pressed
if ( keyEvent->key() == Qt::Key_Space || if ( ignoreKeyEvent(keyEvent))
keyEvent->key() == Qt::Key_Backspace ||
keyEvent->key() == Qt::Key_Tab ||
keyEvent->key() == Qt::Key_Backtab ||
keyEvent->key() == Qt::Key_Escape)
return false; // Those key have other uses than to start typing return false; // Those key have other uses than to start typing
// or don't make sense // or don't make sense
@ -2686,6 +2678,16 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
return false; return false;
} }
bool MainWindow::ignoreKeyEvent(QKeyEvent *keyEvent) {
if ( keyEvent->key() == Qt::Key_Space ||
keyEvent->key() == Qt::Key_Backspace ||
keyEvent->key() == Qt::Key_Tab ||
keyEvent->key() == Qt::Key_Backtab ||
keyEvent->key() == Qt::Key_Escape)
return true;
return false;
}
void MainWindow::wordListItemActivated( QListWidgetItem * item ) void MainWindow::wordListItemActivated( QListWidgetItem * item )
{ {
if( wordListSelChanged ) if( wordListSelChanged )

View file

@ -276,7 +276,7 @@ private:
TranslateBoxPopup popupAction ); TranslateBoxPopup popupAction );
void setTranslateBoxTextAndClearSuffix( QString const & text, WildcardPolicy wildcardPolicy, void setTranslateBoxTextAndClearSuffix( QString const & text, WildcardPolicy wildcardPolicy,
TranslateBoxPopup popupAction ); TranslateBoxPopup popupAction );
bool ignoreKeyEvent(QKeyEvent *keyEvent);
private slots: private slots:
void hotKeyActivated( int ); void hotKeyActivated( int );