BibleTime
cbiblereadwindow.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 "cbiblereadwindow.h"
14 
15 #include <QAction>
16 #include <QEvent>
17 #include <QMdiSubWindow>
18 #include <QMenu>
19 #include <QTimer>
20 #include <QWidget>
21 #include "../../backend/drivers/cswordbiblemoduleinfo.h"
22 #include "../../backend/keys/cswordversekey.h"
23 #include "../../backend/managers/cswordbackend.h"
24 #include "../../util/btassert.h"
25 #include "../../util/btconnect.h"
26 #include "../../util/cresmgr.h"
27 #include "../cexportmanager.h"
28 #include "../cmdiarea.h"
29 #include "../display/btmodelviewreaddisplay.h"
30 #include "../keychooser/ckeychooser.h"
31 #include "btactioncollection.h"
32 
33 
36 
39 
42 
43  // Apply settings to display:
44  lookup();
45 }
46 
50 
52 }
53 
54 
55 /** Reimplementation. */
57  QAction* qaction;
58 
59  qaction = new QAction(tr("Next book"), a);
61  a->addAction(QStringLiteral("nextBook"), qaction);
62 
63  qaction = new QAction(tr("Previous book"), a);
65  a->addAction(QStringLiteral("previousBook"), qaction);
66 
67  qaction = new QAction(tr("Next chapter"), a);
69  a->addAction(QStringLiteral("nextChapter"), qaction);
70 
71  qaction = new QAction(tr("Previous chapter"), a);
73  a->addAction(QStringLiteral("previousChapter"), qaction);
74 
75  qaction = new QAction(tr("Next verse"), a);
77  a->addAction(QStringLiteral("nextVerse"), qaction);
78 
79  qaction = new QAction(tr("Previous verse"), a);
81  a->addAction(QStringLiteral("previousVerse"), qaction);
82 
83  //popup menu items
84  qaction = new QAction(tr("Copy chapter"), a);
85  a->addAction(QStringLiteral("copyChapter"), qaction);
86 
87  qaction = new QAction(tr("Save chapter as plain text"), a);
88  a->addAction(QStringLiteral("saveChapterAsPlainText"), qaction);
89 
90  qaction = new QAction(tr("Save chapter as HTML"), a);
91  a->addAction(QStringLiteral("saveChapterAsHTML"), qaction);
92 
93  qaction = new QAction(tr("Print chapter"), a);
94  qaction->setShortcut(QKeySequence::Print);
95  a->addAction(QStringLiteral("printChapter"), qaction);
96 
97  // qaction = new QAction( /* QIcon(CResMgr::displaywindows::general::findStrongs::icon), */ tr("Strong's search"), a);
98  // qaction->setShortcut(CResMgr::displaywindows::general::findStrongs::accel);
99  // qaction->setToolTip(tr("Find all occurences of the Strong number currently under the mouse cursor"));
100  // a->addAction(CResMgr::displaywindows::general::findStrongs::actionName, qaction);
101 
102  // qaction = new QAction(tr("Reference only"), a );
103  // a->addAction("copyReferenceOnly", qaction);
104 
105  qaction = new QAction(tr("Text of reference"), a);
106  a->addAction(QStringLiteral("copyTextOfReference"), qaction);
107 
108  qaction = new QAction(tr("Reference with text"), a);
109  a->addAction(QStringLiteral("copyReferenceWithText"), qaction);
110 
111  qaction = new QAction(tr("Reference with text"), a);
112  a->addAction(QStringLiteral("printReferenceWithText"), qaction);
113 
114  qaction = new QAction(tr("Reference with text"), a);
115  a->addAction(QStringLiteral("saveReferenceWithText"), qaction);
116 }
117 
120 
121  CDisplayWindow::initActions(); //make sure the predefined actions are available
122 
124 
125  initAddAction(QStringLiteral("nextBook"),
126  this,
128  initAddAction(QStringLiteral("previousBook"),
129  this,
131  initAddAction(QStringLiteral("nextChapter"),
132  this,
134  initAddAction(QStringLiteral("previousChapter"),
135  this,
137  initAddAction(QStringLiteral("nextVerse"),
138  this,
140  initAddAction(QStringLiteral("previousVerse"),
141  this,
143 
144  m_actions.findText = &ac->action(QStringLiteral("findText"));
146  m_actions.copy.referenceOnly =
147  &ac->action(QStringLiteral("copyReferenceOnly"));
148 
149  m_actions.copy.referenceTextOnly =
150  &initAddAction(QStringLiteral("copyTextOfReference"),
151  displayWidget(),
153 
154  m_actions.copy.referenceAndText =
155  &initAddAction(QStringLiteral("copyReferenceWithText"),
156  displayWidget(),
158 
159  m_actions.copy.chapter =
160  &initAddAction(QStringLiteral("copyChapter"),
161  this,
163 
164  m_actions.copy.selectedText =
165  &ac->action(QStringLiteral("copySelectedText"));
166 
167  m_actions.copy.byReferences =
168  &ac->action(QStringLiteral("copyByReferences"));
169 
170  m_actions.save.referenceAndText =
171  &initAddAction(QStringLiteral("saveReferenceWithText"),
172  displayWidget(),
174 
175  m_actions.save.chapterAsPlain =
176  &initAddAction(QStringLiteral("saveChapterAsPlainText"),
177  this,
179 
180  m_actions.save.chapterAsHTML =
181  &initAddAction(QStringLiteral("saveChapterAsHTML"),
182  this,
184 
185  m_actions.print.reference =
186  &initAddAction(QStringLiteral("printReferenceWithText"),
187  this,
189 
190  m_actions.print.chapter =
191  &initAddAction(QStringLiteral("printChapter"),
192  this,
194 
195  ac->readShortcuts(QStringLiteral("Bible shortcuts"));
196 }
197 
199  auto * const popupMenu = new QMenu(this);
200  BT_CONNECT(popupMenu, &QMenu::aboutToShow,
201  [this] {
202  auto const & display = *displayWidget();
203  m_actions.findStrongs->setEnabled(
204  !display.getCurrentNodeInfo().isNull());
205 
206  bool const hasActiveAnchor = display.hasActiveAnchor();
207  m_actions.copy.referenceOnly->setEnabled(hasActiveAnchor);
208  m_actions.copy.referenceTextOnly->setEnabled(
209  hasActiveAnchor);
210  m_actions.copy.referenceAndText->setEnabled(
211  hasActiveAnchor);
212 
213  m_actions.save.referenceAndText->setEnabled(
214  hasActiveAnchor);
215 
216  m_actions.print.reference->setEnabled(hasActiveAnchor);
217 
218  m_actions.copy.selectedText->setEnabled(hasSelectedText());
219  });
220  popupMenu->setTitle(tr("Bible window"));
221  popupMenu->setIcon(firstModule()->moduleIcon());
222  popupMenu->addAction(m_actions.findText);
223  QKeySequence ks = m_actions.findText->shortcut();
224  QString keys = ks.toString();
225  popupMenu->addAction(m_actions.findStrongs);
226 
227  popupMenu->addSeparator();
228 
229  m_actions.copyMenu = new QMenu(tr("Copy"), popupMenu);
230 
231  m_actions.copyMenu->addSeparator();
232 
233  m_actions.copyMenu->addAction(m_actions.copy.selectedText);
234  m_actions.copyMenu->addAction(m_actions.copy.byReferences);
235  m_actions.copyMenu->addAction(m_actions.copy.referenceOnly);
236  m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly);
237  m_actions.copyMenu->addAction(m_actions.copy.referenceAndText);
238  m_actions.copyMenu->addAction(m_actions.copy.chapter);
239 
240 
241  popupMenu->addMenu(m_actions.copyMenu);
242 
243  m_actions.saveMenu = new QMenu(tr("Save..."), popupMenu);
244  m_actions.saveMenu->addAction(m_actions.save.referenceAndText);
245  m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain);
246  m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML);
247  popupMenu->addMenu(m_actions.saveMenu);
248 
249  m_actions.printMenu = new QMenu(tr("Print..."), popupMenu);
250  m_actions.printMenu->addAction(m_actions.print.reference);
251  m_actions.printMenu->addAction(m_actions.print.chapter);
252  popupMenu->addMenu(m_actions.printMenu);
253  return popupMenu;
254 }
255 
256 /** Moves to the next book. */
258  if (verseKey()->next(CSwordVerseKey::UseBook)) {
259  keyChooser()->setKey(key());
260  }
261 }
262 
263 /** Moves one book behind. */
265  if (verseKey()->previous(CSwordVerseKey::UseBook)) {
266  keyChooser()->setKey(key());
267  }
268 }
269 
270 /** Moves to the next book. */
272  if (verseKey()->next(CSwordVerseKey::UseChapter)) {
273  keyChooser()->setKey(key());
274  }
275 }
276 
277 /** Moves one book behind. */
279  if (verseKey()->previous(CSwordVerseKey::UseChapter)) {
280  keyChooser()->setKey(key());
281  }
282 }
283 
284 /** Moves to the next book. */
286  if (verseKey()->next(CSwordVerseKey::UseVerse)) {
287  keyChooser()->setKey(key());
288  }
289 }
290 
291 /** Moves one book behind. */
293  if (verseKey()->previous(CSwordVerseKey::UseVerse)) {
294  keyChooser()->setKey(key());
295  }
296 }
297 
298 /** wrapper around key() to return the right type of key. */
300  CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
301  BT_ASSERT(k);
302 
303  return k;
304 }
305 
306 /** Copies the current chapter into the clipboard. */
308  CSwordVerseKey dummy(*verseKey());
309  dummy.setVerse(1);
310 
311  CSwordVerseKey vk(*verseKey());
312  vk.setLowerBound(dummy);
313 
314  auto const bible =
315  dynamic_cast<CSwordBibleModuleInfo const *>(firstModule());
316  dummy.setVerse(bible->verseCount(dummy.bookName(), dummy.chapter()));
317  vk.setUpperBound(dummy);
318 
319  CExportManager mgr(false, tr("Copying"), filterOptions(), displayOptions());
320  mgr.copyKey(&vk, CExportManager::Text, true);
321 }
322 
323 /** Saves the chapter as valid HTML page. */
326 }
327 
328 /** Saves the chapter as valid HTML page. */
331 }
332 
335  if (! key)
336  return;
337  CSwordVerseKey* verseKey = dynamic_cast<CSwordVerseKey*>(key);
338  if (! verseKey)
339  return;
340 
342  CSwordVerseKey dummy(*verseKey);
343  dummy.setVerse(1);
344  vk.setLowerBound(dummy);
345 
346  auto const constMods = constModules();
347 
348  auto const bible =
349  dynamic_cast<CSwordBibleModuleInfo const *>(constMods.first());
350  /// \bug Check if bible is nullptr!
351  dummy.setVerse(bible->verseCount(dummy.book(), dummy.chapter()));
352  vk.setUpperBound(dummy);
353 
354  CExportManager mgr(true, tr("Saving"), filterOptions(), displayOptions());
355  mgr.saveKey(&vk, format, true, constMods);
356 }
357 
360 
361  if (m_modules.isEmpty()) {
362  close();
363  return;
364  }
365 
366  //refresh the book lists
367  verseKey()->setLocale(
368  CSwordBackend::instance().booknameLanguage().toLatin1());
370 
371  actionCollection()->readShortcuts(QStringLiteral("Bible shortcuts"));
372 }
373 
376  syncWindows();
377 }
378 
380  for (auto * const subWindow : mdi()->subWindowList()) {
381  CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget());
382  if (w && w->syncAllowed()) {
383  w->lookupKey( key()->key() );
384  }
385  }
386 }
#define BT_ASSERT(...)
Definition: btassert.h:17
#define BT_CONNECT(...)
Definition: btconnect.h:20
void readShortcuts(QString const &group)
Read shortcuts from config.
void addAction(QString const &name, QAction *const action)
QAction & action(QString const &name) const
static void storeFilterOptionsToGroup(FilterOptions const &options, BtConfigCore &group)
Saves the current filter options.
Definition: btconfig.cpp:301
static FilterOptions loadFilterOptionsFromGroup(BtConfigCore const &group)
Definition: btconfig.cpp:283
static DisplayOptions loadDisplayOptionsFromGroup(BtConfigCore const &group)
Definition: btconfig.cpp:320
static void storeDisplayOptionsToGroup(DisplayOptions const &options, BtConfigCore &group)
Saves the current display options.
Definition: btconfig.cpp:328
void saveChapter(CExportManager::Format const format)
void applyProfileSettings(BtConfigCore const &windowConf) override
Loads the settings of this window from configuration.
void lookupSwordKey(CSwordKey *newKey) override
static void insertKeyboardActions(BtActionCollection *const a)
void initActions() override
void copyDisplayedText() override
void storeProfileSettings(BtConfigCore &windowConf) const override
Stores the settings of this window to configuration.
CSwordVerseKey * verseKey()
void reload() override
struct CBibleReadWindow::@1 m_actions
QMenu * newDisplayWidgetPopupMenu() override
The base class for all display windows of BibleTime.
DisplayOptions const & displayOptions() const
void sigDisplayOptionsChanged(const DisplayOptions &displayOptions)
void printAnchorWithText()
virtual void reload()
QAction & initAddAction(Args &&... args)
BtModuleList m_modules
CKeyChooser * keyChooser() const
virtual void storeProfileSettings(BtConfigCore &windowConf) const
Stores the settings of this window to configuration.
BtActionCollection * actionCollection() const
void setDisplayOptions(DisplayOptions const &v)
void sigFilterOptionsChanged(const FilterOptions &filterOptions)
virtual void initActions()
FilterOptions const & filterOptions() const
CMDIArea * mdi() const
virtual void lookupSwordKey(CSwordKey *)
void lookupKey(QString const &key)
void setFilterOptions(FilterOptions const &v)
BtConstModuleList constModules() const
virtual bool syncAllowed() const
BtModelViewReadDisplay * displayWidget() const
virtual void applyProfileSettings(BtConfigCore const &windowConf)
Loads the settings of this window from configuration.
CSwordModuleInfo const * firstModule() const noexcept
CSwordKey * key() const
CSwordKey * getMouseClickedKey() const
bool saveKey(CSwordKey const *const key, Format const format, bool const addText, const BtConstModuleList &modules)
bool copyKey(CSwordKey const *const key, Format const format, bool const addText)
virtual void setKey(CSwordKey *key)=0
virtual void refreshContent()=0
static CSwordBackend & instance() noexcept
Definition: cswordbackend.h:98
Implementation for Sword Bibles.
virtual QString key() const =0
QIcon moduleIcon() const
CSwordKey implementation for Sword's VerseKey.
void setLowerBound(CSwordVerseKey const &bound)
char book() const
QString bookName() const
void setLocale(char const *const locale)
void setUpperBound(CSwordVerseKey const &bound)
int chapter() const
void setVerse(int v)