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-2025 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
32
35{
36 QAction* qaction;
37
38 qaction = new QAction(tr("Next book"), this);
40 addAction(QStringLiteral("nextBook"), qaction);
41
42 qaction = new QAction(tr("Previous book"), this);
44 addAction(QStringLiteral("previousBook"), qaction);
45
46 qaction = new QAction(tr("Next chapter"), this);
48 addAction(QStringLiteral("nextChapter"), qaction);
49
50 qaction = new QAction(tr("Previous chapter"), this);
52 addAction(QStringLiteral("previousChapter"), qaction);
53
54 qaction = new QAction(tr("Next verse"), this);
56 addAction(QStringLiteral("nextVerse"), qaction);
57
58 qaction = new QAction(tr("Previous verse"), this);
60 addAction(QStringLiteral("previousVerse"), qaction);
61
62 //popup menu items
63 qaction = new QAction(tr("Copy chapter"), this);
64 addAction(QStringLiteral("copyChapter"), qaction);
65
66 qaction = new QAction(tr("Save chapter as plain text"), this);
67 addAction(QStringLiteral("saveChapterAsPlainText"), qaction);
68
69 qaction = new QAction(tr("Save chapter as HTML"), this);
70 addAction(QStringLiteral("saveChapterAsHTML"), qaction);
71
72 qaction = new QAction(tr("Print chapter"), this);
73 qaction->setShortcut(QKeySequence::Print);
74 addAction(QStringLiteral("printChapter"), qaction);
75
76 qaction = new QAction(tr("Text of reference"), this);
77 addAction(QStringLiteral("copyTextOfReference"), qaction);
78
79 qaction = new QAction(tr("Reference with text"), this);
80 addAction(QStringLiteral("copyReferenceWithText"), qaction);
81
82 qaction = new QAction(tr("Reference with text"), this);
83 addAction(QStringLiteral("printReferenceWithText"), qaction);
84
85 qaction = new QAction(tr("Reference with text"), this);
86 addAction(QStringLiteral("saveReferenceWithText"), qaction);
87}
88
89CBibleReadWindow::CBibleReadWindow(QList<CSwordModuleInfo *> const & modules,
90 QString const & key,
91 CMDIArea * parent)
92 : CDisplayWindow(modules, key, true, new ActionCollection(), parent)
93{ init(); }
94
107
114
116 initAddAction(QStringLiteral("nextBook"),
117 this,
119 initAddAction(QStringLiteral("previousBook"),
120 this,
122 initAddAction(QStringLiteral("nextChapter"),
123 this,
125 initAddAction(QStringLiteral("previousChapter"),
126 this,
128 initAddAction(QStringLiteral("nextVerse"),
129 this,
131 initAddAction(QStringLiteral("previousVerse"),
132 this,
134
135 auto * const ac = actionCollection();
136 m_actions.findText = &ac->action(QStringLiteral("findText"));
138 m_actions.copy.referenceOnly =
139 &ac->action(QStringLiteral("copyReferenceOnly"));
140
141 m_actions.copy.referenceTextOnly =
142 &initAddAction(QStringLiteral("copyTextOfReference"),
145
146 m_actions.copy.referenceAndText =
147 &initAddAction(QStringLiteral("copyReferenceWithText"),
150
151 m_actions.copy.chapter =
152 &initAddAction(QStringLiteral("copyChapter"),
153 this,
155
156 m_actions.copy.selectedText =
157 &ac->action(QStringLiteral("copySelectedText"));
158
159 m_actions.copy.byReferences =
160 &ac->action(QStringLiteral("copyByReferences"));
161
162 m_actions.save.referenceAndText =
163 &initAddAction(QStringLiteral("saveReferenceWithText"),
166
167 m_actions.save.chapterAsPlain =
168 &initAddAction(QStringLiteral("saveChapterAsPlainText"),
169 this,
171
172 m_actions.save.chapterAsHTML =
173 &initAddAction(QStringLiteral("saveChapterAsHTML"),
174 this,
176
177 m_actions.print.reference =
178 &initAddAction(QStringLiteral("printReferenceWithText"),
179 this,
181
182 m_actions.print.chapter =
183 &initAddAction(QStringLiteral("printChapter"),
184 this,
186
187 #ifdef BUILD_TEXT_TO_SPEECH
188 m_actions.speakSelectedText = &ac->action("speakSelectedText");
189 #endif
190
192 this,
193 [this](QString const & newActiveAnchor) {
194 bool const hasActiveAnchor = !newActiveAnchor.isEmpty();
195 m_actions.copy.referenceTextOnly->setEnabled(
196 hasActiveAnchor);
197 m_actions.copy.referenceAndText->setEnabled(
198 hasActiveAnchor);
199 m_actions.save.referenceAndText->setEnabled(
200 hasActiveAnchor);
201 });
202
203 ac->readShortcuts(QStringLiteral("Bible shortcuts"));
204}
205
207 auto * const popupMenu = new QMenu(this);
208 popupMenu->addAction(m_actions.findText);
209 popupMenu->addAction(m_actions.findStrongs);
210 popupMenu->addSeparator();
211
212 m_actions.copyMenu = new QMenu(tr("Copy"), popupMenu);
213
214 m_actions.copyMenu->addSeparator();
215
216 m_actions.copyMenu->addAction(m_actions.copy.selectedText);
217 m_actions.copyMenu->addAction(m_actions.copy.byReferences);
218 m_actions.copyMenu->addAction(m_actions.copy.referenceOnly);
219 m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly);
220 m_actions.copyMenu->addAction(m_actions.copy.referenceAndText);
221 m_actions.copyMenu->addAction(m_actions.copy.chapter);
222
223
224 popupMenu->addMenu(m_actions.copyMenu);
225
226 m_actions.saveMenu = new QMenu(tr("Save..."), popupMenu);
227 m_actions.saveMenu->addAction(m_actions.save.referenceAndText);
228 m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain);
229 m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML);
230 popupMenu->addMenu(m_actions.saveMenu);
231
232 m_actions.printMenu = new QMenu(tr("Print..."), popupMenu);
233 m_actions.printMenu->addAction(m_actions.print.reference);
234 m_actions.printMenu->addAction(m_actions.print.chapter);
235 popupMenu->addMenu(m_actions.printMenu);
236
237 #ifdef BUILD_TEXT_TO_SPEECH
238 popupMenu->addAction(m_actions.speakSelectedText);
239 #endif
240
241 return popupMenu;
242}
243
244/** Moves to the next book. */
246 if (verseKey()->next(CSwordVerseKey::UseBook)) {
248 }
249}
250
251/** Moves one book behind. */
253 if (verseKey()->previous(CSwordVerseKey::UseBook)) {
255 }
256}
257
258/** Moves to the next book. */
264
265/** Moves one book behind. */
271
272/** Moves to the next book. */
278
279/** Moves one book behind. */
281 if (verseKey()->previous(CSwordVerseKey::UseVerse)) {
283 }
284}
285
286/** wrapper around key() to return the right type of key. */
288 CSwordVerseKey * const k =
290 BT_ASSERT(k);
291 return k;
292}
293
294/** Copies the current chapter into the clipboard. */
296 CSwordVerseKey dummy(*verseKey());
297 dummy.setVerse(1);
298
300 vk.setLowerBound(dummy);
301
302 auto const bible =
303 dynamic_cast<CSwordBibleModuleInfo const *>(firstModule());
304 dummy.setVerse(bible->verseCount(dummy.bookName(), dummy.chapter()));
305 vk.setUpperBound(dummy);
306
307 CExportManager mgr(false, tr("Copying"), filterOptions(), displayOptions());
308 mgr.copyKey(&vk, CExportManager::Text, true);
309}
310
311/** Saves the chapter as valid HTML page. */
315
316/** Saves the chapter as valid HTML page. */
320
323 if (! key)
324 return;
325 CSwordVerseKey* verseKey = dynamic_cast<CSwordVerseKey*>(key);
326 if (! verseKey)
327 return;
328
330 CSwordVerseKey dummy(*verseKey);
331 dummy.setVerse(1);
332 vk.setLowerBound(dummy);
333
334 auto const constMods = constModules();
335
336 auto const bible =
337 dynamic_cast<CSwordBibleModuleInfo const *>(constMods.first());
338 /// \bug Check if bible is nullptr!
339 dummy.setVerse(bible->verseCount(dummy.book(), dummy.chapter()));
340 vk.setUpperBound(dummy);
341
342 CExportManager mgr(true, tr("Saving"), filterOptions(), displayOptions());
343 mgr.saveKey(&vk, format, true, constMods);
344}
345
348
349 if (m_modules.isEmpty()) {
350 close();
351 return;
352 }
353
354 //refresh the book lists
356 CSwordBackend::instance().booknameLanguage().toLatin1());
358
359 actionCollection()->readShortcuts(QStringLiteral("Bible shortcuts"));
360}
361
366
368 for (auto * const subWindow : mdi()->subWindowList()) {
369 CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget());
370 if (w && w->syncAllowed()) {
371 w->lookupKey(swordKey()->key());
372 }
373 }
374}
#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)
static void storeFilterOptionsToGroup(FilterOptions const &options, BtConfigCore &group)
Saves the current filter options.
Definition btconfig.cpp:291
static FilterOptions loadFilterOptionsFromGroup(BtConfigCore const &group)
Definition btconfig.cpp:273
static DisplayOptions loadDisplayOptionsFromGroup(BtConfigCore const &group)
Definition btconfig.cpp:310
static void storeDisplayOptionsToGroup(DisplayOptions const &options, BtConfigCore &group)
Saves the current display options.
Definition btconfig.cpp:318
void activeAnchorChanged(QString newActiveAnchor)
void save(TextPart const part)
Saves the given text with the specified format into the applications clipboard.
ActionCollection(QObject *parent=nullptr)
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
void initActions() override
void copyDisplayedText() override
void storeProfileSettings(BtConfigCore &windowConf) const override
Stores the settings of this window to configuration.
struct CBibleReadWindow::@9 m_actions
CSwordVerseKey * verseKey()
void reload() override
QMenu * newDisplayWidgetPopupMenu() override
The base class for all display windows of BibleTime.
virtual bool syncAllowed() const noexcept
QAction & initAddAction(Args &&... args)
void sigDisplayOptionsChanged(const DisplayOptions &displayOptions)
virtual void reload()
BtModuleList m_modules
virtual void storeProfileSettings(BtConfigCore &windowConf) const
Stores the settings of this window to configuration.
FilterOptions const & filterOptions() const noexcept
void setDisplayOptions(DisplayOptions const &v)
CKeyChooser * keyChooser() const noexcept
void sigFilterOptionsChanged(const FilterOptions &filterOptions)
BtModelViewReadDisplay * displayWidget() const noexcept
virtual void lookupSwordKey(CSwordKey *)
void lookupKey(QString const &key)
CSwordModuleInfo const * firstModule() const noexcept
DisplayOptions const & displayOptions() const noexcept
void setFilterOptions(FilterOptions const &v)
BtConstModuleList constModules() const
CSwordKey * swordKey() const noexcept
virtual void applyProfileSettings(BtConfigCore const &windowConf)
Loads the settings of this window from configuration.
ActionCollection * actionCollection() const noexcept
CMDIArea * mdi() const
BtModuleList const & modules() const noexcept
CSwordKey * getMouseClickedKey() const
friend class CBibleReadWindow
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
Implementation for Sword Bibles.
virtual QString key() const =0
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)