diff --git a/src/qtgui/guiutils.cpp b/src/qtgui/guiutils.cpp index 6b13cbb3..a9cdb46b 100644 --- a/src/qtgui/guiutils.cpp +++ b/src/qtgui/guiutils.cpp @@ -111,8 +111,12 @@ void rwSettings(bool writing) } } - SETTING_RW(prefs.autoSearchOnWS, "/Recoll/prefs/reslist/autoSearchOnWS", + SETTING_RW(prefs.ssearchOnWS, "/Recoll/prefs/reslist/autoSearchOnWS", Bool, false); + SETTING_RW(prefs.ssearchNoComplete, + "/Recoll/prefs/ssearch/noComplete", Bool, false); + SETTING_RW(prefs.ssearchAsYouType, + "/Recoll/prefs/ssearch/asYouType", Bool, false); SETTING_RW(prefs.catgToolBar, "/Recoll/prefs/catgToolBar", Bool, false); SETTING_RW(prefs.ssearchAutoPhrase, "/Recoll/prefs/ssearchAutoPhrase", Bool, true); diff --git a/src/qtgui/guiutils.h b/src/qtgui/guiutils.h index d840e4f5..5cabb44b 100644 --- a/src/qtgui/guiutils.h +++ b/src/qtgui/guiutils.h @@ -39,7 +39,10 @@ using std::vector; /** Holder for preferences (gets saved to user Qt prefs) */ class PrefsPack { public: - bool autoSearchOnWS; + // Simple search entry behaviour + bool ssearchOnWS; + bool ssearchNoComplete; + bool ssearchAsYouType; // Decide if we display the doc category filter control as a // toolbar+combobox or as a button group under simple search bool catgToolBar; diff --git a/src/qtgui/rclmain_w.cpp b/src/qtgui/rclmain_w.cpp index 4ac98210..0b5510ba 100644 --- a/src/qtgui/rclmain_w.cpp +++ b/src/qtgui/rclmain_w.cpp @@ -1894,6 +1894,7 @@ void RclMain::setUIPrefs() return; LOGDEB(("Recollmain::setUIPrefs\n")); reslist->setFont(); + sSearch->setPrefs(); } void RclMain::enableNextPage(bool yesno) diff --git a/src/qtgui/ssearch_w.cpp b/src/qtgui/ssearch_w.cpp index b47cbc6b..98359fa0 100644 --- a/src/qtgui/ssearch_w.cpp +++ b/src/qtgui/ssearch_w.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include "debuglog.h" #include "guiutils.h" @@ -60,6 +61,13 @@ void SSearch::init() queryText->installEventFilter(this); queryText->view()->installEventFilter(this); + queryText->setInsertPolicy(QComboBox::NoInsert); + // Note: we can't do the obvious and save the completer instead because + // the combobox lineedit will delete the completer on setCompleter(0). + // But the model does not belong to the completer so it's not deleted... + m_savedModel = queryText->completer()->model(); + if (prefs.ssearchNoComplete) + queryText->completer()->setModel(0); m_displayingCompletions = false; m_escape = false; m_disableAutosearch = true; @@ -92,7 +100,7 @@ void SSearch::searchTextChanged(const QString& text) if (m_keystroke) { m_tstartqs = qs; } - if (prefs.autoSearchOnWS && !m_disableAutosearch && + if (prefs.ssearchAsYouType && !m_disableAutosearch && !m_keystroke && m_tstartqs == qs) { m_disableAutosearch = true; LOGDEB0(("SSearch::searchTextChanged: autosearch\n")); @@ -173,12 +181,15 @@ void SSearch::startSimpleSearch() // entry to be erased. There is no standard qt policy to do this ? // So do it by hand. QString txt = queryText->currentText(); - int index = queryText->findText(txt); + QString txtt = txt.trimmed(); + int index = queryText->findText(txtt); if (index > 0) { queryText->removeItem(index); } - queryText->insertItem(0, txt); - queryText->setCurrentIndex(0); + if (index != 0) { + queryText->insertItem(0, txtt); + queryText->setEditText(txt); + } m_disableAutosearch = true; m_stroketimeout->stop(); @@ -189,6 +200,14 @@ void SSearch::startSimpleSearch() prefs.ssearchHistory.push_back(queryText->itemText(index)); } } +void SSearch::setPrefs() +{ + if (prefs.ssearchNoComplete) { + queryText->completer()->setModel(0); + } else { + queryText->completer()->setModel(m_savedModel); + } +} bool SSearch::startSimpleSearch(const string& u8, int maxexp) { @@ -325,6 +344,13 @@ int SSearch::partialWord(string& s) return cs; } +// Create completion list for term by adding a joker at the end and calling +// rcldb->termMatch(). This does not work well if the db is not +// rcldb->stripped, the completion is casediac-sensitive in this case. +// +// What we should do instead is complete the term from the key list in +// the casediac expansion db (stripped->unstripped synonyms table), +// then expand each of the completed keys. int SSearch::completionList(string s, QStringList& lst, int max) { if (!rcldb) @@ -612,17 +638,18 @@ bool SSearch::eventFilter(QObject *target, QEvent *event) m_stroketimeout->stop(); return true; } else if (ke->key() == Qt::Key_Space) { -// if (prefs.autoSearchOnWS) -// startSimpleSearch(); - } - m_escape = false; - m_keystroke = true; - if (prefs.autoSearchOnWS) { - m_disableAutosearch = false; - QString qs = queryText->currentText(); - LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n", - qs2utf8s(qs).c_str())); - m_stroketimeout->start(200); + if (prefs.ssearchOnWS) + startSimpleSearch(); + } else { + m_escape = false; + m_keystroke = true; + if (prefs.ssearchAsYouType) { + m_disableAutosearch = false; + QString qs = queryText->currentText(); + LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n", + qs2utf8s(qs).c_str())); + m_stroketimeout->start(200); + } } } return false; diff --git a/src/qtgui/ssearch_w.h b/src/qtgui/ssearch_w.h index 60fc4732..7cefe8c8 100644 --- a/src/qtgui/ssearch_w.h +++ b/src/qtgui/ssearch_w.h @@ -47,6 +47,7 @@ public: virtual void completion(); virtual bool eventFilter(QObject *target, QEvent *event); virtual bool hasSearchString(); + virtual void setPrefs(); public slots: virtual void searchTextChanged(const QString & text); virtual void searchTypeChanged(int); @@ -72,6 +73,7 @@ signals: QTimer *m_stroketimeout; bool m_keystroke; QString m_tstartqs; + QAbstractItemModel *m_savedModel; int partialWord(string& s); int completionList(string s, QStringList& lst, int max = 100); diff --git a/src/qtgui/uiprefs.ui b/src/qtgui/uiprefs.ui index a0820485..a973af1d 100644 --- a/src/qtgui/uiprefs.ui +++ b/src/qtgui/uiprefs.ui @@ -219,7 +219,17 @@ - + + + Disable Qt autocompletion in search entry. + + + false + + + + + Auto-start simple search on whitespace entry. @@ -228,6 +238,16 @@ + + + + Search as you type. + + + false + + + diff --git a/src/qtgui/uiprefs_w.cpp b/src/qtgui/uiprefs_w.cpp index 511c4724..46f0d2a3 100644 --- a/src/qtgui/uiprefs_w.cpp +++ b/src/qtgui/uiprefs_w.cpp @@ -79,6 +79,10 @@ void UIPrefsDialog::init() connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(buildAbsCB, SIGNAL(toggled(bool)), replAbsCB, SLOT(setEnabled(bool))); + connect(ssAutoAllCB, SIGNAL(toggled(bool)), + ssAutoSpaceCB, SLOT(setDisabled(bool))); + connect(ssAutoAllCB, SIGNAL(toggled(bool)), + ssAutoSpaceCB, SLOT(setChecked(bool))); connect(useDesktopOpenCB, SIGNAL(toggled(bool)), viewActionPB, SLOT(setDisabled(bool))); connect(useDesktopOpenCB, SIGNAL(toggled(bool)), @@ -95,7 +99,9 @@ void UIPrefsDialog::setFromPrefs() collapseDupsCB->setChecked(prefs.collapseDuplicates); maxHLTSB->setValue(prefs.maxhltextmbs); catgToolBarCB->setChecked(prefs.catgToolBar); - autoSearchCB->setChecked(prefs.autoSearchOnWS); + ssAutoSpaceCB->setChecked(prefs.ssearchOnWS); + ssNoCompleteCB->setChecked(prefs.ssearchNoComplete); + ssAutoAllCB->setChecked(prefs.ssearchAsYouType); syntlenSB->setValue(prefs.syntAbsLen); syntctxSB->setValue(prefs.syntAbsCtx); @@ -207,7 +213,10 @@ void UIPrefsDialog::setFromPrefs() void UIPrefsDialog::accept() { - prefs.autoSearchOnWS = autoSearchCB->isChecked(); + prefs.ssearchOnWS = ssAutoSpaceCB->isChecked(); + prefs.ssearchNoComplete = ssNoCompleteCB->isChecked(); + prefs.ssearchAsYouType = ssAutoAllCB->isChecked(); + prefs.catgToolBar = catgToolBarCB->isChecked(); prefs.respagesize = pageLenSB->value(); prefs.collapseDuplicates = collapseDupsCB->isChecked();