added preferences for search-as-you-type and combobox completion

This commit is contained in:
Jean-Francois Dockes 2012-11-23 17:10:53 +01:00
parent 5c01c60ad0
commit b67bc06f4b
7 changed files with 86 additions and 20 deletions

View File

@ -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);

View File

@ -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;

View File

@ -1894,6 +1894,7 @@ void RclMain::setUIPrefs()
return;
LOGDEB(("Recollmain::setUIPrefs\n"));
reslist->setFont();
sSearch->setPrefs();
}
void RclMain::enableNextPage(bool yesno)

View File

@ -25,6 +25,7 @@
#include <qmessagebox.h>
#include <qevent.h>
#include <QTimer>
#include <QCompleter>
#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;

View File

@ -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);

View File

@ -219,7 +219,17 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="autoSearchCB">
<widget class="QCheckBox" name="ssNoCompleteCB">
<property name="text">
<string>Disable Qt autocompletion in search entry.</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ssAutoSpaceCB">
<property name="text">
<string>Auto-start simple search on whitespace entry.</string>
</property>
@ -228,6 +238,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ssAutoAllCB">
<property name="text">
<string>Search as you type.</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="initStartAdvCB">
<property name="text">

View File

@ -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();