|
a/src/qtgui/ssearchb.ui.h |
|
b/src/qtgui/ssearchb.ui.h |
1 |
/*
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
/****************************************************************************
|
1 |
/****************************************************************************
|
18 |
** ui.h extension file, included from the uic-generated form implementation.
|
2 |
** ui.h extension file, included from the uic-generated form implementation.
|
19 |
**
|
3 |
**
|
20 |
** If you want to add, delete, or rename functions or slots, use
|
4 |
** If you want to add, delete, or rename functions or slots, use
|
21 |
** Qt Designer to update this file, preserving your code.
|
5 |
** Qt Designer to update this file, preserving your code.
|
|
... |
|
... |
23 |
** You should not define a constructor or destructor in this file.
|
7 |
** You should not define a constructor or destructor in this file.
|
24 |
** Instead, write your code in functions called init() and destroy().
|
8 |
** Instead, write your code in functions called init() and destroy().
|
25 |
** These will automatically be called by the form's constructor and
|
9 |
** These will automatically be called by the form's constructor and
|
26 |
** destructor.
|
10 |
** destructor.
|
27 |
*****************************************************************************/
|
11 |
*****************************************************************************/
|
28 |
#include <qapplication.h>
|
|
|
29 |
#include <qinputdialog.h>
|
|
|
30 |
|
|
|
31 |
#include "debuglog.h"
|
|
|
32 |
#include "guiutils.h"
|
|
|
33 |
#include "searchdata.h"
|
|
|
34 |
|
|
|
35 |
void SSearchBase::init()
|
|
|
36 |
{
|
|
|
37 |
searchTypCMB->insertItem(tr("Any term"));
|
|
|
38 |
searchTypCMB->insertItem(tr("All terms"));
|
|
|
39 |
searchTypCMB->insertItem(tr("File name"));
|
|
|
40 |
queryText->insertStringList(prefs.ssearchHistory);
|
|
|
41 |
queryText->setEditText("");
|
|
|
42 |
connect(queryText->lineEdit(), SIGNAL(returnPressed()),
|
|
|
43 |
this, SLOT(startSimpleSearch()));
|
|
|
44 |
connect(queryText->lineEdit(), SIGNAL(textChanged(const QString&)),
|
|
|
45 |
this, SLOT(searchTextChanged(const QString&)));
|
|
|
46 |
connect(clearqPB, SIGNAL(clicked()),
|
|
|
47 |
queryText->lineEdit(), SLOT(clear()));
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
void SSearchBase::searchTextChanged( const QString & text )
|
|
|
51 |
{
|
|
|
52 |
if (text.isEmpty()) {
|
|
|
53 |
searchPB->setEnabled(false);
|
|
|
54 |
clearqPB->setEnabled(false);
|
|
|
55 |
emit clearSearch();
|
|
|
56 |
} else {
|
|
|
57 |
searchPB->setEnabled(true);
|
|
|
58 |
clearqPB->setEnabled(true);
|
|
|
59 |
string u8 = (const char *)queryText->currentText().utf8();
|
|
|
60 |
if (prefs.autoSearchOnWS && !u8.empty() && u8[u8.length()-1] == ' ')
|
|
|
61 |
startSimpleSearch();
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
void SSearchBase::startSimpleSearch()
|
|
|
66 |
{
|
|
|
67 |
LOGDEB(("SSearchBase::startSimpleSearch\n"));
|
|
|
68 |
|
|
|
69 |
Rcl::AdvSearchData sdata;
|
|
|
70 |
QCString u8 = queryText->currentText().utf8();
|
|
|
71 |
switch (searchTypCMB->currentItem()) {
|
|
|
72 |
case 0:
|
|
|
73 |
default:
|
|
|
74 |
sdata.orwords = u8;
|
|
|
75 |
break;
|
|
|
76 |
case 1:
|
|
|
77 |
sdata.allwords = u8;
|
|
|
78 |
break;
|
|
|
79 |
case 2:
|
|
|
80 |
sdata.filename = u8;
|
|
|
81 |
break;
|
|
|
82 |
}
|
|
|
83 |
prefs.ssearchHistory.clear();
|
|
|
84 |
for (int index = 0; index < queryText->count(); index++)
|
|
|
85 |
prefs.ssearchHistory.push_back(queryText->text(index));
|
|
|
86 |
|
|
|
87 |
emit startSearch(sdata);
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
void SSearchBase::setAnyTermMode()
|
|
|
91 |
{
|
|
|
92 |
searchTypCMB->setCurrentItem(0);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
// Complete last word in input by querying db for all possible terms.
|
|
|
96 |
void SSearchBase::completion()
|
|
|
97 |
{
|
|
|
98 |
if (!rcldb)
|
|
|
99 |
return;
|
|
|
100 |
if (searchTypCMB->currentItem() == 2) {
|
|
|
101 |
// Filename: no completion
|
|
|
102 |
QApplication::beep();
|
|
|
103 |
return;
|
|
|
104 |
}
|
|
|
105 |
// Extract last word in text
|
|
|
106 |
string txt = (const char *)queryText->currentText().utf8();
|
|
|
107 |
string::size_type cs = txt.find_last_of(" ");
|
|
|
108 |
if (cs == string::npos)
|
|
|
109 |
cs = 0;
|
|
|
110 |
else
|
|
|
111 |
cs++;
|
|
|
112 |
if (txt.size() == 0 || cs == txt.size()) {
|
|
|
113 |
QApplication::beep();
|
|
|
114 |
return;
|
|
|
115 |
}
|
|
|
116 |
string s = txt.substr(cs);
|
|
|
117 |
LOGDEB(("Completing: [%s]\n", s.c_str()));
|
|
|
118 |
|
|
|
119 |
// Query database
|
|
|
120 |
const int max = 100;
|
|
|
121 |
list<string> strs = rcldb->completions(s, prefs.queryStemLang.ascii(),max);
|
|
|
122 |
if (strs.size() == 0 || strs.size() == (unsigned int)max) {
|
|
|
123 |
QApplication::beep();
|
|
|
124 |
return;
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
// If list from db is single word, insert it, else ask user to select
|
|
|
128 |
QString res;
|
|
|
129 |
bool ok = false;
|
|
|
130 |
if (strs.size() == 1) {
|
|
|
131 |
res = QString::fromUtf8(strs.begin()->c_str());
|
|
|
132 |
ok = true;
|
|
|
133 |
} else {
|
|
|
134 |
QStringList lst;
|
|
|
135 |
for (list<string>::iterator it=strs.begin(); it != strs.end(); it++)
|
|
|
136 |
lst.push_back(QString::fromUtf8(it->c_str()));
|
|
|
137 |
res = QInputDialog::getItem(tr("Completions"),
|
|
|
138 |
tr("Select an item:"), lst, 0,
|
|
|
139 |
FALSE, &ok, this);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
// Insert result
|
|
|
143 |
if (ok) {
|
|
|
144 |
txt.erase(cs);
|
|
|
145 |
txt.append(res.utf8());
|
|
|
146 |
queryText->setEditText(QString::fromUtf8(txt.c_str()));
|
|
|
147 |
} else {
|
|
|
148 |
return;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
// Handle CTRL-TAB to mean completion
|
|
|
153 |
bool SSearchBase::event( QEvent *evt )
|
|
|
154 |
{
|
|
|
155 |
if ( evt->type() == QEvent::KeyPress ) {
|
|
|
156 |
QKeyEvent *ke = (QKeyEvent *)evt;
|
|
|
157 |
if ( ke->key() == Key_Tab && (ke->state() & Qt::ControlButton)) {
|
|
|
158 |
// special tab handling here
|
|
|
159 |
completion();
|
|
|
160 |
ke->accept();
|
|
|
161 |
return TRUE;
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
return QWidget::event( evt );
|
|
|
165 |
}
|
|
|
166 |
|
|
|