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#include "btactioncollection.h"
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
188 this,
189 [this](QString const & newActiveAnchor) {
190 bool const hasActiveAnchor = !newActiveAnchor.isEmpty();
191 m_actions.copy.referenceTextOnly->setEnabled(
192 hasActiveAnchor);
193 m_actions.copy.referenceAndText->setEnabled(
194 hasActiveAnchor);
195 m_actions.save.referenceAndText->setEnabled(
196 hasActiveAnchor);
197 });
198
199 ac->readShortcuts(QStringLiteral("Bible shortcuts"));
200}
201
203 auto * const popupMenu = new QMenu(this);
204 popupMenu->addAction(m_actions.findText);
205 popupMenu->addAction(m_actions.findStrongs);
206 popupMenu->addSeparator();
207
208 m_actions.copyMenu = new QMenu(tr("Copy"), popupMenu);
209
210 m_actions.copyMenu->addSeparator();
211
212 m_actions.copyMenu->addAction(m_actions.copy.selectedText);
213 m_actions.copyMenu->addAction(m_actions.copy.byReferences);
214 m_actions.copyMenu->addAction(m_actions.copy.referenceOnly);
215 m_actions.copyMenu->addAction(m_actions.copy.referenceTextOnly);
216 m_actions.copyMenu->addAction(m_actions.copy.referenceAndText);
217 m_actions.copyMenu->addAction(m_actions.copy.chapter);
218
219
220 popupMenu->addMenu(m_actions.copyMenu);
221
222 m_actions.saveMenu = new QMenu(tr("Save..."), popupMenu);
223 m_actions.saveMenu->addAction(m_actions.save.referenceAndText);
224 m_actions.saveMenu->addAction(m_actions.save.chapterAsPlain);
225 m_actions.saveMenu->addAction(m_actions.save.chapterAsHTML);
226 popupMenu->addMenu(m_actions.saveMenu);
227
228 m_actions.printMenu = new QMenu(tr("Print..."), popupMenu);
229 m_actions.printMenu->addAction(m_actions.print.reference);
230 m_actions.printMenu->addAction(m_actions.print.chapter);
231 popupMenu->addMenu(m_actions.printMenu);
232 return popupMenu;
233}
234
235/** Moves to the next book. */
237 if (verseKey()->next(CSwordVerseKey::UseBook)) {
239 }
240}
241
242/** Moves one book behind. */
244 if (verseKey()->previous(CSwordVerseKey::UseBook)) {
246 }
247}
248
249/** Moves to the next book. */
255
256/** Moves one book behind. */
262
263/** Moves to the next book. */
269
270/** Moves one book behind. */
272 if (verseKey()->previous(CSwordVerseKey::UseVerse)) {
274 }
275}
276
277/** wrapper around key() to return the right type of key. */
279 CSwordVerseKey * const k =
281 BT_ASSERT(k);
282 return k;
283}
284
285/** Copies the current chapter into the clipboard. */
287 CSwordVerseKey dummy(*verseKey());
288 dummy.setVerse(1);
289
291 vk.setLowerBound(dummy);
292
293 auto const bible =
294 dynamic_cast<CSwordBibleModuleInfo const *>(firstModule());
295 dummy.setVerse(bible->verseCount(dummy.bookName(), dummy.chapter()));
296 vk.setUpperBound(dummy);
297
298 CExportManager mgr(false, tr("Copying"), filterOptions(), displayOptions());
299 mgr.copyKey(&vk, CExportManager::Text, true);
300}
301
302/** Saves the chapter as valid HTML page. */
306
307/** Saves the chapter as valid HTML page. */
311
314 if (! key)
315 return;
316 CSwordVerseKey* verseKey = dynamic_cast<CSwordVerseKey*>(key);
317 if (! verseKey)
318 return;
319
321 CSwordVerseKey dummy(*verseKey);
322 dummy.setVerse(1);
323 vk.setLowerBound(dummy);
324
325 auto const constMods = constModules();
326
327 auto const bible =
328 dynamic_cast<CSwordBibleModuleInfo const *>(constMods.first());
329 /// \bug Check if bible is nullptr!
330 dummy.setVerse(bible->verseCount(dummy.book(), dummy.chapter()));
331 vk.setUpperBound(dummy);
332
333 CExportManager mgr(true, tr("Saving"), filterOptions(), displayOptions());
334 mgr.saveKey(&vk, format, true, constMods);
335}
336
339
340 if (m_modules.isEmpty()) {
341 close();
342 return;
343 }
344
345 //refresh the book lists
347 CSwordBackend::instance().booknameLanguage().toLatin1());
349
350 actionCollection()->readShortcuts(QStringLiteral("Bible shortcuts"));
351}
352
357
359 for (auto * const subWindow : mdi()->subWindowList()) {
360 CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(subWindow->widget());
361 if (w && w->syncAllowed()) {
362 w->lookupKey(swordKey()->key());
363 }
364 }
365}
#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:292
static FilterOptions loadFilterOptionsFromGroup(BtConfigCore const &group)
Definition btconfig.cpp:274
static DisplayOptions loadDisplayOptionsFromGroup(BtConfigCore const &group)
Definition btconfig.cpp:311
static void storeDisplayOptionsToGroup(DisplayOptions const &options, BtConfigCore &group)
Saves the current display options.
Definition btconfig.cpp:319
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)