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