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();
101 
102  /** Returns the tool buttons toolbar. */
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  /** Sets the display widget used by this display window.*/
116  void setDisplayWidget(BtModelViewReadDisplay * newDisplay);
117 
118  /** \returns whether syncs to the active window are allowed for this display
119  window. */
120  virtual bool syncAllowed() const { return false; }
121 
122  /**
123  * Return pointer to the BibleTime main window
124  */
126  /**
127  * Called when this window is activated
128  */
129  void windowActivated();
130 
132 
133  bool hasSelectedText();
134 
135  /** Updates the status of the popup menu entries. */
136  virtual void copyDisplayedText();
137 
138  CSwordKey* getMouseClickedKey() const;
139 
140  /* set new reference in this module, or open standard bible */
141  void setBibleReference(const QString& reference);
142 
143 Q_SIGNALS:
144  /** A module was added to this window.*/
145  void sigModuleAdded(int index, QString module);
146  void sigModuleReplaced(int index, QString newModule);
147  void sigModuleRemoved(int index);
148  /** The module list of window changed but backend list didn't.*/
150 
151  /**
152  Signal emitted when display options are changed.
153  */
155 
156  /**
157  Signal emitted when display options are changed.
158  */
160 
161  /** signal for change of modules */
163 
164  /** signal for sword key change */
166 
167 public Q_SLOTS:
168  /** Receives a signal telling that a module should be added.*/
169  void slotAddModule(int index, CSwordModuleInfo * module);
170  void slotReplaceModule(int index, CSwordModuleInfo * newModule);
171  void slotRemoveModule(int index);
172 
173  /** Lookup the key in the chosen modules.*/
174  void lookupKey(QString const & key);
175 
176  /** Refresh the settings of this window.*/
177  virtual void reload();
178 
179 protected:
180 
181  friend class CBibleReadWindow;
182 
183  CDisplayWindow(BtModuleList const & modules, CMDIArea * const parent);
184  ~CDisplayWindow() override;
185 
186  /** Returns history for this window */
187  BTHistory * history() const noexcept { return m_history; }
188 
189  /**
190  * Initialize the window. Call this method from the outside,
191  * because calling this in the constructor is not possible!
192  */
193  bool init();
194 
196 
198 
199  template <typename ... Args>
200  QAction & initAddAction(Args && ... args) {
201  QAction & action = initAction(std::forward<Args>(args)...);
202  addAction(&action);
203  return action;
204  }
205 
206  /** Initializes the internel keyboard actions.*/
207  virtual void initActions();
208 
209  /** Sets the keychooser widget for this display window.*/
210  void setKeyChooser( CKeyChooser* ck );
211 
212  /** Creates and adds the module chooser bar to the toolbar. */
213  void addModuleChooserBar();
214 
215  /** Lookup the given key.*/
216  virtual void lookupSwordKey(CSwordKey *);
217 
218  /** Initializes the signal / slot connections of this display window.*/
219  virtual void initConnections();
220 
221  /** Initialize the view of this display window.*/
222  virtual void initView();
223 
224  /** Initialize the toolbars.*/
225  virtual void initToolbars();
226 
227  virtual QMenu * newDisplayWidgetPopupMenu();
228 
229  /** Called to add actions to mainWindow toolbars */
230  virtual void setupMainWindowToolBars();
231 
233 
234 protected 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 
244  void printAnchorWithText();
245 
246 private: // 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 
255 protected: // fields:
256 
257  struct ActionsStruct {
263  struct {
268  } copy;
270  struct {
271  QAction * reference;
274  } save;
276  struct {
277  QAction * reference;
278  QAction * entry;
279  } print;
281 
282 private:
284  CMDIArea * const m_mdi;
285 
287 
288  // Cache names of modules in case the backend invalidates the pointers in
289  // m_modules. This must be kept in sync with m_modules.
290  QStringList m_moduleNames;
291 
294 
296  std::unique_ptr<CSwordKey> const m_swordKey;
297  bool m_isInitialized = false; ///< Whether init() has been called
299  QToolBar * m_mainToolBar = nullptr;
301  QToolBar * m_headerBar = nullptr;
304 };
#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.
void addModuleChooserBar()
virtual void modulesChanged()
FilterOptions m_filterOptions
void sigKeyChanged(CSwordKey *key)
void setDisplayWidget(BtModelViewReadDisplay *newDisplay)
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()
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
CDisplayWindow(BtModuleList const &modules, CMDIArea *const parent)
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 void initView()
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
void sigModuleListChanged(BtModuleList newList)
~CDisplayWindow() override
BtModuleChooserBar * m_moduleChooserBar
void slotRemoveModule(int index)
QToolBar * mainToolBar()
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()
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