130 << QLatin1String(")") << QLatin1String(":") << QLatin1String("^") |
146 << QLatin1String(")") << QLatin1String(":") << QLatin1String("^") |
131 << QLatin1String("[") << QLatin1String("]") << QLatin1String("{") |
147 << QLatin1String("[") << QLatin1String("]") << QLatin1String("{") |
132 << QLatin1String("}") << QLatin1String("~"); |
148 << QLatin1String("}") << QLatin1String("~"); |
133 |
149 |
134 // make sure we won't end up with an empty string |
150 // make sure we won't end up with an empty string |
135 foreach (const QString escapeChar, escapableCharsList) { |
151 foreach (const QString &escapeChar, escapableCharsList) { |
136 if (retValue.contains(escapeChar)) |
152 if (retValue.contains(escapeChar)) |
137 retValue.replace(escapeChar, QLatin1String("")); |
153 retValue.replace(escapeChar, QLatin1String("")); |
138 } |
154 } |
139 if (retValue.trimmed().isEmpty()) |
155 if (retValue.trimmed().isEmpty()) |
140 return retValue; |
156 return retValue; |
141 |
157 |
142 retValue = text; // now realy escape the string... |
158 retValue = text; // now really escape the string... |
143 foreach (const QString escapeChar, escapableCharsList) { |
159 foreach (const QString &escapeChar, escapableCharsList) { |
144 if (retValue.contains(escapeChar)) |
160 if (retValue.contains(escapeChar)) |
145 retValue.replace(escapeChar, escape + escapeChar); |
161 retValue.replace(escapeChar, escape + escapeChar); |
146 } |
162 } |
147 return retValue; |
163 return retValue; |
148 } |
164 } |
299 } else { |
315 } else { |
300 const QRegExp exp(QLatin1String("\\s+")); |
316 const QRegExp exp(QLatin1String("\\s+")); |
301 QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); |
317 QStringList lst = similarQuery->text().split(exp, QString::SkipEmptyParts); |
302 if (!lst.isEmpty()) { |
318 if (!lst.isEmpty()) { |
303 QStringList fuzzy; |
319 QStringList fuzzy; |
304 foreach (const QString term, lst) |
320 foreach (const QString &term, lst) |
305 fuzzy += buildTermList(escapeString(term)); |
321 fuzzy += buildTermList(escapeString(term)); |
306 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy)); |
322 queryList.append(QHelpSearchQuery(QHelpSearchQuery::FUZZY, fuzzy)); |
307 } |
323 } |
308 |
324 |
309 lst = withoutQuery->text().split(exp, QString::SkipEmptyParts); |
325 lst = withoutQuery->text().split(exp, QString::SkipEmptyParts); |
310 if (!lst.isEmpty()) { |
326 if (!lst.isEmpty()) { |
311 QStringList without; |
327 QStringList without; |
312 foreach (const QString term, lst) |
328 foreach (const QString &term, lst) |
313 without.append(escapeString(term)); |
329 without.append(escapeString(term)); |
314 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without)); |
330 queryList.append(QHelpSearchQuery(QHelpSearchQuery::WITHOUT, without)); |
315 } |
331 } |
316 |
332 |
317 if (!exactQuery->text().isEmpty()) { |
333 if (!exactQuery->text().isEmpty()) { |
406 |
429 |
407 QVBoxLayout *vLayout = new QVBoxLayout(this); |
430 QVBoxLayout *vLayout = new QVBoxLayout(this); |
408 vLayout->setMargin(0); |
431 vLayout->setMargin(0); |
409 |
432 |
410 QHBoxLayout* hBoxLayout = new QHBoxLayout(); |
433 QHBoxLayout* hBoxLayout = new QHBoxLayout(); |
411 QLabel *label = new QLabel(tr("Search for:"), this); |
434 d->simpleSearchLabel = new QLabel(this); |
412 d->defaultQuery = new QLineEdit(this); |
435 d->defaultQuery = new QLineEdit(this); |
413 d->defaultQuery->setCompleter(&d->searchCompleter); |
436 d->defaultQuery->setCompleter(&d->searchCompleter); |
414 d->prevQueryButton = new QToolButton(this); |
437 d->prevQueryButton = new QToolButton(this); |
415 d->prevQueryButton->setArrowType(Qt::LeftArrow); |
438 d->prevQueryButton->setArrowType(Qt::LeftArrow); |
416 d->prevQueryButton->setToolTip(tr("Previous search")); |
|
417 d->prevQueryButton->setEnabled(false); |
439 d->prevQueryButton->setEnabled(false); |
418 d->nextQueryButton = new QToolButton(this); |
440 d->nextQueryButton = new QToolButton(this); |
419 d->nextQueryButton->setArrowType(Qt::RightArrow); |
441 d->nextQueryButton->setArrowType(Qt::RightArrow); |
420 d->nextQueryButton->setToolTip(tr("Next search")); |
|
421 d->nextQueryButton->setEnabled(false); |
442 d->nextQueryButton->setEnabled(false); |
422 d->searchButton = new QPushButton(tr("Search"), this); |
443 d->searchButton = new QPushButton(this); |
423 hBoxLayout->addWidget(label); |
444 hBoxLayout->addWidget(d->simpleSearchLabel); |
424 hBoxLayout->addWidget(d->defaultQuery); |
445 hBoxLayout->addWidget(d->defaultQuery); |
425 hBoxLayout->addWidget(d->prevQueryButton); |
446 hBoxLayout->addWidget(d->prevQueryButton); |
426 hBoxLayout->addWidget(d->nextQueryButton); |
447 hBoxLayout->addWidget(d->nextQueryButton); |
427 hBoxLayout->addWidget(d->searchButton); |
448 hBoxLayout->addWidget(d->searchButton); |
428 |
449 |
437 hBoxLayout = new QHBoxLayout(); |
458 hBoxLayout = new QHBoxLayout(); |
438 d->showHideAdvancedSearchButton = new QToolButton(this); |
459 d->showHideAdvancedSearchButton = new QToolButton(this); |
439 d->showHideAdvancedSearchButton->setText(QLatin1String("+")); |
460 d->showHideAdvancedSearchButton->setText(QLatin1String("+")); |
440 d->showHideAdvancedSearchButton->setMinimumSize(25, 20); |
461 d->showHideAdvancedSearchButton->setMinimumSize(25, 20); |
441 |
462 |
442 label = new QLabel(tr("Advanced search"), this); |
463 d->advancedSearchLabel = new QLabel(this); |
443 QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); |
464 QSizePolicy sizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred); |
444 sizePolicy.setHeightForWidth(label->sizePolicy().hasHeightForWidth()); |
465 sizePolicy.setHeightForWidth(d->advancedSearchLabel->sizePolicy().hasHeightForWidth()); |
445 label->setSizePolicy(sizePolicy); |
466 d->advancedSearchLabel->setSizePolicy(sizePolicy); |
446 |
467 |
447 QFrame* hLine = new QFrame(this); |
468 QFrame* hLine = new QFrame(this); |
448 hLine->setFrameStyle(QFrame::HLine); |
469 hLine->setFrameStyle(QFrame::HLine); |
449 hBoxLayout->addWidget(d->showHideAdvancedSearchButton); |
470 hBoxLayout->addWidget(d->showHideAdvancedSearchButton); |
450 hBoxLayout->addWidget(label); |
471 hBoxLayout->addWidget(d->advancedSearchLabel); |
451 hBoxLayout->addWidget(hLine); |
472 hBoxLayout->addWidget(hLine); |
452 |
473 |
453 vLayout->addLayout(hBoxLayout); |
474 vLayout->addLayout(hBoxLayout); |
454 |
475 |
455 // setup advanced search layout |
476 // setup advanced search layout |
456 d->advancedSearchWidget = new QWidget(this); |
477 d->advancedSearchWidget = new QWidget(this); |
457 QGridLayout *gLayout = new QGridLayout(d->advancedSearchWidget); |
478 QGridLayout *gLayout = new QGridLayout(d->advancedSearchWidget); |
458 gLayout->setMargin(0); |
479 gLayout->setMargin(0); |
459 |
480 |
460 label = new QLabel(tr("words <B>similar</B> to:"), this); |
481 d->similarLabel = new QLabel(this); |
461 gLayout->addWidget(label, 0, 0); |
482 gLayout->addWidget(d->similarLabel, 0, 0); |
462 d->similarQuery = new QLineEdit(this); |
483 d->similarQuery = new QLineEdit(this); |
463 d->similarQuery->setCompleter(&d->searchCompleter); |
484 d->similarQuery->setCompleter(&d->searchCompleter); |
464 gLayout->addWidget(d->similarQuery, 0, 1); |
485 gLayout->addWidget(d->similarQuery, 0, 1); |
465 |
486 |
466 label = new QLabel(tr("<B>without</B> the words:"), this); |
487 d->withoutLabel = new QLabel(this); |
467 gLayout->addWidget(label, 1, 0); |
488 gLayout->addWidget(d->withoutLabel, 1, 0); |
468 d->withoutQuery = new QLineEdit(this); |
489 d->withoutQuery = new QLineEdit(this); |
469 d->withoutQuery->setCompleter(&d->searchCompleter); |
490 d->withoutQuery->setCompleter(&d->searchCompleter); |
470 gLayout->addWidget(d->withoutQuery, 1, 1); |
491 gLayout->addWidget(d->withoutQuery, 1, 1); |
471 |
492 |
472 label = new QLabel(tr("with <B>exact phrase</B>:"), this); |
493 d->exactLabel = new QLabel(this); |
473 gLayout->addWidget(label, 2, 0); |
494 gLayout->addWidget(d->exactLabel, 2, 0); |
474 d->exactQuery = new QLineEdit(this); |
495 d->exactQuery = new QLineEdit(this); |
475 d->exactQuery->setCompleter(&d->searchCompleter); |
496 d->exactQuery->setCompleter(&d->searchCompleter); |
476 gLayout->addWidget(d->exactQuery, 2, 1); |
497 gLayout->addWidget(d->exactQuery, 2, 1); |
477 |
498 |
478 label = new QLabel(tr("with <B>all</B> of the words:"), this); |
499 d->allLabel = new QLabel(this); |
479 gLayout->addWidget(label, 3, 0); |
500 gLayout->addWidget(d->allLabel, 3, 0); |
480 d->allQuery = new QLineEdit(this); |
501 d->allQuery = new QLineEdit(this); |
481 d->allQuery->setCompleter(&d->searchCompleter); |
502 d->allQuery->setCompleter(&d->searchCompleter); |
482 gLayout->addWidget(d->allQuery, 3, 1); |
503 gLayout->addWidget(d->allQuery, 3, 1); |
483 |
504 |
484 label = new QLabel(tr("with <B>at least one</B> of the words:"), this); |
505 d->atLeastLabel = new QLabel(this); |
485 gLayout->addWidget(label, 4, 0); |
506 gLayout->addWidget(d->atLeastLabel, 4, 0); |
486 d->atLeastQuery = new QLineEdit(this); |
507 d->atLeastQuery = new QLineEdit(this); |
487 d->atLeastQuery->setCompleter(&d->searchCompleter); |
508 d->atLeastQuery->setCompleter(&d->searchCompleter); |
488 gLayout->addWidget(d->atLeastQuery, 4, 1); |
509 gLayout->addWidget(d->atLeastQuery, 4, 1); |
489 |
510 |
490 vLayout->addWidget(d->advancedSearchWidget); |
511 vLayout->addWidget(d->advancedSearchWidget); |
491 d->advancedSearchWidget->hide(); |
512 d->advancedSearchWidget->hide(); |
|
513 |
|
514 d->retranslate(); |
492 |
515 |
493 connect(d->exactQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
516 connect(d->exactQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
494 connect(d->similarQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
517 connect(d->similarQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
495 connect(d->withoutQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
518 connect(d->withoutQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
496 connect(d->allQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |
519 connect(d->allQuery, SIGNAL(returnPressed()), this, SIGNAL(search())); |