mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
A little refactor for show/hide completion list in the translate box
This commit is contained in:
parent
321756a9c6
commit
a4a4012255
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "extlineedit.hh"
|
||||
#include "wordlist.hh"
|
||||
#include "mutex.hh"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListWidget>
|
||||
|
@ -63,6 +64,7 @@ private:
|
|||
CompletionList * word_list;
|
||||
ExtLineEdit * translate_line;
|
||||
bool m_popupEnabled;
|
||||
Mutex translateBoxMutex;
|
||||
// QCompleter * completer; // disabled for now
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue