BibleTime
cdisplaywindow.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 <memory>
18#include <QAction>
19#include <QStringList>
20#include "../../backend/btglobal.h"
21#include "../../backend/drivers/btmodulelist.h"
22#include "../../backend/drivers/cswordmoduleinfo.h"
23#include "../../util/btassert.h"
24#include "../../util/btconnect.h"
25#include "btactioncollection.h"
26
27
28class BtConfigCore;
31class CSwordLDKey;
33class CKeyChooser;
34class CMDIArea;
37class QMenu;
38class QToolBar;
39class BTHistory;
40class BibleTime;
42
43/** \brief The base class for all display windows of BibleTime. */
45 Q_OBJECT
46 friend class CLexiconReadWindow;
47
48public: // Types:
49
51
52 public: // Methods:
53
54 ActionCollection(QObject * parent = nullptr);
55
56 };
57
58public:
59
61
62 /** Returns pointer to the mdi area object.*/
63 CMDIArea * mdi() const { return m_mdi; }
64
65 void updateWindowTitle();
66
67 CSwordModuleInfo const * firstModule() const noexcept
68 { return m_modules.first(); }
69
70 BtModuleList const & modules() const noexcept { return m_modules; }
71
73 { return BtConstModuleList(m_modules.begin(), m_modules.end()); }
74
75 /** \returns the used modules as a string list. */
76 QStringList const & moduleNames() const noexcept
77 { return m_moduleNames; }
78
79 /**
80 \brief Stores the settings of this window to configuration.
81 \param[in] windowConf The locked configuration group.
82 */
83 virtual void storeProfileSettings(BtConfigCore & windowConf) const;
84
85 /**
86 \brief Loads the settings of this window from configuration.
87 \param[in] windowConf The locked configuration group.
88 */
89 virtual void applyProfileSettings(BtConfigCore const & windowConf);
90
91 /** Returns the display options used by this display window. */
92 DisplayOptions const & displayOptions() const noexcept
93 { return m_displayOptions; }
94
95 /** Returns the filter options used by this window. */
96 FilterOptions const & filterOptions() const noexcept
97 { return m_filterOptions; }
98
99 /** Returns the keychooser widget of this display window. */
100 CKeyChooser * keyChooser() const noexcept { return m_keyChooser; }
101
102 /** Returns the key of this display window. */
103 CSwordKey * swordKey() const noexcept {
105 return m_swordKey.get();
106 }
107
108 /** Returns the main navigation toolbar. */
109 QToolBar * mainToolBar() const noexcept { return m_mainToolBar; }
110
111 /** Returns the tool buttons toolbar. */
112 QToolBar * buttonsToolBar() const noexcept { return m_buttonsToolBar; }
113
114 /** Sets the display settings button.*/
116
117 /** Returns the display widget used by this implementation of
118 CDisplayWindow. */
123
124 /** \returns whether syncs to the active window are allowed for this display
125 window. */
126 virtual bool syncAllowed() const noexcept { return false; }
127
128 /**
129 * Return pointer to the BibleTime main window
130 */
132 /**
133 * Called when this window is activated
134 */
135 void windowActivated();
136
138 { return m_actionCollection; }
139
140 /** Updates the status of the popup menu entries. */
141 virtual void copyDisplayedText();
142
144
145 /* set new reference in this module, or open standard bible */
146 void setBibleReference(const QString& reference);
147
148Q_SIGNALS:
149 /** A module was added to this window.*/
150 void sigModuleAdded(int index, QString module);
151 void sigModuleReplaced(int index, QString newModule);
152 void sigModuleRemoved(int index);
153 /** The module list of window changed but backend list didn't.*/
155
156 /**
157 Signal emitted when display options are changed.
158 */
160
161 /**
162 Signal emitted when display options are changed.
163 */
165
166 /** signal for change of modules */
168
169 /** signal for sword key change */
171
172public Q_SLOTS:
173 /** Receives a signal telling that a module should be added.*/
174 void slotAddModule(int index, CSwordModuleInfo * module);
175 void slotReplaceModule(int index, CSwordModuleInfo * newModule);
176 void slotRemoveModule(int index);
177
178 /** Lookup the key in the chosen modules.*/
179 void lookupKey(QString const & key);
180
181 /** Refresh the settings of this window.*/
182 virtual void reload();
183
184protected:
185
186 friend class CBibleReadWindow;
187
189 QString const & key,
190 bool const addTextHeaderToolbar,
192 CMDIArea * const parent);
193 ~CDisplayWindow() override;
194
195 /** Returns history for this window */
196 BTHistory * history() const noexcept { return m_history; }
197
198 /**
199 * Initialize the window. Call this method from the outside,
200 * because calling this in the constructor is not possible!
201 */
202 bool init();
203
205
207
208 template <typename ... Args>
209 QAction & initAddAction(Args && ... args) {
210 QAction & action = initAction(std::forward<Args>(args)...);
211 addAction(&action);
212 return action;
213 }
214
215 /** Initializes the internel keyboard actions.*/
216 virtual void initActions() = 0;
217
218 /** Lookup the given key.*/
219 virtual void lookupSwordKey(CSwordKey *);
220
221 /** Initializes the signal / slot connections of this display window.*/
222 virtual void initConnections();
223
224 /** Initialize the toolbars.*/
225 virtual void initToolbars();
226
228
229 /** Called to add actions to mainWindow toolbars */
230 virtual void setupMainWindowToolBars();
231
233
234protected Q_SLOTS:
235
236 virtual void modulesChanged();
237
238 /** Lookup the current key. Used to refresh the display. This also needs to
239 be called after programmatically changing filter/display options. */
240 void lookup();
241
242 void printAll();
243 void printAnchorOnly();
244 void printAnchorWithText();
245
246private: // methods:
247
248 template <typename Name, typename ... Args>
249 QAction & initAction(Name && name, Args && ... args) {
250 QAction & a = m_actionCollection->action(std::forward<Name>(name));
251 BT_CONNECT(&a, &QAction::triggered, std::forward<Args>(args)...);
252 return a;
253 }
254
255protected: // fields:
256
280
281private:
284
286
287 // Cache names of modules in case the backend invalidates the pointers in
288 // m_modules. This must be kept in sync with m_modules.
289 QStringList m_moduleNames;
290
293
295 std::unique_ptr<CSwordKey> const m_swordKey;
296 bool m_isInitialized = false; ///< Whether init() has been called
302};
#define BT_ASSERT(...)
Definition btassert.h:17
#define BT_CONNECT(...)
Definition btconnect.h:20
QList< CSwordModuleInfo * > BtModuleList
QList< CSwordModuleInfo const * > BtConstModuleList
QAction & action(QString const &name) const
The base class for all display windows of BibleTime.
virtual void modulesChanged()
FilterOptions m_filterOptions
QToolBar * buttonsToolBar() const noexcept
virtual bool syncAllowed() const noexcept
QAction & initAddAction(Args &&... args)
void sigKeyChanged(CSwordKey *key)
void sigDisplayOptionsChanged(const DisplayOptions &displayOptions)
BTHistory *const m_history
virtual void reload()
BtModuleList m_modules
struct CDisplayWindow::ActionsStruct m_actions
void setDisplaySettingsButton(BtDisplaySettingsButton *button)
QToolBar * mainToolBar() const noexcept
virtual void initConnections()
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
QStringList m_moduleNames
ActionCollection *const m_actionCollection
void sigFilterOptionsChanged(const FilterOptions &filterOptions)
void sigModulesChanged(const BtConstModuleList &modules)
virtual CSwordModuleInfo::ModuleType moduleType() const
std::unique_ptr< CSwordKey > const m_swordKey
virtual void setupMainWindowToolBars()
BtModelViewReadDisplay * displayWidget() const noexcept
DisplayOptions m_displayOptions
void clearMainWindowToolBars()
CKeyChooser * m_keyChooser
QStringList const & moduleNames() const noexcept
virtual void lookupSwordKey(CSwordKey *)
CMDIArea *const m_mdi
void lookupKey(QString const &key)
CSwordModuleInfo const * firstModule() const noexcept
DisplayOptions const & displayOptions() const noexcept
bool m_isInitialized
Whether init() has been called.
void sigModuleRemoved(int index)
void setFilterOptions(FilterOptions const &v)
BtConstModuleList constModules() const
CSwordKey * swordKey() const noexcept
BibleTime * btMainWindow()
void slotAddModule(int index, CSwordModuleInfo *module)
QToolBar * m_buttonsToolBar
virtual void initToolbars()
virtual void applyProfileSettings(BtConfigCore const &windowConf)
Loads the settings of this window from configuration.
QAction & initAction(Name &&name, Args &&... args)
virtual void initActions()=0
void sigModuleListChanged(BtModuleList newList)
~CDisplayWindow() override
BtModuleChooserBar * m_moduleChooserBar
void slotRemoveModule(int index)
ActionCollection * actionCollection() const noexcept
BtModelViewReadDisplay * m_displayWidget
CMDIArea * mdi() const
void sigModuleAdded(int index, QString module)
BtModuleList const & modules() const noexcept
virtual QMenu * newDisplayWidgetPopupMenu()
QToolBar * m_mainToolBar
void slotReplaceModule(int index, CSwordModuleInfo *newModule)
CSwordKey * getMouseClickedKey() const
void setBibleReference(const QString &reference)
virtual void copyDisplayedText()
BTHistory * history() const noexcept
void sigModuleReplaced(int index, QString newModule)
The class used to display lexicons.
struct CDisplayWindow::ActionsStruct::@14 save
struct CDisplayWindow::ActionsStruct::@13 copy
struct CDisplayWindow::ActionsStruct::@15 print
BtToolBarPopupAction * forwardInHistory
BtToolBarPopupAction * backInHistory