BibleTime
btdisplaysettingsbutton.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 
14 
15 #include <QAction>
16 #include <QMenu>
17 #include <QString>
18 #include <QToolButton>
19 #include "../../backend/btglobal.h"
20 #include "../../backend/drivers/btmodulelist.h"
21 #include "../../backend/drivers/cswordmoduleinfo.h"
22 #include "../../util/btassert.h"
23 #include "../../util/btconnect.h"
24 #include "../../util/cresmgr.h"
25 
26 
28  : QToolButton(parent) {
29  initMenu();
30 
31  setIcon(CResMgr::displaywindows::displaySettings::icon());
32  setPopupMode(QToolButton::InstantPopup);
33  setEnabled(false);
34 
35  initMenu();
36  retranslateUi();
37 
38  BT_CONNECT(m_popup, &QMenu::triggered,
39  [this](QAction * const action) {
40  bool checked = action->isChecked();
41 
42  if (action == m_verseNumbersAction) {
45  } else if (action == m_variantAction) {
48  } else if (action == m_hebrewPointsAction) {
49  m_filterOptions.hebrewPoints = checked;
51  } else if (action == m_greekAccentsAction) {
52  m_filterOptions.greekAccents = checked;
54  } else if (action == m_hebrewCantillationAction) {
57  } else if (action == m_headingsAction) {
58  m_filterOptions.headings = checked;
60  } else if (action == m_morphSegmentationAction) {
63  } else if (action == m_scriptureReferencesAction) {
66  } else if (action == m_footnotesAction) {
67  m_filterOptions.footnotes = checked;
69  } else if (action == m_redWordsAction) {
72  } else {
73  BT_ASSERT(false && "Shouldn't happen!");
74  return;
75  }
76 
77  Q_EMIT sigChanged();
78  });
79 }
80 
82  DisplayOptions const & displaySettings)
83 { m_displayOptions = displaySettings; }
84 
85 
87  FilterOptions const & moduleSettings)
88 { m_filterOptions = moduleSettings; }
89 
91  DisplayOptions const & displaySettings)
92 {
93  m_displayOptions = displaySettings;
95 }
96 
98  FilterOptions const & moduleSettings)
99 {
100  m_filterOptions = moduleSettings;
101  repopulateMenu();
102 }
103 
105  const BtConstModuleList &modules)
106 {
107  m_modules = modules;
108  repopulateMenu();
109 }
110 
112  m_popup = new QMenu(this);
113  setMenu(m_popup);
114 
115  m_verseNumbersAction = new QAction(this);
116  m_verseNumbersAction->setCheckable(true);
117 
118  m_headingsAction = new QAction(this);
119  m_headingsAction->setCheckable(true);
120 
121  m_redWordsAction = new QAction(this);
122  m_redWordsAction->setCheckable(true);
123 
124  m_hebrewPointsAction = new QAction(this);
125  m_hebrewPointsAction->setCheckable(true);
126 
128  m_hebrewCantillationAction->setCheckable(true);
129 
130  m_greekAccentsAction = new QAction(this);
131  m_greekAccentsAction->setCheckable(true);
132 
133  m_variantAction = new QAction(this);
134  m_variantAction->setCheckable(true);
135 
137  m_scriptureReferencesAction->setCheckable(true);
138 
139  m_footnotesAction = new QAction(this);
140  m_footnotesAction->setCheckable(true);
141 
143  m_morphSegmentationAction->setCheckable(true);
144 }
145 
147  m_verseNumbersAction->setText(tr("Show verse numbers"));
148  m_headingsAction->setText(tr("Show headings"));
149  m_redWordsAction->setText(tr("Highlight words of Jesus"));
150  m_hebrewPointsAction->setText(tr("Show Hebrew vowel points"));
151  m_hebrewCantillationAction->setText(tr("Show Hebrew cantillation marks"));
152  m_greekAccentsAction->setText(tr("Show Greek accents"));
153  m_variantAction->setText(tr("Use alternative textual variant"));
154  m_scriptureReferencesAction->setText(tr("Show scripture cross-references"));
155  m_footnotesAction->setText(tr("Show footnotes"));
156  m_morphSegmentationAction->setText(tr("Show morph segmentation"));
157 
159 }
160 
162  if (isEnabled()) {
163  setToolTip(tr("Display settings"));
164  }
165  else {
166  setToolTip(tr("Display settings: No options available"));
167  }
168 }
169 
170 /** No descriptions */
172  bool enable = false;
173 
174  m_popup->clear();
175  if (!m_modules.isEmpty()) {
176  if (m_modules.first()->type() == CSwordModuleInfo::Bible) {
178  enable = true;
179  }
180 
183  enable = true;
184  }
185 
188  enable = true;
189  }
190 
193  enable = true;
194  }
195 
198  enable = true;
199  }
200 
203  enable = true;
204  }
205 
208  enable = true;
209  }
210 
213  enable = true;
214  }
215 
218  enable = true;
219  }
220 
223  enable = true;
224  }
225  }
226 
227  // Disable the settings button if no options are available:
228  setEnabled(enable);
230 }
231 
232 /** Adds an entry to m_popup. */
233 void BtDisplaySettingsButton::addMenuEntry(QAction *action, bool checked) {
234  action->setChecked(checked);
235  m_popup->addAction(action);
236 }
237 
239  CSwordModuleInfo::FilterOption const & option)
240 {
241  for (auto const * const module : m_modules)
242  if (module->has(option))
243  return true;
244  return false;
245 }
#define BT_ASSERT(...)
Definition: btassert.h:17
#define BT_CONNECT(...)
Definition: btconnect.h:20
QList< CSwordModuleInfo const * > BtConstModuleList
Definition: btmodulelist.h:21
void sigDisplayOptionsChanged(DisplayOptions displayOptions)
void setFilterOptions(FilterOptions const &moduleSettings)
bool isOptionAvailable(CSwordModuleInfo::FilterOption const &option)
BtDisplaySettingsButton(QWidget *parent=nullptr)
void addMenuEntry(QAction *action, bool checked)
void sigFilterOptionsChanged(FilterOptions filterOptions)
void setDisplayOptions(DisplayOptions const &displaySettings)
void setDisplayOptionsNoRepopulate(DisplayOptions const &displaySettings)
void setFilterOptionsNoRepopulate(FilterOptions const &moduleSettings)
void setModules(const BtConstModuleList &modules)
static FilterOption const redLetterWords
static FilterOption const headings
static FilterOption const textualVariants
static FilterOption const hebrewPoints
static FilterOption const scriptureReferences
static FilterOption const hebrewCantillation
static FilterOption const morphSegmentation
static FilterOption const greekAccents
static FilterOption const footnotes
int verseNumbers
Definition: btglobal.h:48
int morphSegmentation
Definition: btglobal.h:37
int hebrewCantillation
Definition: btglobal.h:32
int textualVariants
Definition: btglobal.h:34
int hebrewPoints
Definition: btglobal.h:31
int footnotes
Definition: btglobal.h:26
int scriptureReferences
Definition: btglobal.h:36
int greekAccents
Definition: btglobal.h:33
int headings
Definition: btglobal.h:28
int redLetterWords
Definition: btglobal.h:35