BibleTime
ccommentaryreadwindow.cpp
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 #include "ccommentaryreadwindow.h"
14 
15 #include <QAction>
16 #include <QIcon>
17 #include <QMenu>
18 #include <QToolBar>
19 #include "../../backend/config/btconfigcore.h"
20 #include "../../backend/keys/cswordversekey.h"
21 #include "../../backend/managers/cswordbackend.h"
22 #include "../../util/cresmgr.h"
23 #include "../bibletime.h"
24 #include "../keychooser/ckeychooser.h"
25 #include "btactioncollection.h"
26 
27 
29  QAction* qaction;
30 
31  qaction = new QAction(tr("Next book"), a);
33  a->addAction(QStringLiteral("nextBook"), qaction);
34 
35  qaction = new QAction(tr("Previous book"), a);
37  a->addAction(QStringLiteral("previousBook"), qaction);
38 
39  qaction = new QAction(tr("Next chapter"), a);
41  a->addAction(QStringLiteral("nextChapter"), qaction);
42 
43  qaction = new QAction(tr("Previous chapter"), a);
45  a->addAction(QStringLiteral("previousChapter"), qaction);
46 
47  qaction = new QAction(tr("Next verse"), a);
49  a->addAction(QStringLiteral("nextVerse"), qaction);
50 
51  qaction = new QAction(tr("Previous verse"), a);
53  a->addAction(QStringLiteral("previousVerse"), qaction);
54 
55  qaction = new QAction(CResMgr::displaywindows::commentaryWindow::syncWindow::icon(),
56  tr("Synchronize"), a);
57  qaction->setCheckable(true);
59  qaction->setToolTip(tr("Synchronize the displayed entry of this work with the active Bible window"));
61 }
62 
64  CDisplayWindow::initActions(); //make sure the predefined actions are available
67 
68  initAddAction(QStringLiteral("nextBook"),
69  this,
71  initAddAction(QStringLiteral("previousBook"),
72  this,
74  initAddAction(QStringLiteral("nextChapter"),
75  this,
77  initAddAction(QStringLiteral("previousChapter"),
78  this,
80  initAddAction(QStringLiteral("nextVerse"),
81  this,
83  initAddAction(QStringLiteral("previousVerse"),
84  this,
86 
88  m_syncButton = &qaction;
89  addAction(&qaction);
90 
91  actionCollection()->readShortcuts(QStringLiteral("Commentary shortcuts"));
92 }
93 
97  m_syncButton->setChecked(
98  conf.value<bool>(QStringLiteral("syncEnabled"), false));
99 }
100 
102  const
103 {
106  conf.setValue(QStringLiteral("syncEnabled"), m_syncButton->isChecked());
107 }
108 
111  buttonsToolBar()->addAction(m_syncButton);
112 }
113 
116  btMainWindow()->toolsToolBar()->addAction(m_syncButton);
117 }
118 
119 /** Reimplementation to handle the keychooser refresh. */
122 
123  //refresh the book lists
124  verseKey()->setLocale(
125  CSwordBackend::instance().booknameLanguage().toLatin1());
127 
128  actionCollection()->readShortcuts(QStringLiteral("Commentary shortcuts"));
129 }
130 
131 /** rapper around key() to return the right type of key. */
133  CSwordVerseKey* k = dynamic_cast<CSwordVerseKey*>(CDisplayWindow::key());
134  BT_ASSERT(k);
135  return k;
136 }
137 
138 /** Moves to the next book. */
140  if (verseKey()->next(CSwordVerseKey::UseBook))
141  keyChooser()->setKey(key());
142 }
143 
144 /** Moves one book behind. */
146  if (verseKey()->previous(CSwordVerseKey::UseBook))
147  keyChooser()->setKey(key());
148 }
149 
150 /** Moves to the next book. */
153  keyChooser()->setKey(key());
154 }
155 
156 /** Moves one book behind. */
158  if (verseKey()->previous(CSwordVerseKey::UseChapter))
159  keyChooser()->setKey(key());
160 }
161 
162 /** Moves to the next book. */
164  if (verseKey()->next(CSwordVerseKey::UseVerse))
165  keyChooser()->setKey(key());
166 }
167 
168 /** Moves one book behind. */
170  if (verseKey()->previous(CSwordVerseKey::UseVerse))
171  keyChooser()->setKey(key());
172 }
173 
175  return m_syncButton->isChecked();
176 }
#define BT_ASSERT(...)
Definition: btassert.h:17
QToolBar * toolsToolBar() const noexcept
Definition: bibletime.h:156
void readShortcuts(QString const &group)
Read shortcuts from config.
void addAction(QString const &name, QAction *const action)
QAction & action(QString const &name) const
T value(QString const &key, T const &defaultValue=T()) const
Returns the settings value for the given global key.
Definition: btconfigcore.h:50
void setValue(QString const &key, T const &value)
Sets a value for a key.
Definition: btconfigcore.h:73
void setupMainWindowToolBars() override
bool syncAllowed() const override
static void insertKeyboardActions(BtActionCollection *const a)
void storeProfileSettings(BtConfigCore &windowConf) const override
Stores the settings of this window to configuration.
void applyProfileSettings(BtConfigCore const &windowConf) override
Loads the settings of this window from configuration.
virtual void reload()
QAction & initAddAction(Args &&... args)
CKeyChooser * keyChooser() const
virtual void storeProfileSettings(BtConfigCore &windowConf) const
Stores the settings of this window to configuration.
BtActionCollection * actionCollection() const
virtual void initActions()
virtual void setupMainWindowToolBars()
BibleTime * btMainWindow()
virtual void initToolbars()
virtual void applyProfileSettings(BtConfigCore const &windowConf)
Loads the settings of this window from configuration.
CSwordKey * key() const
QToolBar * buttonsToolBar()
virtual void setKey(CSwordKey *key)=0
virtual void refreshContent()=0
static CSwordBackend & instance() noexcept
Definition: cswordbackend.h:98
CSwordKey implementation for Sword's VerseKey.
void setLocale(char const *const locale)