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