ssearch:indent, log messages etc.

This commit is contained in:
Jean-Francois Dockes 2018-11-24 17:25:52 +01:00
parent a193412fa1
commit 4d6ad4c3ea

View File

@ -65,13 +65,14 @@ void SSearch::init()
queryText->addItems(prefs.ssearchHistory); queryText->addItems(prefs.ssearchHistory);
queryText->setEditText(""); queryText->setEditText("");
connect(queryText->lineEdit(), SIGNAL(returnPressed()), connect(queryText->lineEdit(), SIGNAL(returnPressed()),
this, SLOT(startSimpleSearch())); this, SLOT(startSimpleSearch()));
connect(queryText->lineEdit(), SIGNAL(textChanged(const QString&)), connect(queryText->lineEdit(), SIGNAL(textChanged(const QString&)),
this, SLOT(searchTextChanged(const QString&))); this, SLOT(searchTextChanged(const QString&)));
connect(clearqPB, SIGNAL(clicked()), connect(clearqPB, SIGNAL(clicked()),
queryText->lineEdit(), SLOT(clear())); queryText->lineEdit(), SLOT(clear()));
connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch())); connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch()));
connect(searchTypCMB, SIGNAL(activated(int)), this, SLOT(searchTypeChanged(int))); connect(searchTypCMB, SIGNAL(activated(int)), this,
SLOT(searchTypeChanged(int)));
queryText->installEventFilter(this); queryText->installEventFilter(this);
queryText->view()->installEventFilter(this); queryText->view()->installEventFilter(this);
@ -81,7 +82,7 @@ void SSearch::init()
// But the model does not belong to the completer so it's not deleted... // But the model does not belong to the completer so it's not deleted...
m_savedModel = queryText->completer()->model(); m_savedModel = queryText->completer()->model();
if (prefs.ssearchNoComplete) if (prefs.ssearchNoComplete)
queryText->completer()->setModel(0); queryText->completer()->setModel(0);
// Recoll searches are always case-sensitive because of the use of // Recoll searches are always case-sensitive because of the use of
// capitalization to suppress stemming // capitalization to suppress stemming
queryText->completer()->setCaseSensitivity(Qt::CaseSensitive); queryText->completer()->setCaseSensitivity(Qt::CaseSensitive);
@ -96,7 +97,7 @@ void SSearch::init()
void SSearch::takeFocus() void SSearch::takeFocus()
{ {
LOGDEB2("SSearch: take focus\n" ); LOGDEB2("SSearch: take focus\n");
queryText->setFocus(Qt::ShortcutFocusReason); queryText->setFocus(Qt::ShortcutFocusReason);
// If the focus was already in the search entry, the text is not selected. // If the focus was already in the search entry, the text is not selected.
// Do it for consistency // Do it for consistency
@ -106,58 +107,61 @@ void SSearch::takeFocus()
void SSearch::timerDone() void SSearch::timerDone()
{ {
QString qs = queryText->currentText(); QString qs = queryText->currentText();
LOGDEB1("SSearch::timerDone: qs [" << (qs2utf8s(qs)) << "]\n" ); LOGDEB1("SSearch::timerDone: qs [" << qs2utf8s(qs) << "]\n");
searchTextChanged(qs); searchTextChanged(qs);
} }
void SSearch::searchTextChanged(const QString& text) void SSearch::searchTextChanged(const QString& text)
{ {
QString qs = queryText->currentText(); QString qs = queryText->currentText();
LOGDEB1("SSearch::searchTextChanged. ks " << (m_keystroke) << " qs [" << (qs2utf8s(text)) << "]\n" ); LOGDEB1("SSearch::searchTextChanged. ks " << m_keystroke << " qs [" <<
qs2utf8s(text) << "]\n");
if (text.isEmpty()) { if (text.isEmpty()) {
searchPB->setEnabled(false); searchPB->setEnabled(false);
clearqPB->setEnabled(false); clearqPB->setEnabled(false);
queryText->setFocus(); queryText->setFocus();
emit clearSearch(); emit clearSearch();
} else { } else {
searchPB->setEnabled(true); searchPB->setEnabled(true);
clearqPB->setEnabled(true); clearqPB->setEnabled(true);
if (m_keystroke) { if (m_keystroke) {
m_tstartqs = qs; m_tstartqs = qs;
} }
if (prefs.ssearchAsYouType && !m_disableAutosearch && if (prefs.ssearchAsYouType && !m_disableAutosearch &&
!m_keystroke && m_tstartqs == qs) { !m_keystroke && m_tstartqs == qs) {
m_disableAutosearch = true; m_disableAutosearch = true;
string s; string s;
int cs = partialWord(s); int cs = partialWord(s);
LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << (cs) << " s [" << (s) << "]\n" ); LOGDEB1("SSearch::searchTextChanged: autosearch. cs " << cs <<
if (cs < 0) { " s [" << s << "]\n");
startSimpleSearch(); if (cs < 0) {
} else if (!m_stroketimeout->isActive() && s.size() >= 2) { startSimpleSearch();
s = qs2utf8s(queryText->currentText()); } else if (!m_stroketimeout->isActive() && s.size() >= 2) {
s += "*"; s = qs2utf8s(queryText->currentText());
startSimpleSearch(s, 20); s += "*";
} startSimpleSearch(s, 20);
} }
}
} }
m_keystroke = false; m_keystroke = false;
} }
void SSearch::searchTypeChanged(int typ) void SSearch::searchTypeChanged(int typ)
{ {
LOGDEB("Search type now " << (typ) << "\n" ); LOGDEB("Search type now " << typ << "\n");
// Adjust context help // Adjust context help
if (typ == SST_LANG) if (typ == SST_LANG) {
HelpClient::installMap((const char *)this->objectName().toUtf8(), HelpClient::installMap((const char *)this->objectName().toUtf8(),
"RCL.SEARCH.LANG"); "RCL.SEARCH.LANG");
else } else {
HelpClient::installMap((const char *)this->objectName().toUtf8(), HelpClient::installMap((const char *)this->objectName().toUtf8(),
"RCL.SEARCH.GUI.SIMPLE"); "RCL.SEARCH.GUI.SIMPLE");
}
// Also fix tooltips // Also fix tooltips
switch (typ) { switch (typ) {
case SST_LANG: case SST_LANG:
queryText->setToolTip(tr( queryText->setToolTip(
tr(
"Enter query language expression. Cheat sheet:<br>\n" "Enter query language expression. Cheat sheet:<br>\n"
"<i>term1 term2</i> : 'term1' and 'term2' in any field.<br>\n" "<i>term1 term2</i> : 'term1' and 'term2' in any field.<br>\n"
"<i>field:term1</i> : 'term1' in field 'field'.<br>\n" "<i>field:term1</i> : 'term1' in field 'field'.<br>\n"
@ -170,7 +174,7 @@ void SSearch::searchTypeChanged(int typ)
"<i>\"term1 term2\"</i> : phrase (must occur exactly). Possible modifiers:<br>\n" "<i>\"term1 term2\"</i> : phrase (must occur exactly). Possible modifiers:<br>\n"
"<i>\"term1 term2\"p</i> : unordered proximity search with default distance.<br>\n" "<i>\"term1 term2\"p</i> : unordered proximity search with default distance.<br>\n"
"Use <b>Show Query</b> link when in doubt about result and see manual (&lt;F1>) for more detail.\n" "Use <b>Show Query</b> link when in doubt about result and see manual (&lt;F1>) for more detail.\n"
)); ));
break; break;
case SST_FNM: case SST_FNM:
queryText->setToolTip(tr("Enter file name wildcard expression.")); queryText->setToolTip(tr("Enter file name wildcard expression."));
@ -178,29 +182,30 @@ void SSearch::searchTypeChanged(int typ)
case SST_ANY: case SST_ANY:
case SST_ALL: case SST_ALL:
default: default:
queryText->setToolTip(tr( queryText->setToolTip(
"Enter search terms here. Type ESC SPC for completions of current term." tr(
)); "Enter search terms here. Type ESC SPC for completions of current term."
));
} }
} }
void SSearch::startSimpleSearch() void SSearch::startSimpleSearch()
{ {
QString qs = queryText->currentText(); QString qs = queryText->currentText();
LOGDEB("SSearch::startSimpleSearch(): qs [" << (qs2utf8s(qs)) << "]\n" ); LOGDEB("SSearch::startSimpleSearch(): qs [" << qs2utf8s(qs) << "]\n");
if (qs.length() == 0) if (qs.length() == 0)
return; return;
string u8 = (const char *)queryText->currentText().toUtf8(); string u8 = (const char *)queryText->currentText().toUtf8();
trimstring(u8); trimstring(u8);
if (u8.length() == 0) if (u8.length() == 0)
return; return;
if (!startSimpleSearch(u8)) if (!startSimpleSearch(u8))
return; return;
LOGDEB("startSimpleSearch: updating history\n" ); LOGDEB("startSimpleSearch: updating history\n");
// Search terms history: // Search terms history:
// We want to have the new text at the top and any older identical // We want to have the new text at the top and any older identical
// entry to be erased. There is no standard qt policy to do this ? // entry to be erased. There is no standard qt policy to do this ?
@ -209,11 +214,11 @@ void SSearch::startSimpleSearch()
QString txtt = txt.trimmed(); QString txtt = txt.trimmed();
int index = queryText->findText(txtt); int index = queryText->findText(txtt);
if (index > 0) { if (index > 0) {
queryText->removeItem(index); queryText->removeItem(index);
} }
if (index != 0) { if (index != 0) {
queryText->insertItem(0, txtt); queryText->insertItem(0, txtt);
queryText->setEditText(txt); queryText->setEditText(txt);
} }
m_disableAutosearch = true; m_disableAutosearch = true;
m_stroketimeout->stop(); m_stroketimeout->stop();
@ -222,15 +227,15 @@ void SSearch::startSimpleSearch()
// go to disk) // go to disk)
prefs.ssearchHistory.clear(); prefs.ssearchHistory.clear();
for (int index = 0; index < queryText->count(); index++) { for (int index = 0; index < queryText->count(); index++) {
prefs.ssearchHistory.push_back(queryText->itemText(index)); prefs.ssearchHistory.push_back(queryText->itemText(index));
} }
} }
void SSearch::setPrefs() void SSearch::setPrefs()
{ {
if (prefs.ssearchNoComplete) { if (prefs.ssearchNoComplete) {
queryText->completer()->setModel(0); queryText->completer()->setModel(0);
} else { } else {
queryText->completer()->setModel(m_savedModel); queryText->completer()->setModel(m_savedModel);
} }
} }
@ -241,7 +246,7 @@ string SSearch::asXML()
bool SSearch::startSimpleSearch(const string& u8, int maxexp) bool SSearch::startSimpleSearch(const string& u8, int maxexp)
{ {
LOGDEB("SSearch::startSimpleSearch(" << (u8) << ")\n" ); LOGDEB("SSearch::startSimpleSearch(" << u8 << ")\n");
string stemlang = prefs.stemlang(); string stemlang = prefs.stemlang();
ostringstream xml; ostringstream xml;
@ -254,51 +259,51 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
if (tp == SST_LANG) { if (tp == SST_LANG) {
xml << " <SM>QL</SM>\n"; xml << " <SM>QL</SM>\n";
string reason; string reason;
if (prefs.autoSuffsEnable) { if (prefs.autoSuffsEnable) {
sdata = wasaStringToRcl(theconfig, stemlang, u8, reason, sdata = wasaStringToRcl(theconfig, stemlang, u8, reason,
(const char *)prefs.autoSuffs.toUtf8()); (const char *)prefs.autoSuffs.toUtf8());
if (!prefs.autoSuffs.isEmpty()) { if (!prefs.autoSuffs.isEmpty()) {
xml << " <AS>" << qs2utf8s(prefs.autoSuffs) << "</AS>\n"; xml << " <AS>" << qs2utf8s(prefs.autoSuffs) << "</AS>\n";
} }
} else { } else {
sdata = wasaStringToRcl(theconfig, stemlang, u8, reason); sdata = wasaStringToRcl(theconfig, stemlang, u8, reason);
} }
if (sdata == 0) { if (sdata == 0) {
QMessageBox::warning(0, "Recoll", tr("Bad query string") + ": " + QMessageBox::warning(0, "Recoll", tr("Bad query string") + ": " +
QString::fromUtf8(reason.c_str())); QString::fromUtf8(reason.c_str()));
return false; return false;
} }
} else { } else {
sdata = new Rcl::SearchData(Rcl::SCLT_OR, stemlang); sdata = new Rcl::SearchData(Rcl::SCLT_OR, stemlang);
if (sdata == 0) { if (sdata == 0) {
QMessageBox::warning(0, "Recoll", tr("Out of memory")); QMessageBox::warning(0, "Recoll", tr("Out of memory"));
return false; return false;
} }
Rcl::SearchDataClause *clp = 0; Rcl::SearchDataClause *clp = 0;
if (tp == SST_FNM) { if (tp == SST_FNM) {
xml << " <SM>FN</SM>\n"; xml << " <SM>FN</SM>\n";
clp = new Rcl::SearchDataClauseFilename(u8); clp = new Rcl::SearchDataClauseFilename(u8);
} else { } else {
// ANY or ALL, several words. // ANY or ALL, several words.
if (tp == SST_ANY) { if (tp == SST_ANY) {
xml << " <SM>OR</SM>\n"; xml << " <SM>OR</SM>\n";
clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8); clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_OR, u8);
} else { } else {
xml << " <SM>AND</SM>\n"; xml << " <SM>AND</SM>\n";
clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8); clp = new Rcl::SearchDataClauseSimple(Rcl::SCLT_AND, u8);
} }
} }
sdata->addClause(clp); sdata->addClause(clp);
} }
if (prefs.ssearchAutoPhrase && rcldb) { if (prefs.ssearchAutoPhrase && rcldb) {
xml << " <AP/>\n"; xml << " <AP/>\n";
sdata->maybeAddAutoPhrase(*rcldb, sdata->maybeAddAutoPhrase(*rcldb,
prefs.ssearchAutoPhraseThreshPC / 100.0); prefs.ssearchAutoPhraseThreshPC / 100.0);
} }
if (maxexp != -1) { if (maxexp != -1) {
sdata->setMaxExpand(maxexp); sdata->setMaxExpand(maxexp);
} }
for (const auto& dbdir : prefs.activeExtraDbs) { for (const auto& dbdir : prefs.activeExtraDbs) {
@ -307,7 +312,7 @@ bool SSearch::startSimpleSearch(const string& u8, int maxexp)
xml << "</SD>\n"; xml << "</SD>\n";
m_xml = xml.str(); m_xml = xml.str();
LOGDEB("SSearch::startSimpleSearch:xml:[" << (m_xml) << "]\n" ); LOGDEB("SSearch::startSimpleSearch:xml:[" << m_xml << "]\n");
std::shared_ptr<Rcl::SearchData> rsdata(sdata); std::shared_ptr<Rcl::SearchData> rsdata(sdata);
emit startSearch(rsdata, true); emit startSearch(rsdata, true);
@ -393,17 +398,17 @@ bool SSearch::hasSearchString()
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r"; static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void SSearch::addTerm(QString term) void SSearch::addTerm(QString term)
{ {
LOGDEB("SSearch::AddTerm: [" << ((const char *)term.toUtf8()) << "]\n" ); LOGDEB("SSearch::AddTerm: [" << qs2utf8s(term) << "]\n");
string t = (const char *)term.toUtf8(); string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct); string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos) if (pos == string::npos)
return; return;
t = t.substr(0, pos+1); t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct); pos = t.find_first_not_of(punct);
if (pos != string::npos) if (pos != string::npos)
t = t.substr(pos); t = t.substr(pos);
if (t.empty()) if (t.empty())
return; return;
term = QString::fromUtf8(t.c_str()); term = QString::fromUtf8(t.c_str());
QString text = queryText->currentText(); QString text = queryText->currentText();
@ -415,7 +420,8 @@ void SSearch::addTerm(QString term)
void SSearch::onWordReplace(const QString& o, const QString& n) void SSearch::onWordReplace(const QString& o, const QString& n)
{ {
LOGDEB("SSearch::onWordReplace: o [" << (qs2utf8s(o)) << "] n [" << (qs2utf8s(n)) << "]\n" ); LOGDEB("SSearch::onWordReplace: o [" << qs2utf8s(o) << "] n [" <<
qs2utf8s(n) << "]\n");
QString txt = queryText->currentText(); QString txt = queryText->currentText();
QRegExp exp = QRegExp(QString("\\b") + o + QString("\\b")); QRegExp exp = QRegExp(QString("\\b") + o + QString("\\b"));
exp.setCaseSensitivity(Qt::CaseInsensitive); exp.setCaseSensitivity(Qt::CaseInsensitive);
@ -425,7 +431,7 @@ void SSearch::onWordReplace(const QString& o, const QString& n)
m_stroketimeout->stop(); m_stroketimeout->stop();
Qt::KeyboardModifiers mods = QApplication::keyboardModifiers (); Qt::KeyboardModifiers mods = QApplication::keyboardModifiers ();
if (mods == Qt::NoModifier) if (mods == Qt::NoModifier)
startSimpleSearch(); startSimpleSearch();
} }
void SSearch::setAnyTermMode() void SSearch::setAnyTermMode()
@ -441,11 +447,11 @@ int SSearch::partialWord(string& s)
QString txt = queryText->currentText(); QString txt = queryText->currentText();
int cs = txt.lastIndexOf(" "); int cs = txt.lastIndexOf(" ");
if (cs == -1) if (cs == -1)
cs = 0; cs = 0;
else else
cs++; cs++;
if (txt.size() == 0 || cs == txt.size()) { if (txt.size() == 0 || cs == txt.size()) {
return -1; return -1;
} }
s = qs2utf8s(txt.right(txt.size() - cs)); s = qs2utf8s(txt.right(txt.size() - cs));
return cs; return cs;
@ -456,19 +462,18 @@ int SSearch::partialWord(string& s)
int SSearch::completionList(string s, QStringList& lst, int max) int SSearch::completionList(string s, QStringList& lst, int max)
{ {
if (!rcldb) if (!rcldb)
return -1; return -1;
if (s.empty()) if (s.empty())
return 0; return 0;
// Query database for completions // Query database for completions
s += "*"; s += "*";
Rcl::TermMatchResult tmres; Rcl::TermMatchResult tmres;
if (!rcldb->termMatch(Rcl::Db::ET_WILD, "", s, tmres, max) || if (!rcldb->termMatch(Rcl::Db::ET_WILD, "", s, tmres, max) ||
tmres.entries.size() == 0) { tmres.entries.size() == 0) {
return 0; return 0;
} }
for (vector<Rcl::TermMatchEntry>::iterator it = tmres.entries.begin(); for (const auto& entry: tmres.entries) {
it != tmres.entries.end(); it++) { lst.push_back(u8s2qs(entry.term));
lst.push_back(QString::fromUtf8(it->term.c_str()));
} }
return lst.size(); return lst.size();
} }
@ -476,25 +481,25 @@ int SSearch::completionList(string s, QStringList& lst, int max)
// Complete last word in input by querying db for all possible terms. // Complete last word in input by querying db for all possible terms.
void SSearch::completion() void SSearch::completion()
{ {
LOGDEB("SSearch::completion\n" ); LOGDEB("SSearch::completion\n");
m_disableAutosearch = true; m_disableAutosearch = true;
m_stroketimeout->stop(); m_stroketimeout->stop();
if (!rcldb) if (!rcldb)
return; return;
if (searchTypCMB->currentIndex() == SST_FNM) { if (searchTypCMB->currentIndex() == SST_FNM) {
// Filename: no completion // Filename: no completion
QApplication::beep(); QApplication::beep();
return; return;
} }
// Extract last word in text // Extract last word in text
string s; string s;
int cs = partialWord(s); int cs = partialWord(s);
if (cs < 0) { if (cs < 0) {
QApplication::beep(); QApplication::beep();
return; return;
} }
// Query database for completions // Query database for completions
@ -502,53 +507,53 @@ void SSearch::completion()
const int maxdpy = 80; const int maxdpy = 80;
const int maxwalked = 10000; const int maxwalked = 10000;
if (completionList(s, lst, maxwalked) <= 0) { if (completionList(s, lst, maxwalked) <= 0) {
QApplication::beep(); QApplication::beep();
return; return;
} }
if (lst.size() >= maxdpy) { if (lst.size() >= maxdpy) {
LOGDEB0("SSearch::completion(): truncating list\n" ); LOGDEB0("SSearch::completion(): truncating list\n");
lst = lst.mid(0, maxdpy); lst = lst.mid(0, maxdpy);
lst.append("[...]"); lst.append("[...]");
} }
// If list from db is single word, insert it, else popup the listview // If list from db is single word, insert it, else popup the listview
if (lst.size() == 1) { if (lst.size() == 1) {
QString txt = queryText->currentText(); QString txt = queryText->currentText();
txt.truncate(cs); txt.truncate(cs);
txt.append(lst[0]); txt.append(lst[0]);
queryText->setEditText(txt); queryText->setEditText(txt);
} else { } else {
m_savedEditText = queryText->currentText(); m_savedEditText = queryText->currentText();
m_displayingCompletions = true; m_displayingCompletions = true;
m_chosenCompletion.clear(); m_chosenCompletion.clear();
m_completedWordStart = cs; m_completedWordStart = cs;
queryText->clear(); queryText->clear();
queryText->addItems(lst); queryText->addItems(lst);
queryText->showPopup(); queryText->showPopup();
connect(queryText, SIGNAL(activated(const QString&)), this, connect(queryText, SIGNAL(activated(const QString&)), this,
SLOT(completionTermChosen(const QString&))); SLOT(completionTermChosen(const QString&)));
} }
} }
void SSearch::completionTermChosen(const QString& text) void SSearch::completionTermChosen(const QString& text)
{ {
if (text != "[...]") if (text != "[...]")
m_chosenCompletion = text; m_chosenCompletion = text;
else else
m_chosenCompletion.clear(); m_chosenCompletion.clear();
} }
void SSearch::wrapupCompletion() void SSearch::wrapupCompletion()
{ {
LOGDEB("SSearch::wrapupCompletion\n" ); LOGDEB("SSearch::wrapupCompletion\n");
queryText->clear(); queryText->clear();
queryText->addItems(prefs.ssearchHistory); queryText->addItems(prefs.ssearchHistory);
if (!m_chosenCompletion.isEmpty()) { if (!m_chosenCompletion.isEmpty()) {
m_savedEditText.truncate(m_completedWordStart); m_savedEditText.truncate(m_completedWordStart);
m_savedEditText.append(m_chosenCompletion); m_savedEditText.append(m_chosenCompletion);
} }
queryText->setEditText(m_savedEditText); queryText->setEditText(m_savedEditText);
m_disableAutosearch = true; m_disableAutosearch = true;
@ -556,7 +561,7 @@ void SSearch::wrapupCompletion()
m_chosenCompletion.clear(); m_chosenCompletion.clear();
m_displayingCompletions = false; m_displayingCompletions = false;
disconnect(queryText, SIGNAL(activated(const QString&)), this, disconnect(queryText, SIGNAL(activated(const QString&)), this,
SLOT(completionTermChosen(const QString&))); SLOT(completionTermChosen(const QString&)));
} }
#undef SHOWEVENTS #undef SHOWEVENTS
@ -602,7 +607,7 @@ const char *eventTypeToStr(int tp)
case 39: return "PaletteChange"; case 39: return "PaletteChange";
case 40: return "Clipboard"; case 40: return "Clipboard";
case 42: return "Speech"; case 42: return "Speech";
case 43: return "MetaCall"; case 43: return "MetaCall";
case 50: return "SockAct"; case 50: return "SockAct";
case 132: return "WinEventAct"; case 132: return "WinEventAct";
case 52: return "DeferredDelete"; case 52: return "DeferredDelete";
@ -704,54 +709,57 @@ bool SSearch::eventFilter(QObject *target, QEvent *event)
{ {
#if defined(SHOWEVENTS) #if defined(SHOWEVENTS)
if (event->type() == QEvent::Timer || if (event->type() == QEvent::Timer ||
event->type() == QEvent::UpdateRequest || event->type() == QEvent::UpdateRequest ||
event->type() == QEvent::Paint) event->type() == QEvent::Paint)
return false; return false;
LOGDEB2("SSearch::eventFilter: target " << (target) << " (" << (queryText->lineEdit()) << ") type " << (eventTypeToStr(event->type())) << "\n" ); LOGDEB2("SSearch::eventFilter: target " << target << " (" <<
queryText->lineEdit() << ") type " <<
eventTypeToStr(event->type()) << "\n");
#endif #endif
if (target == (QObject*)(queryText->view())) { if (target == (QObject*)(queryText->view())) {
if (event->type() == QEvent::Hide) { if (event->type() == QEvent::Hide) {
// List was closed. If we were displaying completions, need // List was closed. If we were displaying completions, need
// to reset state. // to reset state.
if (m_displayingCompletions) { if (m_displayingCompletions) {
QTimer::singleShot(0, this, SLOT(wrapupCompletion())); QTimer::singleShot(0, this, SLOT(wrapupCompletion()));
} }
} }
return false; return false;
} }
if (event->type() == QEvent::KeyPress) { if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = (QKeyEvent *)event; QKeyEvent *ke = (QKeyEvent *)event;
LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << (m_escape) << ") key " << (ke->key()) << "\n" ); LOGDEB1("SSearch::eventFilter: keyPress (m_escape " << m_escape <<
if (ke->key() == Qt::Key_Escape) { ") key " << ke->key() << "\n");
LOGDEB("Escape\n" ); if (ke->key() == Qt::Key_Escape) {
m_escape = true; LOGDEB("Escape\n");
m_disableAutosearch = true; m_escape = true;
m_stroketimeout->stop(); m_disableAutosearch = true;
return true; m_stroketimeout->stop();
} else if (m_escape && ke->key() == Qt::Key_Space) { return true;
LOGDEB("Escape space\n" ); } else if (m_escape && ke->key() == Qt::Key_Space) {
ke->accept(); LOGDEB("Escape space\n");
completion(); ke->accept();
m_escape = false; completion();
m_disableAutosearch = true; m_escape = false;
m_stroketimeout->stop(); m_disableAutosearch = true;
return true; m_stroketimeout->stop();
} else if (ke->key() == Qt::Key_Space) { return true;
if (prefs.ssearchOnWS) } else if (ke->key() == Qt::Key_Space) {
startSimpleSearch(); if (prefs.ssearchOnWS)
} else { startSimpleSearch();
m_escape = false; } else {
m_keystroke = true; m_escape = false;
if (prefs.ssearchAsYouType) { m_keystroke = true;
m_disableAutosearch = false; if (prefs.ssearchAsYouType) {
QString qs = queryText->currentText(); m_disableAutosearch = false;
LOGDEB0("SSearch::eventFilter: start timer, qs [" << (qs2utf8s(qs)) << "]\n" ); QString qs = queryText->currentText();
m_stroketimeout->start(strokeTimeoutMS); LOGDEB0("SSearch::eventFilter: start timer, qs [" <<
} qs2utf8s(qs) << "]\n");
} m_stroketimeout->start(strokeTimeoutMS);
}
}
} }
return false; return false;
} }