BibleTime
btstandardworkstab.cpp
Go to the documentation of this file.
1 /*********
2 *
3 * In the name of the Father, and of the Son, and of the Holy Spirit.
4 *
5 * This file is part of BibleTime's source code, https://bibletime.info/
6 *
7 * Copyright 1999-2021 by the BibleTime developers.
8 * The BibleTime source code is licensed under the GNU General Public License
9 * version 2.0.
10 *
11 **********/
12 
13 #include "btstandardworkstab.h"
14 
15 #include <QComboBox>
16 #include <QFormLayout>
17 #include <QLabel>
18 #include <QSizePolicy>
19 #include <QStringList>
20 #include <QVBoxLayout>
21 #include "../../backend/config/btconfig.h"
22 #include "../../backend/drivers/cswordlexiconmoduleinfo.h"
23 #include "../../backend/drivers/cswordmoduleinfo.h"
24 #include "../../backend/managers/cswordbackend.h"
25 #include "../../util/tool.h"
26 #include "cswordsettings.h"
27 
28 
30  : QWidget(parent)
31 {
32  QVBoxLayout *mainLayout = new QVBoxLayout(this);
33  mainLayout->setContentsMargins(5, 5, 5, 5);
34  mainLayout->setSpacing(2);
35 
36  m_explanationLabel = new QLabel(this);
37  m_explanationLabel->setSizePolicy(QSizePolicy::MinimumExpanding,
38  QSizePolicy::Preferred);
39  m_explanationLabel->setMaximumHeight(50);
40  m_explanationLabel->setMinimumWidth(300);
41  mainLayout->addWidget(m_explanationLabel);
42 
43  QFormLayout *formLayout = new QFormLayout;
44  formLayout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
45 
46  static constexpr auto const toLexModule =
47  [](CSwordModuleInfo const * module)
48  { return static_cast<CSwordLexiconModuleInfo const *>(module); };
49 #define STANDARD_WORKS_TAB_ADD_ROW(fname,...) \
50  if (true) { \
51  m_ ## fname ## Label = new QLabel(this); \
52  m_ ## fname ## Combo = new QComboBox(this); \
53  formLayout->addRow(m_ ## fname ## Label, m_ ## fname ## Combo); \
54  auto const * const defaultModule = \
55  btConfig().getDefaultSwordModuleByType(#fname); \
56  for (auto const * const m : CSwordBackend::instance().moduleList()) { \
57  if (m->type() == CSwordModuleInfo::__VA_ARGS__) { \
58  QString itemText; \
59  if (auto description = \
60  m->config(CSwordModuleInfo::Description); \
61  !description.isEmpty()) \
62  { \
63  itemText = \
64  tr("%1: %2", \
65  "module name: module description").arg( \
66  m->name(), \
67  std::move(description)); \
68  } else { \
69  itemText = m->name(); \
70  } \
71  auto itemData = \
72  QVariant::fromValue( \
73  const_cast<void *>(static_cast<void const *>(m))); \
74  m_ ## fname ## Combo->addItem(std::move(itemText), \
75  std::move(itemData)); \
76  if (m == defaultModule) \
77  m_ ## fname ## Combo->setCurrentIndex( \
78  m_ ## fname ## Combo->count() - 1); \
79  } \
80  } \
81  } else (void) 0
82 
83  STANDARD_WORKS_TAB_ADD_ROW(standardBible, Bible);
84  STANDARD_WORKS_TAB_ADD_ROW(standardCommentary, Commentary);
86  standardLexicon,
87  Lexicon
88  && !(m->category() == CSwordModuleInfo::DailyDevotional)
90  && toLexModule(m)->hasStrongsKeys())
92  && toLexModule(m)->hasStrongsKeys())
96  standardDailyDevotional,
97  Lexicon && m->category() == CSwordModuleInfo::DailyDevotional);
99  standardHebrewStrongsLexicon,
100  Lexicon
102  && toLexModule(m)->hasStrongsKeys());
104  standardGreekStrongsLexicon,
105  Lexicon
107  && toLexModule(m)->hasStrongsKeys());
109  standardHebrewMorphLexicon,
112  standardGreekMorphLexicon,
114 #undef STANDARD_WORKS_TAB_ADD_ROW
115 
116  mainLayout->addLayout(formLayout);
117  mainLayout->addStretch();
118 
119  retranslateUi();
120 }
121 
122 #define STANDARD_WORKS_SET_DEFAULT(name) \
123  btConfig().setDefaultSwordModuleByType(\
124  #name, \
125  static_cast<CSwordModuleInfo const *>( \
126  m_ ## name ## Combo->currentData().value<void *>()))
128  STANDARD_WORKS_SET_DEFAULT(standardBible);
129  STANDARD_WORKS_SET_DEFAULT(standardCommentary);
130  STANDARD_WORKS_SET_DEFAULT(standardLexicon);
131  STANDARD_WORKS_SET_DEFAULT(standardDailyDevotional);
132  STANDARD_WORKS_SET_DEFAULT(standardHebrewStrongsLexicon);
133  STANDARD_WORKS_SET_DEFAULT(standardGreekStrongsLexicon);
134  STANDARD_WORKS_SET_DEFAULT(standardHebrewMorphLexicon);
135  STANDARD_WORKS_SET_DEFAULT(standardGreekMorphLexicon);
136 }
137 #undef STANDARD_WORKS_SET_DEFAULT
138 
141  m_explanationLabel, QString(),
142  tr("Standard works are used when no particular work is specified, for "
143  "example when a hyperlink into a Bible or lexicon was clicked."));
144 
145  m_standardBibleLabel->setText(tr("Bible:"));
146  m_standardBibleCombo->setToolTip(
147  tr("The standard Bible is used when a hyperlink into a Bible "
148  "is clicked"));
149 
150  m_standardCommentaryLabel->setText(tr("Commentary:"));
151  m_standardCommentaryCombo->setToolTip(
152  tr("The standard commentary is used when a hyperlink into a "
153  "commentary is clicked"));
154 
155  m_standardLexiconLabel->setText(tr("Lexicon:"));
156  m_standardLexiconCombo->setToolTip(
157  tr("The standard lexicon is used when a hyperlink into a "
158  "lexicon is clicked"));
159 
160  m_standardDailyDevotionalLabel->setText(tr("Daily devotional:"));
161  m_standardDailyDevotionalCombo->setToolTip(
162  tr("The standard devotional will be used to display a short "
163  "start up devotional"));
164 
165  m_standardHebrewStrongsLexiconLabel->setText(
166  tr("Hebrew Strong's lexicon:"));
167  m_standardHebrewStrongsLexiconCombo->setToolTip(
168  tr("The standard Hebrew lexicon is used when a hyperlink into "
169  "a Hebrew lexicon is clicked"));
170 
171  m_standardGreekStrongsLexiconLabel->setText(tr("Greek Strong's lexicon:"));
172  m_standardGreekStrongsLexiconCombo->setToolTip(
173  tr("The standard Greek lexicon is used when a hyperlink into a "
174  "Greek lexicon is clicked"));
175 
176  m_standardHebrewMorphLexiconLabel->setText(
177  tr("Hebrew morphological lexicon:"));
178  m_standardHebrewMorphLexiconCombo->setToolTip(
179  tr("The standard morphological lexicon for Hebrew texts is "
180  "used when a hyperlink of a morphological tag in a Hebrew "
181  "text is clicked"));
182 
183  m_standardGreekMorphLexiconLabel->setText(
184  tr("Greek morphological lexicon:"));
185  m_standardGreekMorphLexiconCombo->setToolTip(
186  tr("The standard morphological lexicon for Greek texts is used "
187  "when a hyperlink of a morphological tag in a Greek text is "
188  "clicked"));
189 }
#define STANDARD_WORKS_SET_DEFAULT(name)
#define STANDARD_WORKS_TAB_ADD_ROW(fname,...)
BtStandardWorksTab(CSwordSettingsPage *parent)
void initExplanationLabel(QLabel *const label, const QString &heading, const QString &text)
Initializes a QLabel to explain difficult things of dialogs.
Definition: tool.cpp:116