|
a/src/qtgui/ssearch_w.cpp |
|
b/src/qtgui/ssearch_w.cpp |
|
... |
|
... |
23 |
#include <qtooltip.h>
|
23 |
#include <qtooltip.h>
|
24 |
#include <qwhatsthis.h>
|
24 |
#include <qwhatsthis.h>
|
25 |
#include <qmessagebox.h>
|
25 |
#include <qmessagebox.h>
|
26 |
#include <qevent.h>
|
26 |
#include <qevent.h>
|
27 |
#include <QTimer>
|
27 |
#include <QTimer>
|
|
|
28 |
#include <QCompleter>
|
28 |
|
29 |
|
29 |
#include "debuglog.h"
|
30 |
#include "debuglog.h"
|
30 |
#include "guiutils.h"
|
31 |
#include "guiutils.h"
|
31 |
#include "searchdata.h"
|
32 |
#include "searchdata.h"
|
32 |
#include "ssearch_w.h"
|
33 |
#include "ssearch_w.h"
|
|
... |
|
... |
58 |
connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch()));
|
59 |
connect(searchPB, SIGNAL(clicked()), this, SLOT(startSimpleSearch()));
|
59 |
connect(searchTypCMB, SIGNAL(activated(int)), this, SLOT(searchTypeChanged(int)));
|
60 |
connect(searchTypCMB, SIGNAL(activated(int)), this, SLOT(searchTypeChanged(int)));
|
60 |
|
61 |
|
61 |
queryText->installEventFilter(this);
|
62 |
queryText->installEventFilter(this);
|
62 |
queryText->view()->installEventFilter(this);
|
63 |
queryText->view()->installEventFilter(this);
|
|
|
64 |
queryText->setInsertPolicy(QComboBox::NoInsert);
|
|
|
65 |
// Note: we can't do the obvious and save the completer instead because
|
|
|
66 |
// the combobox lineedit will delete the completer on setCompleter(0).
|
|
|
67 |
// But the model does not belong to the completer so it's not deleted...
|
|
|
68 |
m_savedModel = queryText->completer()->model();
|
|
|
69 |
if (prefs.ssearchNoComplete)
|
|
|
70 |
queryText->completer()->setModel(0);
|
63 |
m_displayingCompletions = false;
|
71 |
m_displayingCompletions = false;
|
64 |
m_escape = false;
|
72 |
m_escape = false;
|
65 |
m_disableAutosearch = true;
|
73 |
m_disableAutosearch = true;
|
66 |
m_stroketimeout = new QTimer(this);
|
74 |
m_stroketimeout = new QTimer(this);
|
67 |
m_stroketimeout->setSingleShot(true);
|
75 |
m_stroketimeout->setSingleShot(true);
|
|
... |
|
... |
90 |
searchPB->setEnabled(true);
|
98 |
searchPB->setEnabled(true);
|
91 |
clearqPB->setEnabled(true);
|
99 |
clearqPB->setEnabled(true);
|
92 |
if (m_keystroke) {
|
100 |
if (m_keystroke) {
|
93 |
m_tstartqs = qs;
|
101 |
m_tstartqs = qs;
|
94 |
}
|
102 |
}
|
95 |
if (prefs.autoSearchOnWS && !m_disableAutosearch &&
|
103 |
if (prefs.ssearchAsYouType && !m_disableAutosearch &&
|
96 |
!m_keystroke && m_tstartqs == qs) {
|
104 |
!m_keystroke && m_tstartqs == qs) {
|
97 |
m_disableAutosearch = true;
|
105 |
m_disableAutosearch = true;
|
98 |
LOGDEB0(("SSearch::searchTextChanged: autosearch\n"));
|
106 |
LOGDEB0(("SSearch::searchTextChanged: autosearch\n"));
|
99 |
string s;
|
107 |
string s;
|
100 |
int cs = partialWord(s);
|
108 |
int cs = partialWord(s);
|
|
... |
|
... |
171 |
// Search terms history:
|
179 |
// Search terms history:
|
172 |
// We want to have the new text at the top and any older identical
|
180 |
// We want to have the new text at the top and any older identical
|
173 |
// entry to be erased. There is no standard qt policy to do this ?
|
181 |
// entry to be erased. There is no standard qt policy to do this ?
|
174 |
// So do it by hand.
|
182 |
// So do it by hand.
|
175 |
QString txt = queryText->currentText();
|
183 |
QString txt = queryText->currentText();
|
|
|
184 |
QString txtt = txt.trimmed();
|
176 |
int index = queryText->findText(txt);
|
185 |
int index = queryText->findText(txtt);
|
177 |
if (index > 0) {
|
186 |
if (index > 0) {
|
178 |
queryText->removeItem(index);
|
187 |
queryText->removeItem(index);
|
179 |
}
|
188 |
}
|
|
|
189 |
if (index != 0) {
|
180 |
queryText->insertItem(0, txt);
|
190 |
queryText->insertItem(0, txtt);
|
181 |
queryText->setCurrentIndex(0);
|
191 |
queryText->setEditText(txt);
|
|
|
192 |
}
|
182 |
m_disableAutosearch = true;
|
193 |
m_disableAutosearch = true;
|
183 |
m_stroketimeout->stop();
|
194 |
m_stroketimeout->stop();
|
184 |
|
195 |
|
185 |
// Save the current state of the listbox list to the prefs (will
|
196 |
// Save the current state of the listbox list to the prefs (will
|
186 |
// go to disk)
|
197 |
// go to disk)
|
187 |
prefs.ssearchHistory.clear();
|
198 |
prefs.ssearchHistory.clear();
|
188 |
for (int index = 0; index < queryText->count(); index++) {
|
199 |
for (int index = 0; index < queryText->count(); index++) {
|
189 |
prefs.ssearchHistory.push_back(queryText->itemText(index));
|
200 |
prefs.ssearchHistory.push_back(queryText->itemText(index));
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
void SSearch::setPrefs()
|
|
|
204 |
{
|
|
|
205 |
if (prefs.ssearchNoComplete) {
|
|
|
206 |
queryText->completer()->setModel(0);
|
|
|
207 |
} else {
|
|
|
208 |
queryText->completer()->setModel(m_savedModel);
|
190 |
}
|
209 |
}
|
191 |
}
|
210 |
}
|
192 |
|
211 |
|
193 |
bool SSearch::startSimpleSearch(const string& u8, int maxexp)
|
212 |
bool SSearch::startSimpleSearch(const string& u8, int maxexp)
|
194 |
{
|
213 |
{
|
|
... |
|
... |
323 |
}
|
342 |
}
|
324 |
s = qs2utf8s(txt.right(txt.size() - cs));
|
343 |
s = qs2utf8s(txt.right(txt.size() - cs));
|
325 |
return cs;
|
344 |
return cs;
|
326 |
}
|
345 |
}
|
327 |
|
346 |
|
|
|
347 |
// Create completion list for term by adding a joker at the end and calling
|
|
|
348 |
// rcldb->termMatch(). This does not work well if the db is not
|
|
|
349 |
// rcldb->stripped, the completion is casediac-sensitive in this case.
|
|
|
350 |
//
|
|
|
351 |
// What we should do instead is complete the term from the key list in
|
|
|
352 |
// the casediac expansion db (stripped->unstripped synonyms table),
|
|
|
353 |
// then expand each of the completed keys.
|
328 |
int SSearch::completionList(string s, QStringList& lst, int max)
|
354 |
int SSearch::completionList(string s, QStringList& lst, int max)
|
329 |
{
|
355 |
{
|
330 |
if (!rcldb)
|
356 |
if (!rcldb)
|
331 |
return -1;
|
357 |
return -1;
|
332 |
// Query database for completions
|
358 |
// Query database for completions
|
|
... |
|
... |
610 |
m_escape = false;
|
636 |
m_escape = false;
|
611 |
m_disableAutosearch = true;
|
637 |
m_disableAutosearch = true;
|
612 |
m_stroketimeout->stop();
|
638 |
m_stroketimeout->stop();
|
613 |
return true;
|
639 |
return true;
|
614 |
} else if (ke->key() == Qt::Key_Space) {
|
640 |
} else if (ke->key() == Qt::Key_Space) {
|
615 |
// if (prefs.autoSearchOnWS)
|
641 |
if (prefs.ssearchOnWS)
|
616 |
// startSimpleSearch();
|
642 |
startSimpleSearch();
|
|
|
643 |
} else {
|
|
|
644 |
m_escape = false;
|
|
|
645 |
m_keystroke = true;
|
|
|
646 |
if (prefs.ssearchAsYouType) {
|
|
|
647 |
m_disableAutosearch = false;
|
|
|
648 |
QString qs = queryText->currentText();
|
|
|
649 |
LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n",
|
|
|
650 |
qs2utf8s(qs).c_str()));
|
|
|
651 |
m_stroketimeout->start(200);
|
|
|
652 |
}
|
617 |
}
|
653 |
}
|
618 |
m_escape = false;
|
|
|
619 |
m_keystroke = true;
|
|
|
620 |
if (prefs.autoSearchOnWS) {
|
|
|
621 |
m_disableAutosearch = false;
|
|
|
622 |
QString qs = queryText->currentText();
|
|
|
623 |
LOGDEB0(("SSearch::eventFilter: start timer, qs [%s]\n",
|
|
|
624 |
qs2utf8s(qs).c_str()));
|
|
|
625 |
m_stroketimeout->start(200);
|
|
|
626 |
}
|
|
|
627 |
}
|
654 |
}
|
628 |
return false;
|
655 |
return false;
|
629 |
}
|
656 |
}
|