17 #include <QGridLayout>
19 #include <QHBoxLayout>
22 #include <QPushButton>
23 #include <QRadioButton>
24 #include "../../backend/config/btconfig.h"
25 #include "../../backend/drivers/btconstmoduleset.h"
26 #include "../../backend/drivers/cswordmoduleinfo.h"
27 #include "../../backend/managers/cswordbackend.h"
28 #include "../../util/btconnect.h"
29 #include "../../util/cresmgr.h"
30 #include "../../util/tool.h"
37 auto const SearchTypeKey = QStringLiteral(
"GUI/SearchDialog/searchType");
88 QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
89 this->setSizePolicy(sizePolicy);
108 m_searchButton->setToolTip(tr(
"Start to search the text in the chosen works"));
122 QHBoxLayout* typeSelectorLayout =
new QHBoxLayout();
123 int tsLeft, tsTop, tsRight, tsBottom;
125 typeSelectorLayout->getContentsMargins(&tsLeft, &tsTop, &tsRight, &tsBottom);
126 typeSelectorLayout->setContentsMargins(
131 typeSelectorLayout->setSpacing(typeSelectorLayout->spacing()
133 QHBoxLayout* fullButtonLayout =
new QHBoxLayout();
140 m_typeAndButton->setToolTip(tr(
"All of the words (AND is added between the words)"));
141 m_typeOrButton->setToolTip(tr(
"Some of the words (OR is added between the words)"));
144 m_helpLabel =
new QLabel(tr(
" (<a href='syntax_help'>full syntax</a>)"));
145 m_helpLabel->setToolTip(tr(
"Click the link to get help for search syntax"));
151 typeSelectorLayout->addLayout(fullButtonLayout);
152 gridLayout->addLayout(typeSelectorLayout, 1, 1, 1, -1, Qt::AlignLeft | Qt::AlignTop);
161 QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Fixed);
162 sizePolicy2.setHorizontalStretch(0);
163 sizePolicy2.setVerticalStretch(0);
166 m_rangeChooserCombo->setToolTip(tr(
"Choose the scope (books/chapters/verses to search in).<br />Applicable for Bibles and commentaries."));
171 sizePolicy2.setHeightForWidth(
m_searchTextCombo->sizePolicy().hasHeightForWidth());
191 setMinimumSize(minimumSizeHint());
210 std::move(startSearch));
219 [
this](
int const index) {
221 for (
auto const & name
223 QStringLiteral(
", ")))
232 dlg->setAttribute(Qt::WA_DeleteOnClose);
237 this, &BtSearchOptionsArea::slotValidateText);
246 for (
auto *
const modulePtr :
modules) {
250 qDebug() <<
"new module:" << modulePtr->name();
253 t.append(modulePtr->name());
254 if (modulePtr !=
modules.last())
255 t += QStringLiteral(
", ");
260 qDebug() <<
"index of the module list string which already exists in combobox:" << existingIndex;
261 if (existingIndex >= 0) {
273 QStringList historyList;
283 for (
auto const & value
285 QStringLiteral(
"history/searchModuleHistory")))
286 for (
auto const & name : value.split(QStringLiteral(
", ")))
287 moduleSet.insert(name);
288 return moduleSet.values();
295 if (dlg.exec() == QDialog::Accepted) {
304 QStringLiteral(
"searchScopeCurrent")));
330 QStringLiteral(
"properties/searchTexts"));
334 this, &BtSearchOptionsArea::slotValidateText);
336 for (
auto const & text : texts)
341 this, &BtSearchOptionsArea::slotValidateText);
347 QStringLiteral(
"history/searchModuleHistory")));
382 if (!scope.isEmpty())
385 return sword::ListKey();
393 if (event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease) {
401 return QWidget::eventFilter(obj, event);
405 void BtSearchOptionsArea::slotValidateText(QString
const & newText) {
406 static const QRegExp re(
"\\b(AND|OR)\\b");
407 if (newText.isEmpty() || !newText.contains(re)) {
412 tr(
"All of the words (AND is added between the words)"));
421 tr(
"Full syntax is used because text includes AND or OR"));
423 tr(
"Full syntax is used because text includes AND or OR"));
BtConfig & btConfig()
This is a shortchand for BtConfig::getInstance().
QList< CSwordModuleInfo const * > BtConstModuleList
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
void setValue(QString const &key, T const &value)
Sets a value for a key.
static sword::ListKey parseVerseListWithModules(const QString &data, const QStringList &scopeModules)
StringMap getSearchScopesForCurrentLocale(const QStringList &scopeModules)
void setCheckedModules(BtConstModuleSet const &modules)
BtConstModuleSet checkedModules() const
CSwordModuleInfo * findModuleByName(const QString &name) const
Searches for a module with the given name.
static CSwordBackend & instance() noexcept
CHistoryComboBox * m_searchTextCombo
QRadioButton * m_typeAndButton
BtConstModuleList m_modules
void setSearchText(const QString &text)
QComboBox * m_rangeChooserCombo
QPushButton * m_searchButton
QLabel * m_searchScopeLabel
QRadioButton * m_typeFreeButton
BtSearchOptionsArea(QWidget *parent=nullptr)
sword::ListKey searchScope()
QComboBox * m_modulesCombo
~BtSearchOptionsArea() override
BtConstModuleList const & modules() const
bool eventFilter(QObject *obj, QEvent *event) override
QGroupBox * searchGroupBox
QPushButton * m_chooseRangeButton
QStringList getUniqueWorksList()
QString searchText() const
QPushButton * m_chooseModulesButton
QLabel * m_searchTextLabel
void setModules(const BtConstModuleList &modules)
QRadioButton * m_typeOrButton
CSwordModuleSearch::SearchType searchType()
void addToHistory(const QString &text)
QStringList historyItems() const
void addToHistory(const QString &item)