mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +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 )
|
bool CompletionList::eventFilter( QObject * obj, QEvent * ev )
|
||||||
{
|
{
|
||||||
// when the main window is moved or resized, hide the word list suggestions
|
// 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 );
|
translateBox->setPopupEnabled( false );
|
||||||
return false;
|
return false;
|
||||||
|
@ -244,6 +245,13 @@ void TranslateBox::showPopup()
|
||||||
// completer->setCompletionPrefix( m_fileLineEdit->text() );
|
// completer->setCompletionPrefix( m_fileLineEdit->text() );
|
||||||
// qDebug() << "COMPLETION:" << completer->currentCompletion();
|
// 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)
|
if (translate_line->text().trimmed().isEmpty() || word_list->count() == 0)
|
||||||
{
|
{
|
||||||
// nothing to show
|
// nothing to show
|
||||||
|
@ -252,7 +260,6 @@ void TranslateBox::showPopup()
|
||||||
word_list->hide();
|
word_list->hide();
|
||||||
translate_line->setFocus();
|
translate_line->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "extlineedit.hh"
|
#include "extlineedit.hh"
|
||||||
#include "wordlist.hh"
|
#include "wordlist.hh"
|
||||||
|
#include "mutex.hh"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QListWidget>
|
#include <QListWidget>
|
||||||
|
@ -63,6 +64,7 @@ private:
|
||||||
CompletionList * word_list;
|
CompletionList * word_list;
|
||||||
ExtLineEdit * translate_line;
|
ExtLineEdit * translate_line;
|
||||||
bool m_popupEnabled;
|
bool m_popupEnabled;
|
||||||
|
Mutex translateBoxMutex;
|
||||||
// QCompleter * completer; // disabled for now
|
// QCompleter * completer; // disabled for now
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue