|
a/src/qtgui/spell_w.cpp |
|
b/src/qtgui/spell_w.cpp |
|
... |
|
... |
14 |
* Free Software Foundation, Inc.,
|
14 |
* Free Software Foundation, Inc.,
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
16 |
*/
|
16 |
*/
|
17 |
#include "autoconfig.h"
|
17 |
#include "autoconfig.h"
|
18 |
|
18 |
|
|
|
19 |
#include <algorithm>
|
|
|
20 |
|
19 |
#include <unistd.h>
|
21 |
#include <unistd.h>
|
20 |
|
22 |
|
21 |
#include <list>
|
23 |
#include <list>
|
22 |
#include <stdio.h>
|
24 |
#include <stdio.h>
|
23 |
|
25 |
|
|
... |
|
... |
28 |
#include <qlayout.h>
|
30 |
#include <qlayout.h>
|
29 |
#include <qtooltip.h>
|
31 |
#include <qtooltip.h>
|
30 |
#include <qcombobox.h>
|
32 |
#include <qcombobox.h>
|
31 |
#include <QTableWidget>
|
33 |
#include <QTableWidget>
|
32 |
#include <QHeaderView>
|
34 |
#include <QHeaderView>
|
|
|
35 |
#include <QClipboard>
|
|
|
36 |
#include <QKeyEvent>
|
33 |
|
37 |
|
34 |
#include "debuglog.h"
|
38 |
#include "debuglog.h"
|
35 |
#include "recoll.h"
|
39 |
#include "recoll.h"
|
36 |
#include "spell_w.h"
|
40 |
#include "spell_w.h"
|
37 |
#include "guiutils.h"
|
41 |
#include "guiutils.h"
|
|
... |
|
... |
86 |
connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
|
90 |
connect(dismissPB, SIGNAL(clicked()), this, SLOT(close()));
|
87 |
connect(expTypeCMB, SIGNAL(activated(int)), this, SLOT(modeSet(int)));
|
91 |
connect(expTypeCMB, SIGNAL(activated(int)), this, SLOT(modeSet(int)));
|
88 |
|
92 |
|
89 |
QStringList labels(tr("Term"));
|
93 |
QStringList labels(tr("Term"));
|
90 |
labels.push_back(tr("Doc. / Tot."));
|
94 |
labels.push_back(tr("Doc. / Tot."));
|
91 |
suggsLV->setHorizontalHeaderLabels(labels);
|
95 |
resTW->setHorizontalHeaderLabels(labels);
|
92 |
suggsLV->setShowGrid(0);
|
96 |
resTW->setShowGrid(0);
|
93 |
suggsLV->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
|
97 |
resTW->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
|
94 |
suggsLV->verticalHeader()->setDefaultSectionSize(20);
|
98 |
resTW->verticalHeader()->setDefaultSectionSize(20);
|
95 |
connect(suggsLV,
|
99 |
connect(resTW,
|
96 |
SIGNAL(cellDoubleClicked(int, int)),
|
100 |
SIGNAL(cellDoubleClicked(int, int)),
|
97 |
this, SLOT(textDoubleClicked(int, int)));
|
101 |
this, SLOT(textDoubleClicked(int, int)));
|
98 |
|
102 |
|
99 |
suggsLV->setColumnWidth(0, 200);
|
103 |
resTW->setColumnWidth(0, 200);
|
100 |
suggsLV->setColumnWidth(1, 150);
|
104 |
resTW->setColumnWidth(1, 150);
|
|
|
105 |
resTW->installEventFilter(this);
|
101 |
}
|
106 |
}
|
102 |
|
107 |
|
103 |
/* Expand term according to current mode */
|
108 |
/* Expand term according to current mode */
|
104 |
void SpellW::doExpand()
|
109 |
void SpellW::doExpand()
|
105 |
{
|
110 |
{
|
106 |
// Can't clear qt4 table widget: resets column headers too
|
111 |
// Can't clear qt4 table widget: resets column headers too
|
107 |
suggsLV->setRowCount(0);
|
112 |
resTW->setRowCount(0);
|
108 |
if (baseWordLE->text().isEmpty())
|
113 |
if (baseWordLE->text().isEmpty())
|
109 |
return;
|
114 |
return;
|
110 |
|
115 |
|
111 |
string reason;
|
116 |
string reason;
|
112 |
if (!maybeOpenDb(reason)) {
|
117 |
if (!maybeOpenDb(reason)) {
|
|
... |
|
... |
174 |
#endif
|
179 |
#endif
|
175 |
}
|
180 |
}
|
176 |
|
181 |
|
177 |
|
182 |
|
178 |
if (res.entries.empty()) {
|
183 |
if (res.entries.empty()) {
|
179 |
suggsLV->setItem(0, 0, new QTableWidgetItem(tr("No expansion found")));
|
184 |
resTW->setItem(0, 0, new QTableWidgetItem(tr("No expansion found")));
|
180 |
} else {
|
185 |
} else {
|
181 |
int row = 0;
|
186 |
int row = 0;
|
182 |
for (list<Rcl::TermMatchEntry>::iterator it = res.entries.begin();
|
187 |
for (list<Rcl::TermMatchEntry>::iterator it = res.entries.begin();
|
183 |
it != res.entries.end(); it++) {
|
188 |
it != res.entries.end(); it++) {
|
184 |
LOGDEB(("SpellW::expand: %6d [%s]\n", it->wcf, it->term.c_str()));
|
189 |
LOGDEB(("SpellW::expand: %6d [%s]\n", it->wcf, it->term.c_str()));
|
185 |
char num[30];
|
190 |
char num[30];
|
186 |
if (it->wcf)
|
191 |
if (it->wcf)
|
187 |
sprintf(num, "%d / %d", it->docs, it->wcf);
|
192 |
sprintf(num, "%d / %d", it->docs, it->wcf);
|
188 |
else
|
193 |
else
|
189 |
num[0] = 0;
|
194 |
num[0] = 0;
|
190 |
if (suggsLV->rowCount() <= row)
|
195 |
if (resTW->rowCount() <= row)
|
191 |
suggsLV->setRowCount(row+1);
|
196 |
resTW->setRowCount(row+1);
|
192 |
suggsLV->setItem(row, 0,
|
197 |
resTW->setItem(row, 0,
|
193 |
new QTableWidgetItem(QString::fromUtf8(it->term.c_str())));
|
198 |
new QTableWidgetItem(QString::fromUtf8(it->term.c_str())));
|
194 |
suggsLV->setItem(row++, 1,
|
199 |
resTW->setItem(row++, 1,
|
195 |
new QTableWidgetItem(QString::fromAscii(num)));
|
200 |
new QTableWidgetItem(QString::fromAscii(num)));
|
196 |
}
|
201 |
}
|
197 |
suggsLV->setRowCount(row+1);
|
202 |
resTW->setRowCount(row+1);
|
198 |
}
|
203 |
}
|
199 |
}
|
204 |
}
|
200 |
|
205 |
|
201 |
void SpellW::wordChanged(const QString &text)
|
206 |
void SpellW::wordChanged(const QString &text)
|
202 |
{
|
207 |
{
|
203 |
if (text.isEmpty()) {
|
208 |
if (text.isEmpty()) {
|
204 |
expandPB->setEnabled(false);
|
209 |
expandPB->setEnabled(false);
|
205 |
suggsLV->setRowCount(0);
|
210 |
resTW->setRowCount(0);
|
206 |
} else {
|
211 |
} else {
|
207 |
expandPB->setEnabled(true);
|
212 |
expandPB->setEnabled(true);
|
208 |
}
|
213 |
}
|
209 |
}
|
214 |
}
|
210 |
|
215 |
|
211 |
void SpellW::textDoubleClicked() {}
|
216 |
void SpellW::textDoubleClicked() {}
|
212 |
void SpellW::textDoubleClicked(int row, int)
|
217 |
void SpellW::textDoubleClicked(int row, int)
|
213 |
{
|
218 |
{
|
214 |
QTableWidgetItem *item = suggsLV->item(row, 0);
|
219 |
QTableWidgetItem *item = resTW->item(row, 0);
|
215 |
if (item)
|
220 |
if (item)
|
216 |
emit(wordSelect(item->text()));
|
221 |
emit(wordSelect(item->text()));
|
217 |
}
|
222 |
}
|
218 |
|
223 |
|
219 |
void SpellW::modeSet(int mode)
|
224 |
void SpellW::modeSet(int mode)
|
|
... |
|
... |
221 |
if (mode == 2)
|
226 |
if (mode == 2)
|
222 |
stemLangCMB->setEnabled(true);
|
227 |
stemLangCMB->setEnabled(true);
|
223 |
else
|
228 |
else
|
224 |
stemLangCMB->setEnabled(false);
|
229 |
stemLangCMB->setEnabled(false);
|
225 |
}
|
230 |
}
|
|
|
231 |
|
|
|
232 |
void SpellW::copy()
|
|
|
233 |
{
|
|
|
234 |
QItemSelectionModel * selection = resTW->selectionModel();
|
|
|
235 |
QModelIndexList indexes = selection->selectedIndexes();
|
|
|
236 |
|
|
|
237 |
if(indexes.size() < 1)
|
|
|
238 |
return;
|
|
|
239 |
|
|
|
240 |
// QModelIndex::operator < sorts first by row, then by column.
|
|
|
241 |
// this is what we need
|
|
|
242 |
std::sort(indexes.begin(), indexes.end());
|
|
|
243 |
|
|
|
244 |
// You need a pair of indexes to find the row changes
|
|
|
245 |
QModelIndex previous = indexes.first();
|
|
|
246 |
indexes.removeFirst();
|
|
|
247 |
QString selected_text;
|
|
|
248 |
QModelIndex current;
|
|
|
249 |
Q_FOREACH(current, indexes)
|
|
|
250 |
{
|
|
|
251 |
QVariant data = resTW->model()->data(previous);
|
|
|
252 |
QString text = data.toString();
|
|
|
253 |
// At this point `text` contains the text in one cell
|
|
|
254 |
selected_text.append(text);
|
|
|
255 |
// If you are at the start of the row the row number of the previous index
|
|
|
256 |
// isn't the same. Text is followed by a row separator, which is a newline.
|
|
|
257 |
if (current.row() != previous.row())
|
|
|
258 |
{
|
|
|
259 |
selected_text.append(QLatin1Char('\n'));
|
|
|
260 |
}
|
|
|
261 |
// Otherwise it's the same row, so append a column separator, which is a tab.
|
|
|
262 |
else
|
|
|
263 |
{
|
|
|
264 |
selected_text.append(QLatin1Char('\t'));
|
|
|
265 |
}
|
|
|
266 |
previous = current;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
// add last element
|
|
|
270 |
selected_text.append(resTW->model()->data(current).toString());
|
|
|
271 |
selected_text.append(QLatin1Char('\n'));
|
|
|
272 |
qApp->clipboard()->setText(selected_text, QClipboard::Selection);
|
|
|
273 |
qApp->clipboard()->setText(selected_text, QClipboard::Clipboard);
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
|
|
|
277 |
bool SpellW::eventFilter(QObject *target, QEvent *event)
|
|
|
278 |
{
|
|
|
279 |
if (event->type() != QEvent::KeyPress ||
|
|
|
280 |
(target != resTW && target != resTW->viewport()))
|
|
|
281 |
return false;
|
|
|
282 |
|
|
|
283 |
QKeyEvent *keyEvent = (QKeyEvent *)event;
|
|
|
284 |
if(keyEvent->matches(QKeySequence::Copy) )
|
|
|
285 |
{
|
|
|
286 |
copy();
|
|
|
287 |
return true;
|
|
|
288 |
}
|
|
|
289 |
return false;
|
|
|
290 |
}
|