From a4a4012255e65fadc62dcca6985f7e1f25d852cf Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 8 Sep 2017 16:43:41 +0300 Subject: [PATCH] A little refactor for show/hide completion list in the translate box --- translatebox.cc | 11 +++++++++-- translatebox.hh | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/translatebox.cc b/translatebox.cc index 19f3042d..427a3210 100644 --- a/translatebox.cc +++ b/translatebox.cc @@ -41,7 +41,8 @@ CompletionList::CompletionList(TranslateBox * parent) : WordList(parent), bool CompletionList::eventFilter( QObject * obj, QEvent * ev ) { // when the main window is moved or resized, hide the word list suggestions - if ( ev->type() == QEvent::Move || ev->type() == QEvent::Resize ) + if ( obj != this && !isAncestorOf( qobject_cast< QWidget * >( obj ) ) + && ( ev->type() == QEvent::Move || ev->type() == QEvent::Resize ) ) { translateBox->setPopupEnabled( false ); return false; @@ -244,6 +245,13 @@ void TranslateBox::showPopup() // completer->setCompletionPrefix( m_fileLineEdit->text() ); // qDebug() << "COMPLETION:" << completer->currentCompletion(); + // Don't allow recursive call + if( translateBoxMutex.tryLock() ) + translateBoxMutex.unlock(); + else + return; + Mutex::Lock _( translateBoxMutex ); + if (translate_line->text().trimmed().isEmpty() || word_list->count() == 0) { // nothing to show @@ -252,7 +260,6 @@ void TranslateBox::showPopup() word_list->hide(); translate_line->setFocus(); } - return; } diff --git a/translatebox.hh b/translatebox.hh index 9b87830c..6b823216 100644 --- a/translatebox.hh +++ b/translatebox.hh @@ -6,6 +6,7 @@ #include "extlineedit.hh" #include "wordlist.hh" +#include "mutex.hh" #include #include @@ -63,6 +64,7 @@ private: CompletionList * word_list; ExtLineEdit * translate_line; bool m_popupEnabled; + Mutex translateBoxMutex; // QCompleter * completer; // disabled for now };