BibleTime
bibletime.h
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#pragma once
14
15#include <QMainWindow>
16
17#include <QList>
18#include <QPointer>
19#ifdef BUILD_TEXT_TO_SPEECH
20#include <QTextToSpeech>
21#endif
22#include <QTimer>
23#include "../backend/drivers/btmodulelist.h"
24#include "../backend/drivers/cswordmoduleinfo.h"
26
27
28namespace InfoDisplay { class CInfoDisplay; }
29namespace Search { class CSearchDialog; }
30class BibleTimeApp;
31class BtActionClass;
34class BtFindWidget;
38class CBookmarkIndex;
39class CDisplayWindow;
40class CKeyChooser;
41class CMDIArea;
42class QAction;
43class QMdiSubWindow;
44class QMenu;
45class QActionGroup;
46class QToolBar;
47class QSplitter;
48
49/**
50 * @page backend The structure of the backend
51 * <p>
52 * The backend implementation for Sword is called CSwordBackend, the classes we use
53 * to work with keys are called CSwordVerseKey and CSwordLDKey, both are derived from
54 * the class CSwordKey.
55 * The CSwordKey derived classes used for Sword do also inherit the classes
56 * VerseKey (CSwordVerseKey)
57 * and SWKey (CSwordLDKey).
58 * </p>
59 * <p>
60 * The classes used to handle all module based stuff are derived from CSwordModuleInfo.
61 * The module classes are: CSwordModuleInfo (for Sword modules),
62 * CSwordBibleModuleInfo (for bibles), CSwordCommentaryModuleInfo (for commentaries) and
63 * CSwordLexiconModuleInfo (for lexicons).
64 * Have a look at the class documentation of the mentioned classes to learn how the
65 * structure of them looks like and which class inherits which other class.
66 * </p>
67 * <p>
68 * The first objects which should be created in the application is the backend
69 * (for Sword the class is called CSwordBackend).
70 * Then create all the different module classes for the correct Sword modules.
71 * Have a look at
72 * BibleTime::initBackend() to see how it's done in BibleTime.@br
73 * Later you can work with them for example by using the CSwordKey and
74 * CSwordModuleInfo derived class.
75 * </p>
76 */
77
78/**
79 * @page frontend The structure of the frontend
80 *
81 * <p>
82 * The frontend contains the classes which interact with the user. For example the
83 * display windows, the searchdialog or the other parts.
84 * </p><p>
85 * The display windows which provide functionality are CBibleReadWindow for
86 * Bibles, CBookReadWindow for books, CCommentaryReadWindow for commentaries and CLexiconReadWindow for
87 * lexicon and dictionaries. CHTMLWriteWindow and CPlainWriteWindows are used for editing the Personal Commentary.
88 * </p><p>
89 *
90 * The class CDisplayWindow is the class that various views with in the windows are derived.
91 * </p><p>
92 *
93 * Another important part of the frontend are the keychoosers.
94 * They provide an interface to choose a key of a module.
95 * The interface for different module types is different.
96 * The base class is CKeyChooser which is the factory for the derived classes.
97 * Use the function CKeyChooser::createInstance to get the correct
98 * keychooser implementation for the desired module.<br/>
99 * </p><p>
100 * Some major toolbar widgets are CKeyChooser and BtDisplaySettingsButton.
101 * </p>
102 */
103
104/** @mainpage BibleTime - Source Code Documentation
105 * BibleTime main page.
106 * <p>This is the source code documentation of BibleTime, a Bible study tool.
107 * <p>
108 * The main class of BibleTime is called @ref BibleTime, which is the main window
109 * and initializes all important parts at startup.
110 * </p><p>
111 * BibleTime is divided in two major parts, the backend and the frontend.
112 * The text display windows belong to the @ref frontend.
113 * The backend is mainly a wrapper around Sword's classes to use Qt functionality
114 * to allow easy access to it's functionality and to have it in a (more or less :)
115 * object oriented structure.</p>
116 * <p>
117 * - Introduction to the frontend: @ref frontend<br/>
118 * - Introduction to the backend: @ref backend<br/>
119 * - Introduction to the model/view display: @ref modelviewmain<br/>
120 * </p>
121 */
122
123/** BibleTime's main class.
124 * The main class of BibleTime. Here are the main widgets created.
125 *
126 * This is the main class of BibleTime! This class creates the GUI, the QAction objects
127 * and connects to some slots. Please insert the creation of actions in initActions,
128 * the creation of widgets into initView and the connect(...) calls into initConnections.
129 * Reading from a config file on creation time should go into readSettings(), saving into
130 * saveSettings().
131 * This is the general way of all BibleTime classes.
132 */
133class BibleTime final : public QMainWindow {
134
135 Q_OBJECT
136
137 friend class CDisplayWindow;
138
139public: // Types:
140
142
143 public: // Fields:
144
145 struct { // File menu:
149
150 struct { // View menu:
156 struct { // Toolbars submenu:
163 struct { // Scroll submenu:
169
170 struct { // Search menu:
174
175 struct { // Windows menu:
182 struct { // Arrangement mode submenu:
192
193 struct { // Settings menu:
197
204
205 public: // Methods:
206
208 QAction * showBookshelfAction,
209 QAction * showBookmarksAction,
210 QAction * showMagAction,
211 QObject * parent = nullptr);
212
213 void retranslateUi();
214
215 };
216
217public:
218
220 QWidget * parent = nullptr,
221 Qt::WindowFlags flags = Qt::WindowFlags());
222
223 ~BibleTime() override;
224
225 static BibleTime * instance() noexcept { return m_instance; }
226
227 /** Saves the configuration dialog settings, doesn't open dialog. */
228 void saveConfigSettings();
229
230 /** \returns a pointer to the Navigation toolbar. */
231 QToolBar * navToolBar() const noexcept { return m_navToolBar; }
232
233 /** \returns a pointer to the Works toolbar. */
235 { return m_worksToolBar; }
236
237 /** \returns a pointer to the Tools toolbar. */
238 QToolBar * toolsToolBar() const noexcept { return m_toolsToolBar; }
239
240 /** \returns a pointer to the info display. */
242 { return m_infoDisplay; }
243
244 /** Clears the actions of the MDI related toolbars. */
245 void clearMdiToolBars();
246
247 /** \returns the main window CKeyChooser. */
248 CKeyChooser * keyChooser() const;
249
250 /**
251 Displays a dialog which asks the user an unlock key for the given module
252 and tries to unlock the module. If an invalid unlock key is given, a
253 warning message is issued and the user is again asked for the key.
254 \param[in] module The module to unlock.
255 \param[in] parent The parent widget for the unlock dialogs.
256 \returns whether the module was successfully unlocked.
257 */
258 static bool moduleUnlock(CSwordModuleInfo * module,
259 QWidget * parent = nullptr);
260
261 /** \returns a pointer to the module associated with the current window. */
263
264 /** \returns a pointer to the display associated with the current window. */
266
267 /** Opens the BtFindWidget below the MDI area. */
268 void openFindWidget();
269
270 /** Sets the focus on the display widget. */
271 void setDisplayFocus();
272
274 QString const & searchText = {});
275
276 #ifdef BUILD_TEXT_TO_SPEECH
277 /**
278 Speaks the given text.
279 \param[in] text The text to speak.
280 */
281 void speakText(QString const & text);
282
283 /**
284 Creates a QTextToSpeech instance, taking text-to-speech
285 settings into account.
286 \returns The QTextToSpeech instance.
287 */
288 static std::unique_ptr<QTextToSpeech> createTextToSpeechInstance();
289 #endif
290
291public Q_SLOTS:
292
293 /** Opens the optionsdialog of BibleTime. */
294 void slotSettingsOptions();
295
296 /** Opens the bookshelf wizard. */
297 void slotBookshelfWizard();
298
299 /** Opens the handbook. */
301
302 /** Opens the bible study howto. */
304
305 /** Opens the Tip Dialog. */
306 void slotOpenTipDialog();
307
308 /**
309 Processes the command-line options given to BibleTime.
310 \param[in] ignoreSession Specifies whether --ignore-session was used.
311 \param[in] bibleKey If --open-default-bible was used, the bible key
312 specified, or null otherwise.
313 */
314 void processCommandline(bool ignoreSession, QString const & bibleKey);
315
316 void autoScrollStop();
317
318Q_SIGNALS:
319
320 void toggledTextWindowHeader(bool newState);
321 void toggledTextWindowNavigator(bool newState);
322 void toggledTextWindowToolButtons(bool newState);
325
326private: // methods:
327
328 bool event(QEvent * event) override;
329
330 /** Creates the main window menu and toolbar. */
332
333 /** Creates MDI and and BtFindWidget. */
334 void createCentralWidget();
335
336 /** Initializes the view of this widget. */
337 void initView();
338
339 /** Initializes the menubar of BibleTime. */
340 void initMenubar();
341
342 /** Initializes the SIGNAL / SLOT connections. */
343 void initConnections();
344
345 /** Initializes the action objects of the GUI. */
346 void initActions();
347
348 /** Initializes the toolbars. */
349 void initToolbars();
350
351 /** Retranslates the UI. */
352 void retranslateUi();
353
354 /**
355 Refreshes all presenter supporting at least in of the features given as
356 parameter.
357 */
358 void refreshDisplayWindows() const;
359
360 template <bool goingUp>
361 void autoScroll();
362
363 /**
364 Set the visibility of all tool bars according to the configuration taking
365 the toolbarsInEachWindow setting into account.
366 */
367 void showOrHideToolBars();
368
369 void slotShowDebugWindow(bool);
370
371private Q_SLOTS:
372
373 /**
374 Creates a new presenter in the MDI area according to the type of the
375 module.
376 */
377 CDisplayWindow * createReadDisplayWindow(QList<CSwordModuleInfo *> modules,
378 QString const & key);
380 QString const & key = {});
381 void slotModuleUnlock(CSwordModuleInfo * module);
382 void moduleAbout(CSwordModuleInfo * module);
383
384 /** Automatically scrolls the display. */
385 void slotAutoScroll();
386
387 /** Called when the window menu is about to show. */
389
390 /** Called when the open windows menu is about to show. */
392
393 void slotUpdateWindowArrangementActions(QAction * trigerredAction);
394
395 void slotCascade();
396 void slotTile();
397 void slotTileVertical();
398 void slotTileHorizontal();
399
400 /** Shows or hides the main toolbar. */
405
407
408 /**
409 Shows or hides the text window text area headers and sets configuration
410 that newly opened windows don't user headers.
411 */
413
414 /** Used to set the active menu. */
415 void slotSetActiveSubWindow(QWidget * window);
416
417 void slotActiveWindowChanged(QMdiSubWindow * window);
418
419 /** Saves the current settings into the currently activated profile. */
420 void saveProfile();
421
422 /** Deletes the chosen session from the menu and from disk. */
423 void deleteProfile(QAction * action);
424
425 /** Loads the profile with the menu id ID. */
426 void loadProfile(QAction * action);
427
428 /** Loads the profile with the given key. */
429 void loadProfile(QString const & profileKey);
430
431 /** Reloads the current profile. */
432 void reloadProfile();
433
434 /** Toggles between normal and fullscreen mode. */
435 void toggleFullscreen();
436
437 void autoScrollPause();
438 bool autoScrollAnyKey();
439
440 /** Called when search button is pressed. */
441 void slotSearchModules();
442
443 /** Called for search default bible. */
445
446 /** Saves current settings into a new profile. */
447 void saveToNewProfile();
448
449 /** Refreshes the save profile and load profile menus. */
450 void refreshProfileMenus();
451
452 /** Open the About Dialog. */
453 void slotOpenAboutDialog();
454
455private: // fields:
456
458
459 // Docking widgets and their respective content widgets:
465
470
485
487
490
493 QPointer<Search::CSearchDialog> m_searchDialog;
494
496 QPointer<QWidget> m_debugWindow;
497
498 #ifdef BUILD_TEXT_TO_SPEECH
499 std::unique_ptr<QTextToSpeech> m_textToSpeech;
500 #endif
501
502};
503
504extern template void BibleTime::autoScroll<true>();
505extern template void BibleTime::autoScroll<false>();
QList< CSwordModuleInfo const * > BtConstModuleList
struct BibleTime::ActionCollection::@5 settings
struct BibleTime::ActionCollection::@3 search
struct BibleTime::ActionCollection::@1 file
BtOpenWorkAction * openWork
Definition bibletime.h:146
struct BibleTime::ActionCollection::@4 windows
struct BibleTime::ActionCollection::@2 view
struct BibleTime::ActionCollection::@2::@7 scroll
struct BibleTime::ActionCollection::@2::@6 toolbars
struct BibleTime::ActionCollection::@4::@8 arrangementMode
QAction * showToolbarsInTextWindows
Definition bibletime.h:161
void loadProfile(QAction *action)
QMenu * m_toolBarsMenu
Definition bibletime.h:473
QPointer< QWidget > m_debugWindow
Definition bibletime.h:496
void slotModuleUnlock(CSwordModuleInfo *module)
BtModuleChooserBar * m_worksToolBar
Definition bibletime.h:468
QMenu * m_searchMenu
Definition bibletime.h:475
void clearMdiToolBars()
QActionGroup * m_windowArrangementActionGroup
Definition bibletime.h:479
BtBookshelfDockWidget * m_bookshelfDock
Definition bibletime.h:460
void slotBookshelfWizard()
void slotOpenTipDialog()
void slotSearchModules()
static bool moduleUnlock(CSwordModuleInfo *module, QWidget *parent=nullptr)
void retranslateUi()
void slotShowDebugWindow(bool)
int m_autoScrollSpeed
Definition bibletime.h:491
void moduleAbout(CSwordModuleInfo *module)
QDockWidget * m_magDock
Definition bibletime.h:463
CKeyChooser * keyChooser() const
QToolBar * m_mainToolBar
Definition bibletime.h:466
QAction * m_debugWidgetAction
Definition bibletime.h:495
QMenu * m_fileMenu
Definition bibletime.h:471
void slotActiveWindowChanged(QMdiSubWindow *window)
ActionCollection * m_actions
Definition bibletime.h:486
void deleteProfile(QAction *action)
void openFindWidget()
void slotTileHorizontal()
CMDIArea * m_mdi
Definition bibletime.h:488
InfoDisplay::CInfoDisplay * m_infoDisplay
Definition bibletime.h:464
void slotUpdateWindowArrangementActions(QAction *trigerredAction)
void toggledTextWindowToolButtons(bool newState)
void createCentralWidget()
bool event(QEvent *event) override
void slotToggleWorksToolbar()
void slotOpenAboutDialog()
void toggledTextWindowHeader(bool newState)
void initToolbars()
void openSearchDialog(BtConstModuleList modules, QString const &searchText={})
void slotSearchDefaultBible()
void slotSettingsOptions()
void slotToggleMainToolbar()
void autoScrollPause()
void slotToggleTextWindowHeader()
static BibleTime * m_instance
Definition bibletime.h:457
QDockWidget * m_bookmarksDock
Definition bibletime.h:461
QToolBar * toolsToolBar() const noexcept
Definition bibletime.h:238
CBookmarkIndex * m_bookmarksPage
Definition bibletime.h:462
void showOrHideToolBars()
void colorThemeChanged()
void setDisplayFocus()
void slotAutoScroll()
void toggledTextWindowNavigator(bool newState)
QMenu * m_settingsMenu
Definition bibletime.h:483
void slotOpenWindowsMenuAboutToShow()
void openOnlineHelp_Handbook()
void initConnections()
static BibleTime * instance() noexcept
Definition bibletime.h:225
void createMenuAndToolBar()
QMenu * m_windowDeleteProfileMenu
Definition bibletime.h:482
BtModuleChooserBar * worksToolBar() const noexcept
Definition bibletime.h:234
void refreshProfileMenus()
void slotToggleToolsToolbar()
QToolBar * m_toolsToolBar
Definition bibletime.h:469
void slotToggleToolBarsInEachWindow()
void toggledTextWindowModuleChooser(bool newState)
QToolBar * navToolBar() const noexcept
Definition bibletime.h:231
QToolBar * m_navToolBar
Definition bibletime.h:467
BtFindWidget * m_findWidget
Definition bibletime.h:489
InfoDisplay::CInfoDisplay * infoDisplay() const noexcept
Definition bibletime.h:241
QMenu * m_viewMenu
Definition bibletime.h:472
void saveToNewProfile()
QPointer< Search::CSearchDialog > m_searchDialog
Definition bibletime.h:493
void slotTileVertical()
CSwordModuleInfo const * getCurrentModule()
QMenu * m_scrollMenu
Definition bibletime.h:474
BtModelViewReadDisplay * getCurrentDisplay()
void openOnlineHelp_Howto()
~BibleTime() override
void processCommandline(bool ignoreSession, QString const &bibleKey)
void slotWindowMenuAboutToShow()
QMenu * m_windowsMenu
Definition bibletime.h:476
QMenu * m_helpMenu
Definition bibletime.h:484
void autoScrollStop()
void saveConfigSettings()
QMenu * m_windowLoadProfileMenu
Definition bibletime.h:480
QActionGroup * m_windowLoadProfileActionGroup
Definition bibletime.h:481
CDisplayWindow * createReadDisplayWindow(QList< CSwordModuleInfo * > modules, QString const &key)
Creates a new presenter in the MDI area according to the type of the module.
void refreshDisplayWindows() const
void slotToggleNavigatorToolbar()
QTimer m_autoScrollTimer
Definition bibletime.h:492
QMenu * m_openWindowsMenu
Definition bibletime.h:477
void slotSetActiveSubWindow(QWidget *window)
void toggleFullscreen()
bool autoScrollAnyKey()
QMenu * m_windowArrangementMenu
Definition bibletime.h:478
The base class for all display windows of BibleTime.