10
#include "btsearchoptionsarea.h"
11
#include "csearchmodulechooserdialog.h"
12
#include "crangechooserdialog.h"
14
#include "util/directoryutil.h"
15
#include "util/cresmgr.h"
16
#include "util/ctoolclass.h"
17
#include "util/cpointers.h"
18
#include "backend/drivers/cswordmoduleinfo.h"
19
#include "backend/config/cbtconfig.h"
20
#include "frontend/htmldialogs/bttabhtmldialog.h"
10
#include "frontend/searchdialog/btsearchoptionsarea.h"
14
#include <QGridLayout>
22
16
#include <QHBoxLayout>
24
#include <QGridLayout>
19
#include <QMessageBox>
26
20
#include <QPushButton>
27
21
#include <QRadioButton>
30
#include <QMessageBox>
22
#include "backend/config/cbtconfig.h"
23
#include "backend/drivers/cswordmoduleinfo.h"
24
#include "frontend/htmldialogs/bttabhtmldialog.h"
25
#include "frontend/searchdialog/crangechooserdialog.h"
26
#include "frontend/searchdialog/csearchmodulechooserdialog.h"
27
#include "util/cpointers.h"
28
#include "util/cresmgr.h"
29
#include "util/tool.h"
30
#include "util/directory.h"
36
35
BtSearchOptionsArea::BtSearchOptionsArea(QWidget *parent )
44
42
BtSearchOptionsArea::~BtSearchOptionsArea() {
48
46
QString BtSearchOptionsArea::searchText() const {
49
return m_searchTextCombo->currentText();
47
return m_searchTextCombo->currentText();
52
BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType()
54
if (m_typeAndButton->isChecked()) {
55
return BtSearchOptionsArea::AndType;
57
if (m_typeOrButton->isChecked()) {
58
return BtSearchOptionsArea::OrType;
60
return BtSearchOptionsArea::FullType;
50
BtSearchOptionsArea::SearchType BtSearchOptionsArea::searchType() {
51
if (m_typeAndButton->isChecked()) {
52
return BtSearchOptionsArea::AndType;
54
if (m_typeOrButton->isChecked()) {
55
return BtSearchOptionsArea::OrType;
57
return BtSearchOptionsArea::FullType;
63
60
QPushButton* BtSearchOptionsArea::searchButton() const {
64
return m_searchButton;
61
return m_searchButton;
67
64
void BtSearchOptionsArea::setSearchText(const QString& text) {
70
for (i = 0; !found && i < m_searchTextCombo->count(); ++i) {
71
if (m_searchTextCombo->itemText(i) == text) {
75
// This is needed because in the for loop i is incremented before the comparison (++i)
76
// As a result the index i is actually one greater than expected.
80
m_searchTextCombo->insertItem(0, text );
67
for (i = 0; !found && i < m_searchTextCombo->count(); ++i) {
68
if (m_searchTextCombo->itemText(i) == text) {
72
// This is needed because in the for loop i is incremented before the comparison (++i)
73
// As a result the index i is actually one greater than expected.
77
m_searchTextCombo->insertItem(0, text );
83
m_searchTextCombo->setCurrentIndex(i);
84
m_searchTextCombo->setFocus();
80
m_searchTextCombo->setCurrentIndex(i);
81
m_searchTextCombo->setFocus();
87
void BtSearchOptionsArea::initView()
89
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
90
this->setSizePolicy(sizePolicy);
91
hboxLayout = new QHBoxLayout(this);
93
searchGroupBox = new QGroupBox(this);
95
gridLayout = new QGridLayout(searchGroupBox);
97
gridLayout->setHorizontalSpacing(3);
99
// ******** label for search text editor***********
84
void BtSearchOptionsArea::initView() {
85
namespace DU = util::directory;
87
QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
88
this->setSizePolicy(sizePolicy);
89
hboxLayout = new QHBoxLayout(this);
91
searchGroupBox = new QGroupBox(this);
93
gridLayout = new QGridLayout(searchGroupBox);
95
gridLayout->setHorizontalSpacing(3);
97
// ******** label for search text editor***********
100
98
m_searchTextLabel = new QLabel(tr("Search for:"), searchGroupBox);
101
m_searchTextLabel->setWordWrap(false);
102
gridLayout->addWidget(m_searchTextLabel, 0, 0);
104
// **********Buttons******************
106
m_searchButton = new QPushButton(this);
107
m_searchButton->setText(tr("&Search"));
108
m_searchButton->setIcon( util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::icon));
109
m_searchButton->setToolTip(tr("Start to search the text in the chosen works"));
110
gridLayout->addWidget(m_searchButton, 0, 2);
112
m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox);
113
m_chooseModulesButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::chooseworks_icon));
114
m_chooseModulesButton->setToolTip( tr("Choose works for the search"));
115
gridLayout->addWidget(m_chooseModulesButton, 2, 2);
117
m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox);
118
m_chooseRangeButton->setIcon(util::filesystem::DirectoryUtil::getIcon(CResMgr::searchdialog::setupscope_icon));
119
m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search"));
120
gridLayout->addWidget(m_chooseRangeButton, 3, 2);
122
// ************* Search type (AND/OR) selector ***************************************
123
QHBoxLayout* typeSelectorLayout = new QHBoxLayout();
124
int tsLeft, tsTop, tsRight, tsBottom;
125
// Added space looks nicer and enhances readability
126
typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom);
127
typeSelectorLayout->setContentsMargins(tsLeft, 0, tsRight, tsBottom + CToolClass::mWidth(this,1) );
128
typeSelectorLayout->setSpacing(typeSelectorLayout->spacing()+CToolClass::mWidth(this,1));
129
QHBoxLayout* fullButtonLayout = new QHBoxLayout();
130
fullButtonLayout->setSpacing(CToolClass::mWidth(this,1)/2);
131
m_typeAndButton = new QRadioButton(tr("All words"));
132
m_typeAndButton->setChecked(true);
133
m_typeOrButton = new QRadioButton(tr("Some words"));
134
m_typeFreeButton = new QRadioButton(tr("Free"));
136
m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)"));
137
m_typeOrButton->setToolTip(tr("Some of the words (OR is added between the words)"));
138
m_typeFreeButton->setToolTip(tr("Full lucene syntax"));
140
m_helpLabel = new QLabel(tr(" (<a href='syntax_help'>full syntax</a>)"));
141
m_helpLabel->setToolTip(tr("Click the link to get help for search syntax"));
143
typeSelectorLayout->addWidget(m_typeAndButton);
144
typeSelectorLayout->addWidget(m_typeOrButton);
145
fullButtonLayout->addWidget(m_typeFreeButton);
146
fullButtonLayout->addWidget(m_helpLabel);
147
typeSelectorLayout->addLayout(fullButtonLayout);
148
gridLayout->addLayout(typeSelectorLayout, 1,1, 1,-1, Qt::AlignLeft|Qt::AlignTop);
150
// ************* Label for search range/scope selector *************
151
m_searchScopeLabel = new QLabel(tr("Scope:"), searchGroupBox);
152
m_searchScopeLabel->setWordWrap(false);
153
gridLayout->addWidget(m_searchScopeLabel, 3, 0);
155
// ***********Range/scope selector combo box***********
156
m_rangeChooserCombo = new QComboBox(searchGroupBox);
157
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
158
sizePolicy2.setHorizontalStretch(0);
159
sizePolicy2.setVerticalStretch(0);
160
sizePolicy2.setHeightForWidth(m_rangeChooserCombo->sizePolicy().hasHeightForWidth());
161
m_rangeChooserCombo->setSizePolicy(sizePolicy2);
162
m_rangeChooserCombo->setToolTip(tr("Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries."));
163
gridLayout->addWidget(m_rangeChooserCombo, 3, 1);
165
// ************* Search text combo box *******************
166
m_searchTextCombo = new CHistoryComboBox(searchGroupBox);
167
sizePolicy2.setHeightForWidth(m_searchTextCombo->sizePolicy().hasHeightForWidth());
168
m_searchTextCombo->setSizePolicy(sizePolicy2);
169
m_searchTextCombo->setFocusPolicy(Qt::WheelFocus);
170
m_searchTextCombo->setProperty("sizeLimit", QVariant(25));
171
m_searchTextCombo->setProperty("duplicatesEnabled", QVariant(false));
172
m_searchTextCombo->setToolTip(tr("The text you want to search for"));
173
m_searchTextCombo->setInsertPolicy(QComboBox::NoInsert);
174
gridLayout->addWidget(m_searchTextCombo, 0, 1);
176
m_modulesLabel = new QLabel(tr("Works:"), searchGroupBox);
177
gridLayout->addWidget(m_modulesLabel, 2, 0);
179
m_modulesCombo = new QComboBox(searchGroupBox);
180
m_modulesCombo->setDuplicatesEnabled(false);
181
gridLayout->addWidget(m_modulesCombo, 2, 1);
183
hboxLayout->addWidget(searchGroupBox);
185
// Set the minimum size before the widgets are populated with data.
186
// Otherwise we will get problems with sizing.
187
setMinimumSize(minimumSizeHint());
190
//set the initial focus
191
m_searchTextCombo->setFocus();
192
// event filter to prevent the Return/Enter presses in the combo box doing something
193
// in the parent widget
194
m_searchTextCombo->installEventFilter(this);
99
m_searchTextLabel->setWordWrap(false);
100
gridLayout->addWidget(m_searchTextLabel, 0, 0);
102
// **********Buttons******************
104
m_searchButton = new QPushButton(this);
105
m_searchButton->setText(tr("&Search"));
106
m_searchButton->setIcon(DU::getIcon(CResMgr::searchdialog::icon));
107
m_searchButton->setToolTip(tr("Start to search the text in the chosen works"));
108
gridLayout->addWidget(m_searchButton, 0, 2);
110
m_chooseModulesButton = new QPushButton(tr("Ch&oose..."), searchGroupBox);
111
m_chooseModulesButton->setIcon(DU::getIcon(CResMgr::searchdialog::chooseworks_icon));
112
m_chooseModulesButton->setToolTip( tr("Choose works for the search"));
113
gridLayout->addWidget(m_chooseModulesButton, 2, 2);
115
m_chooseRangeButton = new QPushButton(tr("S&etup..."), searchGroupBox);
116
m_chooseRangeButton->setIcon(DU::getIcon(CResMgr::searchdialog::setupscope_icon));
117
m_chooseRangeButton->setToolTip(tr("Configure predefined scopes for search"));
118
gridLayout->addWidget(m_chooseRangeButton, 3, 2);
120
// ************* Search type (AND/OR) selector ***************************************
121
QHBoxLayout* typeSelectorLayout = new QHBoxLayout();
122
int tsLeft, tsTop, tsRight, tsBottom;
123
// Added space looks nicer and enhances readability
124
typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom);
125
typeSelectorLayout->setContentsMargins(tsLeft, 0, tsRight, tsBottom + util::tool::mWidth(this, 1) );
126
typeSelectorLayout->setSpacing(typeSelectorLayout->spacing() + util::tool::mWidth(this, 1));
127
QHBoxLayout* fullButtonLayout = new QHBoxLayout();
128
fullButtonLayout->setSpacing(util::tool::mWidth(this, 1) / 2);
129
m_typeAndButton = new QRadioButton(tr("All words"));
130
m_typeAndButton->setChecked(true);
131
m_typeOrButton = new QRadioButton(tr("Some words"));
132
m_typeFreeButton = new QRadioButton(tr("Free"));
134
m_typeAndButton->setToolTip(tr("All of the words (AND is added between the words)"));
135
m_typeOrButton->setToolTip(tr("Some of the words (OR is added between the words)"));
136
m_typeFreeButton->setToolTip(tr("Full lucene syntax"));
138
m_helpLabel = new QLabel(tr(" (<a href='syntax_help'>full syntax</a>)"));
139
m_helpLabel->setToolTip(tr("Click the link to get help for search syntax"));
141
typeSelectorLayout->addWidget(m_typeAndButton);
142
typeSelectorLayout->addWidget(m_typeOrButton);
143
fullButtonLayout->addWidget(m_typeFreeButton);
144
fullButtonLayout->addWidget(m_helpLabel);
145
typeSelectorLayout->addLayout(fullButtonLayout);
146
gridLayout->addLayout(typeSelectorLayout, 1, 1, 1, -1, Qt::AlignLeft | Qt::AlignTop);
148
// ************* Label for search range/scope selector *************
149
m_searchScopeLabel = new QLabel(tr("Scope:"), searchGroupBox);
150
m_searchScopeLabel->setWordWrap(false);
151
gridLayout->addWidget(m_searchScopeLabel, 3, 0);
153
// ***********Range/scope selector combo box***********
154
m_rangeChooserCombo = new QComboBox(searchGroupBox);
155
QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
156
sizePolicy2.setHorizontalStretch(0);
157
sizePolicy2.setVerticalStretch(0);
158
sizePolicy2.setHeightForWidth(m_rangeChooserCombo->sizePolicy().hasHeightForWidth());
159
m_rangeChooserCombo->setSizePolicy(sizePolicy2);
160
m_rangeChooserCombo->setToolTip(tr("Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries."));
161
gridLayout->addWidget(m_rangeChooserCombo, 3, 1);
163
// ************* Search text combo box *******************
164
m_searchTextCombo = new CHistoryComboBox(searchGroupBox);
165
sizePolicy2.setHeightForWidth(m_searchTextCombo->sizePolicy().hasHeightForWidth());
166
m_searchTextCombo->setSizePolicy(sizePolicy2);
167
m_searchTextCombo->setFocusPolicy(Qt::WheelFocus);
168
m_searchTextCombo->setProperty("sizeLimit", QVariant(25));
169
m_searchTextCombo->setProperty("duplicatesEnabled", QVariant(false));
170
m_searchTextCombo->setToolTip(tr("The text you want to search for"));
171
m_searchTextCombo->setInsertPolicy(QComboBox::NoInsert);
172
gridLayout->addWidget(m_searchTextCombo, 0, 1);
174
m_modulesLabel = new QLabel(tr("Works:"), searchGroupBox);
175
gridLayout->addWidget(m_modulesLabel, 2, 0);
177
m_modulesCombo = new QComboBox(searchGroupBox);
178
m_modulesCombo->setDuplicatesEnabled(false);
179
gridLayout->addWidget(m_modulesCombo, 2, 1);
181
hboxLayout->addWidget(searchGroupBox);
183
// Set the minimum size before the widgets are populated with data.
184
// Otherwise we will get problems with sizing.
185
setMinimumSize(minimumSizeHint());
188
//set the initial focus
189
m_searchTextCombo->setFocus();
190
// event filter to prevent the Return/Enter presses in the combo box doing something
191
// in the parent widget
192
m_searchTextCombo->installEventFilter(this);
197
void BtSearchOptionsArea::initConnections()
199
QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()),
200
this, SLOT( slotSearchTextEditReturnPressed() )
202
connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules()));
203
connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges()));
204
connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) );
205
connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp()));
206
connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
195
void BtSearchOptionsArea::initConnections() {
196
QObject::connect( m_searchTextCombo->lineEdit(), SIGNAL(returnPressed ()),
197
this, SLOT( slotSearchTextEditReturnPressed() )
199
connect(m_chooseModulesButton, SIGNAL(clicked()), this, SLOT(chooseModules()));
200
connect(m_chooseRangeButton, SIGNAL(clicked()), this, SLOT(setupRanges()));
201
connect(m_modulesCombo, SIGNAL(activated(int)), this, SLOT(moduleListTextSelected(int) ) );
202
connect(m_helpLabel, SIGNAL(linkActivated(QString)), this, SLOT(syntaxHelp()));
203
connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
209
206
/** Sets the modules used by the search. */
210
void BtSearchOptionsArea::setModules( QList<CSwordModuleInfo*> modules )
212
qDebug("BtSearchOptionsArea::setModules");
216
m_modules.clear(); //remove old modules
217
QList<CSwordModuleInfo*>::iterator end_it = modules.end();
219
for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
220
//ToDo: Check for containsRef compat
221
if (*it == 0) { //don't operate on null modules.
224
qDebug() << "new module:" << (*it)->name();
225
if ( !m_modules.contains(*it) ) {
226
m_modules.append( *it );
227
t.append( (*it)->name() );
228
if (*it != modules.last()) {
229
t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...)
233
//m_modulesLabel->setText(t);
234
int existingIndex = m_modulesCombo->findText(t);
235
qDebug() << "index of the module list string which already exists in combobox:" << existingIndex;
236
if (existingIndex >= 0) {
237
m_modulesCombo->removeItem(existingIndex);
239
if (m_modulesCombo->count() > 10) {
240
m_modulesCombo->removeItem(m_modulesCombo->count()-1);
242
m_modulesCombo->insertItem(0, t);
243
m_modulesCombo->setItemData(0, t, Qt::ToolTipRole);
244
m_modulesCombo->setCurrentIndex(0);
245
m_modulesCombo->setToolTip(t);
246
//Save the list in config here, not when deleting, because the history may be used
247
// elsewhere while the dialog is still open
248
QStringList historyList;
249
for (int i = 0; i < m_modulesCombo->count(); ++i) {
250
historyList.append(m_modulesCombo->itemText(i));
252
CBTConfig::set(CBTConfig::searchModulesHistory, historyList);
253
emit( sigSetSearchButtonStatus( (modules.count() != 0) ) );
207
void BtSearchOptionsArea::setModules( QList<CSwordModuleInfo*> modules ) {
208
qDebug() << "BtSearchOptionsArea::setModules";
212
m_modules.clear(); //remove old modules
213
QList<CSwordModuleInfo*>::iterator end_it = modules.end();
215
for (QList<CSwordModuleInfo*>::iterator it(modules.begin()); it != end_it; ++it) {
216
/// \todo Check for containsRef compat
217
if (*it == 0) { //don't operate on null modules.
220
qDebug() << "new module:" << (*it)->name();
221
if ( !m_modules.contains(*it) ) {
222
m_modules.append( *it );
223
t.append( (*it)->name() );
224
if (*it != modules.last()) {
225
t += QString::fromLatin1(", "); // so that it will become a readable list (WLC, LXX, GerLut...)
229
//m_modulesLabel->setText(t);
230
int existingIndex = m_modulesCombo->findText(t);
231
qDebug() << "index of the module list string which already exists in combobox:" << existingIndex;
232
if (existingIndex >= 0) {
233
m_modulesCombo->removeItem(existingIndex);
235
if (m_modulesCombo->count() > 10) {
236
m_modulesCombo->removeItem(m_modulesCombo->count() - 1);
238
m_modulesCombo->insertItem(0, t);
239
m_modulesCombo->setItemData(0, t, Qt::ToolTipRole);
240
m_modulesCombo->setCurrentIndex(0);
241
m_modulesCombo->setToolTip(t);
242
//Save the list in config here, not when deleting, because the history may be used
243
// elsewhere while the dialog is still open
244
QStringList historyList;
245
for (int i = 0; i < m_modulesCombo->count(); ++i) {
246
historyList.append(m_modulesCombo->itemText(i));
248
CBTConfig::set(CBTConfig::searchModulesHistory, historyList);
249
emit sigSetSearchButtonStatus(modules.count() != 0);
256
252
// Catch activated signal of module selector combobox
257
void BtSearchOptionsArea::moduleListTextSelected(int index)
259
qDebug("BtSearchOptionsArea::moduleListTextSelected");
260
//create the module list
261
QString text = m_modulesCombo->itemText(index);
263
QStringList moduleNamesList = text.split(", ");
264
QList<CSwordModuleInfo*> moduleList;
265
foreach(QString name, moduleNamesList) {
266
moduleList.append(CPointers::backend()->findModuleByName(name));
268
//set the list and the combobox list and text
269
setModules(moduleList);
253
void BtSearchOptionsArea::moduleListTextSelected(int index) {
254
qDebug() << "BtSearchOptionsArea::moduleListTextSelected";
255
//create the module list
256
QString text = m_modulesCombo->itemText(index);
258
QStringList moduleNamesList = text.split(", ");
259
QList<CSwordModuleInfo*> moduleList;
260
foreach(QString name, moduleNamesList) {
261
moduleList.append(CPointers::backend()->findModuleByName(name));
263
//set the list and the combobox list and text
264
setModules(moduleList);
272
267
void BtSearchOptionsArea::chooseModules() {
273
QString title(tr("Works to Search in"));
274
QString label(tr("Select the works which should be searched."));
275
CSearchModuleChooserDialog* dlg = new CSearchModuleChooserDialog(this, title, label, modules());
276
connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(setModules(QList<CSwordModuleInfo*>)));
268
QString title(tr("Works to Search in"));
269
QString label(tr("Select the works which should be searched."));
270
CSearchModuleChooserDialog* dlg = new CSearchModuleChooserDialog(this, title, label, modules());
271
connect(dlg, SIGNAL(modulesChanged(QList<CSwordModuleInfo*>, QTreeWidget*)), this, SLOT(setModules(QList<CSwordModuleInfo*>)));
280
275
QList<CSwordModuleInfo*> BtSearchOptionsArea::modules() const {
284
279
void BtSearchOptionsArea::reset() {
285
m_rangeChooserCombo->setCurrentIndex(0);
286
m_searchTextCombo->clearEditText();
280
m_rangeChooserCombo->setCurrentIndex(0);
281
m_searchTextCombo->clearEditText();
289
284
void BtSearchOptionsArea::saveSettings() {
290
CBTConfig::set(CBTConfig::searchTexts, m_searchTextCombo->historyItems());
291
SearchType t = FullType;
292
if (m_typeAndButton->isChecked()) {
295
if (m_typeOrButton->isChecked()) {
298
CBTConfig::set(CBTConfig::searchType, t);
285
CBTConfig::set(CBTConfig::searchTexts, m_searchTextCombo->historyItems());
286
SearchType t = FullType;
287
if (m_typeAndButton->isChecked()) {
290
if (m_typeOrButton->isChecked()) {
293
CBTConfig::set(CBTConfig::searchType, t);
301
296
void BtSearchOptionsArea::readSettings() {
302
QStringList texts = CBTConfig::get(CBTConfig::searchTexts);
303
//for some reason the slot was called when setting the upmost item
304
disconnect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
305
for (int i=0; i<texts.size(); i++)
307
if (texts.at(i).size() > 0)
308
m_searchTextCombo->addItem(texts.at(i));
310
connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
312
m_modulesCombo->insertItems(0, CBTConfig::get(CBTConfig::searchModulesHistory));
313
for (int i = 0; i < m_modulesCombo->count(); ++i) {
314
m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole);
317
int stype = CBTConfig::get(CBTConfig::searchType);
319
case AndType: m_typeAndButton->setChecked(true);
321
case OrType: m_typeOrButton->setChecked(true);
323
default: m_typeFreeButton->setChecked(true);
297
QStringList texts = CBTConfig::get(CBTConfig::searchTexts);
298
//for some reason the slot was called when setting the upmost item
299
disconnect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
300
for (int i = 0; i < texts.size(); i++) {
301
if (texts.at(i).size() > 0)
302
m_searchTextCombo->addItem(texts.at(i));
304
connect(m_searchTextCombo, SIGNAL(editTextChanged(const QString&)), this, SLOT(slotValidateText(const QString&)));
306
m_modulesCombo->insertItems(0, CBTConfig::get(CBTConfig::searchModulesHistory));
307
for (int i = 0; i < m_modulesCombo->count(); ++i) {
308
m_modulesCombo->setItemData(i, m_modulesCombo->itemText(i), Qt::ToolTipRole);
311
int stype = CBTConfig::get(CBTConfig::searchType);
314
m_typeAndButton->setChecked(true);
317
m_typeOrButton->setChecked(true);
320
m_typeFreeButton->setChecked(true);
327
324
void BtSearchOptionsArea::aboutToShow() {
328
m_searchTextCombo->setFocus();
325
m_searchTextCombo->setFocus();
331
328
void BtSearchOptionsArea::setupRanges() {
332
CRangeChooserDialog* chooser = new CRangeChooserDialog(this);
329
CRangeChooserDialog* chooser = new CRangeChooserDialog(this);
338
335
void BtSearchOptionsArea::syntaxHelp() {
340
QString style = QString(
341
"<style type='text/css'>"
342
"h1 a {font-size: medium}"
343
"table {margin-left: 20px}"
345
" border-width: 3px 3px 3px 3px;"
346
" border-style: solid solid solid solid;"
347
" border-color: white white white white;"
348
" background-color: #faf0e6;"
350
"p#links {margin-left: 20px}"
353
//: Don't translate words inside <> tags!
354
//: Translate 'All words' etc. indentically to the Search dialog options.
357
"This help is mainly for 'Full syntax' option. 'All words' and 'Some words' options " "have more limited syntax; <a href='#wildcards'>wildcards</a> and <a " "href='#fields'>text fields</a> are supported for them. Some other syntax features " "may give strange or wrong results with All words/Some words."
362
"<A href='#allsome'>Which words to find</A><br />"
363
"<A href='#grouping'>Grouping and order</A><br />"
364
"<A href='#wildcards'>Wildcards (partial words)</A><br />"
365
"<A href='#fields'>Text fields (different parts of text)</A><br/>"
366
"<A href='#lucene'>Other syntax features</A><br/>"
369
//: Syntax words (AND, OR...) must not be translated.
370
QString whichwords = tr(
371
"<h1><A name='allsome'>Which words to find</A></h1>"
372
"<p>Search terms are separated by spaces. <strong>AND</strong> (all words), " "<strong>OR</strong> (some words) and <strong>NOT</strong> (not the following word) " "can be added between the words. If none is added explicitly OR is used " "automatically. '<strong>+</strong>word' means the word must be in the results, " "'<strong>-</strong>word' means it must not be in the results.</p>");
374
//: In examples words to be searched for may be translated, but syntax words (AND, OR...) must not be translated.
375
QString whichwordstable = tr(
377
"<td>jesus AND god</td><td>Finds verses with both 'Jesus' and 'God'</td>"
379
"<td>jesus OR god</td><td>Finds verses with 'Jesus' or 'God' or both</td>"
381
"<td>jesus NOT god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
383
"<td>+jesus -god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
384
"</tr></table></p>");
386
QString grouping = tr(
387
"<h1><A name='grouping'>Grouping and order</A></h1>"
388
"<p>Words can be grouped with <strong>parenthesis</strong>. "
389
"Strict word order can be defined with <strong>quotes</strong>.</p>");
391
QString groupingtable = tr(
393
"<td>(a AND b) OR c</td><td>Finds verses with both 'a' AND 'b', and verses with 'c'</td>"
395
"<td>\"says lord\"</td><td>Finds e.g. '...Isaiah says, \"Lord...' but not '...says the LORD'</td>"
397
"<td>\"says the lord\"</td><td>Finds all verses with 'says the LORD'</td>"
398
"</tr></table></p>");
400
QString wildcards = tr(
401
"<h1><A name='wildcards'>Wildcards (partial words)</A></h1>"
402
"<p>'<strong>*</strong>' matches any sequence of 0 or more characters, while '<strong>?</strong>' matches any single character. A wildcard can not be used in the beginning of a word.</p>");
404
QString wildcardstable = tr(
406
"<td>a*</td><td>All words beginning with 'a'</td>"
408
"<td>a*a</td><td>'Assyria', 'aroma', 'abba' etc.</td>"
410
"<td>a?</td><td>'at' and 'an'</td>"
412
"<td>a??a</td><td>'abba', 'area', 'Asia' etc.</td>"
413
"</tr></table></p>");
416
"<h1><A name='fields'>Text fields (different parts of text)</A></h1>"
417
"<p>Available text fields:<br /><table>"
418
"<tr><td>heading:</td><td>Searches headings</td></tr>"
419
"<tr><td>footnote:</td><td>Searches footnotes</td></tr>"
420
"<tr><td>strong:</td><td>Searches Strong's numbers</td></tr>"
421
"<tr><td>morph:</td><td>Searches morphology codes</td></tr></table></p>");
423
QString fieldstable = tr(
424
"<p>Examples:<br /><table>"
425
"<tr><td>heading:Jesus</td><td>Finds headings with 'Jesus'</td></tr>"
426
"<tr><td>footnote:Jesus AND footnote:said</td><td>Finds footnotes with 'Jesus' and 'said'</td></tr>"
427
"<tr><td>strong:G846</td><td>Finds verses with Strong's Greek number 846</td></tr>"
428
"<tr><td>morph:\"N-NSF\"</td><td>Finds verses with morphology code 'N-NSF'</td>"
429
"</tr></table></p>");
432
"<h1><A name='lucene'>Other syntax features</A></h1>"
433
"<p>BibleTime uses the CLucene search engine. You can read more on the <a href='http://lucene.apache.org/java/1_4_3/queryparsersyntax.html'>lucene syntax web page</a> (in external browser).</p>");
435
QString syntax = style + intro + links + whichwords + whichwordstable +
436
grouping + groupingtable + wildcards + wildcardstable +
437
fields + fieldstable + lucene;
439
BtTabHtmlDialog* dlg = new BtTabHtmlDialog(tr("Search Syntax Help"), 0, this);
440
dlg->setHtml(syntax);
337
QString style = QString(
338
"<style type='text/css'>"
339
"h1 a {font-size: medium}"
340
"table {margin-left: 20px}"
342
" border-width: 3px 3px 3px 3px;"
343
" border-style: solid solid solid solid;"
344
" border-color: white white white white;"
345
" background-color: #faf0e6;"
347
"p#links {margin-left: 20px}"
350
//: Don't translate words inside <> tags!
351
//: Translate 'All words' etc. indentically to the Search dialog options.
354
"This help is mainly for 'Full syntax' option. 'All words' and 'Some words' options " "have more limited syntax; <a href='#wildcards'>wildcards</a> and <a " "href='#fields'>text fields</a> are supported for them. Some other syntax features " "may give strange or wrong results with All words/Some words."
359
"<A href='#allsome'>Which words to find</A><br />"
360
"<A href='#grouping'>Grouping and order</A><br />"
361
"<A href='#wildcards'>Wildcards (partial words)</A><br />"
362
"<A href='#fields'>Text fields (different parts of text)</A><br/>"
363
"<A href='#lucene'>Other syntax features</A><br/>"
366
//: Syntax words (AND, OR...) must not be translated.
367
QString whichwords = tr(
368
"<h1><A name='allsome'>Which words to find</A></h1>"
369
"<p>Search terms are separated by spaces. <strong>AND</strong> (all words), " "<strong>OR</strong> (some words) and <strong>NOT</strong> (not the following word) " "can be added between the words. If none is added explicitly OR is used " "automatically. '<strong>+</strong>word' means the word must be in the results, " "'<strong>-</strong>word' means it must not be in the results.</p>");
371
//: In examples words to be searched for may be translated, but syntax words (AND, OR...) must not be translated.
372
QString whichwordstable = tr(
374
"<td>jesus AND god</td><td>Finds verses with both 'Jesus' and 'God'</td>"
376
"<td>jesus OR god</td><td>Finds verses with 'Jesus' or 'God' or both</td>"
378
"<td>jesus NOT god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
380
"<td>+jesus -god</td><td>Finds verses with 'Jesus' but with no 'God'</td>"
381
"</tr></table></p>");
383
QString grouping = tr(
384
"<h1><A name='grouping'>Grouping and order</A></h1>"
385
"<p>Words can be grouped with <strong>parenthesis</strong>. "
386
"Strict word order can be defined with <strong>quotes</strong>.</p>");
388
QString groupingtable = tr(
390
"<td>(a AND b) OR c</td><td>Finds verses with both 'a' AND 'b', and verses with 'c'</td>"
392
"<td>\"says lord\"</td><td>Finds e.g. '...Isaiah says, \"Lord...' but not '...says the LORD'</td>"
394
"<td>\"says the lord\"</td><td>Finds all verses with 'says the LORD'</td>"
395
"</tr></table></p>");
397
QString wildcards = tr(
398
"<h1><A name='wildcards'>Wildcards (partial words)</A></h1>"
399
"<p>'<strong>*</strong>' matches any sequence of 0 or more characters, while '<strong>?</strong>' matches any single character. A wildcard can not be used in the beginning of a word.</p>");
401
QString wildcardstable = tr(
403
"<td>a*</td><td>All words beginning with 'a'</td>"
405
"<td>a*a</td><td>'Assyria', 'aroma', 'abba' etc.</td>"
407
"<td>a?</td><td>'at' and 'an'</td>"
409
"<td>a??a</td><td>'abba', 'area', 'Asia' etc.</td>"
410
"</tr></table></p>");
413
"<h1><A name='fields'>Text fields (different parts of text)</A></h1>"
414
"<p>Available text fields:<br /><table>"
415
"<tr><td>heading:</td><td>Searches headings</td></tr>"
416
"<tr><td>footnote:</td><td>Searches footnotes</td></tr>"
417
"<tr><td>strong:</td><td>Searches Strong's numbers</td></tr>"
418
"<tr><td>morph:</td><td>Searches morphology codes</td></tr></table></p>");
420
QString fieldstable = tr(
421
"<p>Examples:<br /><table>"
422
"<tr><td>heading:Jesus</td><td>Finds headings with 'Jesus'</td></tr>"
423
"<tr><td>footnote:Jesus AND footnote:said</td><td>Finds footnotes with 'Jesus' and 'said'</td></tr>"
424
"<tr><td>strong:G846</td><td>Finds verses with Strong's Greek number 846</td></tr>"
425
"<tr><td>morph:\"N-NSF\"</td><td>Finds verses with morphology code 'N-NSF'</td>"
426
"</tr></table></p>");
429
"<h1><A name='lucene'>Other syntax features</A></h1>"
430
"<p>BibleTime uses the CLucene search engine. You can read more on the <a href='http://lucene.apache.org/java/1_4_3/queryparsersyntax.html'>lucene syntax web page</a> (in external browser).</p>");
432
QString syntax = style + intro + links + whichwords + whichwordstable +
433
grouping + groupingtable + wildcards + wildcardstable +
434
fields + fieldstable + lucene;
436
BtTabHtmlDialog* dlg = new BtTabHtmlDialog(tr("Search Syntax Help"), 0, this);
437
dlg->setHtml(syntax);
444
441
void BtSearchOptionsArea::refreshRanges() {
445
//the first option is fixed, the others can be edited using the "Setup ranges" button.
446
m_rangeChooserCombo->clear();
447
m_rangeChooserCombo->insertItem(0, QString("[") + tr("No search scope") + QString("]"));
448
//TODO: what about this?
449
//m_rangeChooserCombo->insertItem(tr("Last search result"));
442
//the first option is fixed, the others can be edited using the "Setup ranges" button.
443
m_rangeChooserCombo->clear();
444
m_rangeChooserCombo->insertItem(0, QString("[") + tr("No search scope") + QString("]"));
445
/// \todo what about this?
446
//m_rangeChooserCombo->insertItem(tr("Last search result"));
451
//insert the user-defined ranges
452
m_rangeChooserCombo->insertItems(1, CBTConfig::get(CBTConfig::searchScopes).keys());
448
//insert the user-defined ranges
449
m_rangeChooserCombo->insertItems(1, CBTConfig::get(CBTConfig::searchScopes).keys());
456
453
sword::ListKey BtSearchOptionsArea::searchScope() {
457
if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope"
458
CBTConfig::StringMap map = CBTConfig::get(CBTConfig::searchScopes);
459
QString scope = map[ m_rangeChooserCombo->currentText() ];
460
if (!scope.isEmpty()) {
461
return sword::VerseKey().ParseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true);
464
return sword::ListKey();
454
if (m_rangeChooserCombo->currentIndex() > 0) { //is not "no scope"
455
CBTConfig::StringMap map = CBTConfig::get(CBTConfig::searchScopes);
456
QString scope = map[ m_rangeChooserCombo->currentText() ];
457
if (!scope.isEmpty()) {
458
return sword::VerseKey().ParseVerseList( (const char*)scope.toUtf8(), "Genesis 1:1", true);
461
return sword::ListKey();
467
464
bool BtSearchOptionsArea::hasSearchScope() {
468
return (searchScope().Count() > 0);
471
void BtSearchOptionsArea::addToHistory(const QString& text)
473
m_searchTextCombo->addToHistory(text);
476
void BtSearchOptionsArea::slotSearchTextEditReturnPressed()
478
qDebug("BtSearchOptionsArea::slotSearchTextEditReturnPressed");
479
m_searchTextCombo->addToHistory( m_searchTextCombo->currentText() );
480
emit sigStartSearch();
483
bool BtSearchOptionsArea::eventFilter(QObject* obj, QEvent* event)
485
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
486
//qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
487
if (obj == m_searchTextCombo->view() || obj == m_searchTextCombo || obj == m_searchTextCombo->lineEdit()) {
488
//qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
490
// don't handle this event in parent
495
return QWidget::eventFilter(obj, event);
498
void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/)
465
return (searchScope().Count() > 0);
468
void BtSearchOptionsArea::addToHistory(const QString& text) {
469
m_searchTextCombo->addToHistory(text);
472
void BtSearchOptionsArea::slotSearchTextEditReturnPressed() {
473
qDebug() << "BtSearchOptionsArea::slotSearchTextEditReturnPressed";
474
m_searchTextCombo->addToHistory( m_searchTextCombo->currentText() );
475
emit sigStartSearch();
478
bool BtSearchOptionsArea::eventFilter(QObject* obj, QEvent* event) {
479
if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
480
//qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
481
if (obj == m_searchTextCombo->view() || obj == m_searchTextCombo || obj == m_searchTextCombo->lineEdit()) {
482
//qDebug() << "BtSearchOptionsArea::eventFilter" << obj << event;
484
// don't handle this event in parent
489
return QWidget::eventFilter(obj, event);
492
void BtSearchOptionsArea::slotValidateText(const QString& /*newText*/) {
500
493
// static const QRegExp re("\\b(AND|OR)\\b");
501
494
// qDebug() << "new text:" << newText;
502
495
// qDebug() << "contains:" << (newText.contains(re));